Skip to content

Commit

Permalink
Further improve test of #1064
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 16, 2024
1 parent e5292e1 commit a1c1205
Showing 1 changed file with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testParserWithBoundedPool() throws Exception {
_testParser(JsonRecyclerPools.newBoundedPool(5));
_testParser(JsonRecyclerPools.sharedBoundedPool());
}

private void _testParser(RecyclerPool<BufferRecycler> pool) throws Exception
{
JsonFactory jsonF = JsonFactory.builder()
Expand All @@ -53,7 +53,7 @@ private void _testParser(RecyclerPool<BufferRecycler> pool) throws Exception

p.close();
}

// // Generators with RecyclerPools:

public void testGeneratorWithThreadLocalPool() throws Exception {
Expand Down Expand Up @@ -97,4 +97,50 @@ private void _testGenerator(RecyclerPool<BufferRecycler> 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<BufferRecycler> 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());
}
}

0 comments on commit a1c1205

Please sign in to comment.