@@ -31,7 +31,7 @@ public void testParserWithBoundedPool() throws Exception {
31
31
_testParser (JsonRecyclerPools .newBoundedPool (5 ));
32
32
_testParser (JsonRecyclerPools .sharedBoundedPool ());
33
33
}
34
-
34
+
35
35
private void _testParser (RecyclerPool <BufferRecycler > pool ) throws Exception
36
36
{
37
37
JsonFactory jsonF = JsonFactory .builder ()
@@ -53,7 +53,7 @@ private void _testParser(RecyclerPool<BufferRecycler> pool) throws Exception
53
53
54
54
p .close ();
55
55
}
56
-
56
+
57
57
// // Generators with RecyclerPools:
58
58
59
59
public void testGeneratorWithThreadLocalPool () throws Exception {
@@ -97,4 +97,50 @@ private void _testGenerator(RecyclerPool<BufferRecycler> pool) throws Exception
97
97
98
98
assertEquals (a2q ("{'a':-42,'b':'barfoo'}" ), w .toString ());
99
99
}
100
+
101
+ // // Read-and-Write: Parser and Generator, overlapping usage
102
+
103
+ public void testCopyWithThreadLocalPool () throws Exception {
104
+ _testCopy (JsonRecyclerPools .threadLocalPool ());
105
+ }
106
+
107
+ public void testCopyWithNopLocalPool () throws Exception {
108
+ _testCopy (JsonRecyclerPools .nonRecyclingPool ());
109
+ }
110
+
111
+ public void testCopyWithDequeuPool () throws Exception {
112
+ _testCopy (JsonRecyclerPools .newConcurrentDequePool ());
113
+ _testCopy (JsonRecyclerPools .sharedConcurrentDequePool ());
114
+ }
115
+
116
+ public void testCopyWithLockFreePool () throws Exception {
117
+ _testCopy (JsonRecyclerPools .newLockFreePool ());
118
+ _testCopy (JsonRecyclerPools .sharedLockFreePool ());
119
+ }
120
+
121
+ public void testCopyWithBoundedPool () throws Exception {
122
+ _testCopy (JsonRecyclerPools .newBoundedPool (5 ));
123
+ _testCopy (JsonRecyclerPools .sharedBoundedPool ());
124
+ }
125
+
126
+ private void _testCopy (RecyclerPool <BufferRecycler > pool ) throws Exception
127
+ {
128
+ JsonFactory jsonF = JsonFactory .builder ()
129
+ .recyclerPool (pool )
130
+ .build ();
131
+
132
+ final String DOC = a2q ("{'a':123,'b':'foobar'}" );
133
+ JsonParser p = jsonF .createParser (DOC );
134
+ StringWriter w = new StringWriter ();
135
+ JsonGenerator g = jsonF .createGenerator (w );
136
+
137
+ while (p .nextToken () != null ) {
138
+ g .copyCurrentEvent (p );
139
+ }
140
+
141
+ p .close ();
142
+ g .close ();
143
+
144
+ assertEquals (DOC , w .toString ());
145
+ }
100
146
}
0 commit comments