File tree Expand file tree Collapse file tree
zookeeper-server/src/test/java/org/apache/zookeeper/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,20 +53,24 @@ public void testCircularBlockingQueueTakeBlock()
5353 final CircularBlockingQueue <Integer > testQueue = new CircularBlockingQueue <>(2 );
5454
5555 ExecutorService executor = Executors .newSingleThreadExecutor ();
56-
57- Future <Integer > testTake = executor .submit (() -> {
58- return testQueue .take ();
59- });
60-
61- // Allow the other thread to get into position; waiting for item to be inserted
62- while (!testQueue .isConsumerThreadBlocked ()) {
63- Thread .sleep (50L );
56+ try {
57+ Future <Integer > testTake = executor .submit (() -> {
58+ return testQueue .take ();
59+ });
60+
61+ // Allow the other thread to get into position; waiting for item to be
62+ // inserted
63+ while (!testQueue .isConsumerThreadBlocked ()) {
64+ Thread .sleep (50L );
65+ }
66+
67+ testQueue .offer (10 );
68+
69+ Integer result = testTake .get ();
70+ Assert .assertEquals (10 , result .intValue ());
71+ } finally {
72+ executor .shutdown ();
6473 }
65-
66- testQueue .offer (10 );
67-
68- Integer result = testTake .get ();
69- Assert .assertEquals (10 , result .intValue ());
7074 }
7175
7276}
You can’t perform that action at this time.
0 commit comments