@@ -31,7 +31,7 @@ public void testParserWithBoundedPool() throws Exception {
3131 _testParser (JsonRecyclerPools .newBoundedPool (5 ));
3232 _testParser (JsonRecyclerPools .sharedBoundedPool ());
3333 }
34-
34+
3535 private void _testParser (RecyclerPool <BufferRecycler > pool ) throws Exception
3636 {
3737 JsonFactory jsonF = JsonFactory .builder ()
@@ -53,7 +53,7 @@ private void _testParser(RecyclerPool<BufferRecycler> pool) throws Exception
5353
5454 p .close ();
5555 }
56-
56+
5757 // // Generators with RecyclerPools:
5858
5959 public void testGeneratorWithThreadLocalPool () throws Exception {
@@ -97,4 +97,50 @@ private void _testGenerator(RecyclerPool<BufferRecycler> pool) throws Exception
9797
9898 assertEquals (a2q ("{'a':-42,'b':'barfoo'}" ), w .toString ());
9999 }
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+ }
100146}
0 commit comments