This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-pool.git
The following commit(s) were added to refs/heads/master by this push: new ad4408b7 Refactor for simpler ad-hoc testing. ad4408b7 is described below commit ad4408b722b720876a49f480914d9582d647b03d Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Jul 7 17:20:23 2023 -0400 Refactor for simpler ad-hoc testing. --- .../pool2/impl/TestGenericKeyedObjectPool.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java index 9358b64f..6da15c3f 100644 --- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java +++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java @@ -1001,7 +1001,7 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool { } /** - * TODO Tests POOL-411, or least tries to reproduce the NPE, but does not. + * Tests POOL-411, or least tries to reproduce the NPE, but does not. * * @throws TestException a test failure. */ @@ -1012,7 +1012,18 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool { final int addCount = 1; final int borrowCycles = 1024; final int clearCycles = 1024; + final boolean useYield = true; + testConcurrentBorrowAndClear(threadCount, taskCount, addCount, borrowCycles, clearCycles, useYield); + } + + /** + * Tests POOL-411, or least tries to reproduce the NPE, but does not. + * + * @throws TestException a test failure. + */ + private void testConcurrentBorrowAndClear(final int threadCount, final int taskCount, final int addCount, final int borrowCycles, final int clearCycles, + final boolean useYield) throws TestException { final GenericKeyedObjectPoolConfig<String> config = new GenericKeyedObjectPoolConfig<>(); final int maxTotalPerKey = borrowCycles + 1; config.setMaxTotalPerKey(threadCount); @@ -1030,7 +1041,9 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool { for (int t = 0; t < taskCount; t++) { futures.add(threadPool.submit(() -> { for (int i = 0; i < clearCycles; i++) { - Thread.yield(); + if (useYield) { + Thread.yield(); + } gkoPool.clear("0", true); try { gkoPool.addObjects(Arrays.asList("0"), addCount); @@ -1042,7 +1055,9 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool { futures.add(threadPool.submit(() -> { try { for (int i = 0; i < borrowCycles; i++) { - Thread.yield(); + if (useYield) { + Thread.yield(); + } final String pooled = gkoPool.borrowObject("0"); gkoPool.returnObject("0", pooled); }