From a1c1205b17b5b35da3dbb3f909d2a38b34b83f2b Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Mon, 15 Jan 2024 17:08:18 -0800 Subject: [PATCH] Further improve test of #1064 --- .../core/util/JsonBufferRecyclersTest.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/core/util/JsonBufferRecyclersTest.java b/src/test/java/com/fasterxml/jackson/core/util/JsonBufferRecyclersTest.java index 985afc956f..5bebf35958 100644 --- a/src/test/java/com/fasterxml/jackson/core/util/JsonBufferRecyclersTest.java +++ b/src/test/java/com/fasterxml/jackson/core/util/JsonBufferRecyclersTest.java @@ -31,7 +31,7 @@ public void testParserWithBoundedPool() throws Exception { _testParser(JsonRecyclerPools.newBoundedPool(5)); _testParser(JsonRecyclerPools.sharedBoundedPool()); } - + private void _testParser(RecyclerPool pool) throws Exception { JsonFactory jsonF = JsonFactory.builder() @@ -53,7 +53,7 @@ private void _testParser(RecyclerPool pool) throws Exception p.close(); } - + // // Generators with RecyclerPools: public void testGeneratorWithThreadLocalPool() throws Exception { @@ -97,4 +97,50 @@ private void _testGenerator(RecyclerPool pool) throws Exception assertEquals(a2q("{'a':-42,'b':'barfoo'}"), w.toString()); } + + // // Read-and-Write: Parser and Generator, overlapping usage + + public void testCopyWithThreadLocalPool() throws Exception { + _testCopy(JsonRecyclerPools.threadLocalPool()); + } + + public void testCopyWithNopLocalPool() throws Exception { + _testCopy(JsonRecyclerPools.nonRecyclingPool()); + } + + public void testCopyWithDequeuPool() throws Exception { + _testCopy(JsonRecyclerPools.newConcurrentDequePool()); + _testCopy(JsonRecyclerPools.sharedConcurrentDequePool()); + } + + public void testCopyWithLockFreePool() throws Exception { + _testCopy(JsonRecyclerPools.newLockFreePool()); + _testCopy(JsonRecyclerPools.sharedLockFreePool()); + } + + public void testCopyWithBoundedPool() throws Exception { + _testCopy(JsonRecyclerPools.newBoundedPool(5)); + _testCopy(JsonRecyclerPools.sharedBoundedPool()); + } + + private void _testCopy(RecyclerPool pool) throws Exception + { + JsonFactory jsonF = JsonFactory.builder() + .recyclerPool(pool) + .build(); + + final String DOC = a2q("{'a':123,'b':'foobar'}"); + JsonParser p = jsonF.createParser(DOC); + StringWriter w = new StringWriter(); + JsonGenerator g = jsonF.createGenerator(w); + + while (p.nextToken() != null) { + g.copyCurrentEvent(p); + } + + p.close(); + g.close(); + + assertEquals(DOC, w.toString()); + } }