99import java .util .Set ;
1010import java .util .UUID ;
1111import java .util .concurrent .ArrayBlockingQueue ;
12+ import java .util .concurrent .CountDownLatch ;
1213import java .util .concurrent .TimeUnit ;
1314
1415import org .apache .accumulo .core .client .AccumuloClient ;
2728import datawave .security .authorization .AuthorizationException ;
2829
2930public class CompositeQueryLogicResultsIteratorTest {
31+
32+ private CompositeQueryLogic compositeLogic ;
33+
3034 @ Test
3135 public void countDownLatchShortCircuitTest () throws Exception {
3236 final long pollTime = 1000 ;
3337 final long delay = 0 ;
3438
3539 CompositeQueryLogicResultsIterator iterator = setup (pollTime , delay );
40+
41+ // wait for threads to complete before testing the short-circuit behavior
42+ CountDownLatch latch = compositeLogic .getCompletionLatch ();
43+ assertTrue ("completion latch did not count down in time" , latch .await (5 , TimeUnit .SECONDS ));
44+
3645 long start = System .currentTimeMillis ();
3746 iterator .hasNext ();
3847
@@ -61,6 +70,7 @@ public void minimumWaitTest() throws Exception {
6170
6271 private CompositeQueryLogicResultsIterator setup (long pollTime , long delay ) throws Exception {
6372 CompositeQueryLogic logic = new StrippedCompositeQueryLogic ();
73+ this .compositeLogic = logic ;
6474 Map <String ,QueryLogic <?>> logicMap = new HashMap <>();
6575 logicMap .put ("alfred" , new StubbedQueryLogic (delay ));
6676 logicMap .put ("ben" , new StubbedQueryLogic (delay ));
@@ -77,9 +87,6 @@ private CompositeQueryLogicResultsIterator setup(long pollTime, long delay) thro
7787 ArrayBlockingQueue queue = new ArrayBlockingQueue (1 );
7888 CompositeQueryLogicResultsIterator iterator = new CompositeQueryLogicResultsIterator (logic , queue , pollTime , TimeUnit .MILLISECONDS );
7989
80- // small sleep to guarantee any init in the threads is finished for consistent test results
81- Thread .sleep (25 );
82-
8390 return iterator ;
8491 }
8592
0 commit comments