@@ -16,37 +16,41 @@ class JsonBufferRecyclersTest extends JUnit5TestBase
1616
1717 @ Test
1818 void parserWithThreadLocalPool () throws Exception {
19- _testParser (JsonRecyclerPools .threadLocalPool ());
19+ _testParser (JsonRecyclerPools .threadLocalPool (), - 1 , - 1 );
2020 }
2121
2222 @ Test
2323 void parserWithNopLocalPool () throws Exception {
24- _testParser (JsonRecyclerPools .nonRecyclingPool ());
24+ _testParser (JsonRecyclerPools .nonRecyclingPool (), 0 , 0 );
2525 }
2626
2727 @ Test
2828 void parserWithDequeuPool () throws Exception {
29- _testParser (JsonRecyclerPools .newConcurrentDequePool ());
30- _testParser (JsonRecyclerPools .sharedConcurrentDequePool ());
29+ _testParser (JsonRecyclerPools .newConcurrentDequePool (), 0 , 1 );
30+ _testParser (JsonRecyclerPools .sharedConcurrentDequePool (), null , null );
3131 }
3232
3333 @ Test
3434 void parserWithLockFreePool () throws Exception {
35- _testParser (JsonRecyclerPools .newLockFreePool ());
36- _testParser (JsonRecyclerPools .sharedLockFreePool ());
35+ _testParser (JsonRecyclerPools .newLockFreePool (), 0 , 1 );
36+ _testParser (JsonRecyclerPools .sharedLockFreePool (), null , null );
3737 }
3838
3939 @ Test
4040 void parserWithBoundedPool () throws Exception {
41- _testParser (JsonRecyclerPools .newBoundedPool (5 ));
42- _testParser (JsonRecyclerPools .sharedBoundedPool ());
41+ _testParser (JsonRecyclerPools .newBoundedPool (5 ), 0 , 1 );
42+ _testParser (JsonRecyclerPools .sharedBoundedPool (), null , null );
4343 }
4444
45- private void _testParser (RecyclerPool <BufferRecycler > pool ) throws Exception
45+ private void _testParser (RecyclerPool <BufferRecycler > pool ,
46+ Integer expSizeBefore , Integer expSizeAfter ) throws Exception
4647 {
4748 JsonFactory jsonF = JsonFactory .builder ()
4849 .recyclerPool (pool )
4950 .build ();
51+ if (expSizeBefore != null ) {
52+ assertEquals (expSizeBefore , pool .pooledCount ());
53+ }
5054
5155 JsonParser p = jsonF .createParser (a2q ("{'a':123,'b':'foobar'}" ));
5256
@@ -62,44 +66,53 @@ private void _testParser(RecyclerPool<BufferRecycler> pool) throws Exception
6266 assertToken (JsonToken .END_OBJECT , p .nextToken ());
6367
6468 p .close ();
69+
70+ if (expSizeAfter != null ) {
71+ assertEquals (expSizeAfter , pool .pooledCount ());
72+ }
6573 }
6674
6775 // // Generators with RecyclerPools:
6876
6977 @ Test
7078 void generatorWithThreadLocalPool () throws Exception {
71- _testGenerator (JsonRecyclerPools .threadLocalPool ());
79+ _testGenerator (JsonRecyclerPools .threadLocalPool (), - 1 , - 1 );
7280 }
7381
7482 @ Test
7583 void generatorWithNopLocalPool () throws Exception {
76- _testGenerator (JsonRecyclerPools .nonRecyclingPool ());
84+ _testGenerator (JsonRecyclerPools .nonRecyclingPool (), 0 , 0 );
7785 }
7886
7987 @ Test
8088 void generatorWithDequeuPool () throws Exception {
81- _testGenerator (JsonRecyclerPools .newConcurrentDequePool ());
82- _testGenerator (JsonRecyclerPools .sharedConcurrentDequePool ());
89+ _testGenerator (JsonRecyclerPools .newConcurrentDequePool (), 0 , 1 );
90+ _testGenerator (JsonRecyclerPools .sharedConcurrentDequePool (), null , null );
8391 }
8492
8593 @ Test
8694 void generatorWithLockFreePool () throws Exception {
87- _testGenerator (JsonRecyclerPools .newLockFreePool ());
88- _testGenerator (JsonRecyclerPools .sharedLockFreePool ());
95+ _testGenerator (JsonRecyclerPools .newLockFreePool (), 0 , 1 );
96+ _testGenerator (JsonRecyclerPools .sharedLockFreePool (), null , null );
8997 }
9098
9199 @ Test
92100 void generatorWithBoundedPool () throws Exception {
93- _testGenerator (JsonRecyclerPools .newBoundedPool (5 ));
94- _testGenerator (JsonRecyclerPools .sharedBoundedPool ());
101+ _testGenerator (JsonRecyclerPools .newBoundedPool (5 ), 0 , 1 );
102+ _testGenerator (JsonRecyclerPools .sharedBoundedPool (), null , null );
95103 }
96-
97- private void _testGenerator (RecyclerPool <BufferRecycler > pool ) throws Exception
104+
105+ private void _testGenerator (RecyclerPool <BufferRecycler > pool ,
106+ Integer expSizeBefore , Integer expSizeAfter ) throws Exception
98107 {
99108 JsonFactory jsonF = JsonFactory .builder ()
100109 .recyclerPool (pool )
101110 .build ();
102111
112+ if (expSizeBefore != null ) {
113+ assertEquals (expSizeBefore , pool .pooledCount ());
114+ }
115+
103116 StringWriter w = new StringWriter ();
104117 JsonGenerator g = jsonF .createGenerator (w );
105118
@@ -110,6 +123,10 @@ private void _testGenerator(RecyclerPool<BufferRecycler> pool) throws Exception
110123
111124 g .close ();
112125
126+ if (expSizeAfter != null ) {
127+ assertEquals (expSizeAfter , pool .pooledCount ());
128+ }
129+
113130 assertEquals (a2q ("{'a':-42,'b':'barfoo'}" ), w .toString ());
114131 }
115132
0 commit comments