@@ -16,37 +16,41 @@ class JsonBufferRecyclersTest extends JUnit5TestBase
16
16
17
17
@ Test
18
18
void parserWithThreadLocalPool () throws Exception {
19
- _testParser (JsonRecyclerPools .threadLocalPool ());
19
+ _testParser (JsonRecyclerPools .threadLocalPool (), - 1 , - 1 );
20
20
}
21
21
22
22
@ Test
23
23
void parserWithNopLocalPool () throws Exception {
24
- _testParser (JsonRecyclerPools .nonRecyclingPool ());
24
+ _testParser (JsonRecyclerPools .nonRecyclingPool (), 0 , 0 );
25
25
}
26
26
27
27
@ Test
28
28
void parserWithDequeuPool () throws Exception {
29
- _testParser (JsonRecyclerPools .newConcurrentDequePool ());
30
- _testParser (JsonRecyclerPools .sharedConcurrentDequePool ());
29
+ _testParser (JsonRecyclerPools .newConcurrentDequePool (), 0 , 1 );
30
+ _testParser (JsonRecyclerPools .sharedConcurrentDequePool (), null , null );
31
31
}
32
32
33
33
@ Test
34
34
void parserWithLockFreePool () throws Exception {
35
- _testParser (JsonRecyclerPools .newLockFreePool ());
36
- _testParser (JsonRecyclerPools .sharedLockFreePool ());
35
+ _testParser (JsonRecyclerPools .newLockFreePool (), 0 , 1 );
36
+ _testParser (JsonRecyclerPools .sharedLockFreePool (), null , null );
37
37
}
38
38
39
39
@ Test
40
40
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 );
43
43
}
44
44
45
- private void _testParser (RecyclerPool <BufferRecycler > pool ) throws Exception
45
+ private void _testParser (RecyclerPool <BufferRecycler > pool ,
46
+ Integer expSizeBefore , Integer expSizeAfter ) throws Exception
46
47
{
47
48
JsonFactory jsonF = JsonFactory .builder ()
48
49
.recyclerPool (pool )
49
50
.build ();
51
+ if (expSizeBefore != null ) {
52
+ assertEquals (expSizeBefore , pool .pooledCount ());
53
+ }
50
54
51
55
JsonParser p = jsonF .createParser (a2q ("{'a':123,'b':'foobar'}" ));
52
56
@@ -62,44 +66,53 @@ private void _testParser(RecyclerPool<BufferRecycler> pool) throws Exception
62
66
assertToken (JsonToken .END_OBJECT , p .nextToken ());
63
67
64
68
p .close ();
69
+
70
+ if (expSizeAfter != null ) {
71
+ assertEquals (expSizeAfter , pool .pooledCount ());
72
+ }
65
73
}
66
74
67
75
// // Generators with RecyclerPools:
68
76
69
77
@ Test
70
78
void generatorWithThreadLocalPool () throws Exception {
71
- _testGenerator (JsonRecyclerPools .threadLocalPool ());
79
+ _testGenerator (JsonRecyclerPools .threadLocalPool (), - 1 , - 1 );
72
80
}
73
81
74
82
@ Test
75
83
void generatorWithNopLocalPool () throws Exception {
76
- _testGenerator (JsonRecyclerPools .nonRecyclingPool ());
84
+ _testGenerator (JsonRecyclerPools .nonRecyclingPool (), 0 , 0 );
77
85
}
78
86
79
87
@ Test
80
88
void generatorWithDequeuPool () throws Exception {
81
- _testGenerator (JsonRecyclerPools .newConcurrentDequePool ());
82
- _testGenerator (JsonRecyclerPools .sharedConcurrentDequePool ());
89
+ _testGenerator (JsonRecyclerPools .newConcurrentDequePool (), 0 , 1 );
90
+ _testGenerator (JsonRecyclerPools .sharedConcurrentDequePool (), null , null );
83
91
}
84
92
85
93
@ Test
86
94
void generatorWithLockFreePool () throws Exception {
87
- _testGenerator (JsonRecyclerPools .newLockFreePool ());
88
- _testGenerator (JsonRecyclerPools .sharedLockFreePool ());
95
+ _testGenerator (JsonRecyclerPools .newLockFreePool (), 0 , 1 );
96
+ _testGenerator (JsonRecyclerPools .sharedLockFreePool (), null , null );
89
97
}
90
98
91
99
@ Test
92
100
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 );
95
103
}
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
98
107
{
99
108
JsonFactory jsonF = JsonFactory .builder ()
100
109
.recyclerPool (pool )
101
110
.build ();
102
111
112
+ if (expSizeBefore != null ) {
113
+ assertEquals (expSizeBefore , pool .pooledCount ());
114
+ }
115
+
103
116
StringWriter w = new StringWriter ();
104
117
JsonGenerator g = jsonF .createGenerator (w );
105
118
@@ -110,6 +123,10 @@ private void _testGenerator(RecyclerPool<BufferRecycler> pool) throws Exception
110
123
111
124
g .close ();
112
125
126
+ if (expSizeAfter != null ) {
127
+ assertEquals (expSizeAfter , pool .pooledCount ());
128
+ }
129
+
113
130
assertEquals (a2q ("{'a':-42,'b':'barfoo'}" ), w .toString ());
114
131
}
115
132
0 commit comments