This is an automated email from the ASF dual-hosted git repository. cshannon pushed a commit to branch elasticity in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/elasticity by this push: new ab308a208f Use future in Fate deferred overflow test (#4182) ab308a208f is described below commit ab308a208f1826cd767eebdd757e82e58021333f Author: Christopher L. Shannon <christopher.l.shan...@gmail.com> AuthorDate: Mon Jan 22 17:21:29 2024 -0500 Use future in Fate deferred overflow test (#4182) This updates AccumuloStoreReadWriteIT deferred overflow test to use a future when calling the store runnable() method so that we can make sure the task has finished and exited the thread before continuing on with the rest of the test. This improves the test to make sure we don't have a situation where two threads are executing the runnable() method at the same time --- .../fate/accumulo/AccumuloStoreReadWriteIT.java | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/src/main/java/org/apache/accumulo/test/fate/accumulo/AccumuloStoreReadWriteIT.java b/test/src/main/java/org/apache/accumulo/test/fate/accumulo/AccumuloStoreReadWriteIT.java index aee077f8c0..0d36d30a95 100644 --- a/test/src/main/java/org/apache/accumulo/test/fate/accumulo/AccumuloStoreReadWriteIT.java +++ b/test/src/main/java/org/apache/accumulo/test/fate/accumulo/AccumuloStoreReadWriteIT.java @@ -29,6 +29,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -61,7 +62,7 @@ public class AccumuloStoreReadWriteIT extends SharedMiniClusterBase { @Override protected Duration defaultTimeout() { - return Duration.ofMinutes(5); + return Duration.ofMinutes(1); } @Test @@ -157,18 +158,18 @@ public class AccumuloStoreReadWriteIT extends SharedMiniClusterBase { assertFalse(store.isDeferredOverflow()); var executor = Executors.newCachedThreadPool(); + Future<?> future; AtomicBoolean keepRunning = new AtomicBoolean(true); try { // Run and verify all 10 transactions still exist and were not // run because of the deferral time of all the transactions - try { - executor.execute(() -> store.runnable(keepRunning, transactions::remove)); - Thread.sleep(2000); - assertEquals(10, transactions.size()); - } finally { - // Should terminate the task if waiting - keepRunning.set(false); - } + future = executor.submit(() -> store.runnable(keepRunning, transactions::remove)); + Thread.sleep(2000); + assertEquals(10, transactions.size()); + // Setting this flag to false should terminate the task if sleeping + keepRunning.set(false); + // wait for the future to finish to verify the task finished + future.get(); // Store one more that should go over the max deferred of 10 // and should clear the map and set the overflow flag @@ -187,13 +188,12 @@ public class AccumuloStoreReadWriteIT extends SharedMiniClusterBase { // Run and verify all 11 transactions were processed // and removed from the store keepRunning.set(true); - try { - executor.execute(() -> store.runnable(keepRunning, transactions::remove)); - Wait.waitFor(transactions::isEmpty); - } finally { - // Should terminate the task if waiting - keepRunning.set(false); - } + future = executor.submit(() -> store.runnable(keepRunning, transactions::remove)); + Wait.waitFor(transactions::isEmpty); + // Setting this flag to false should terminate the task if sleeping + keepRunning.set(false); + // wait for the future to finish to verify the task finished + future.get(); // Overflow should now be reset to false so adding another deferred // transaction should now go back into the deferral map and flag should