Skip to content

Commit 38d7e3f

Browse files
committed
Shutdown ExecutorService in test
1 parent f5ea2b6 commit 38d7e3f

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

zookeeper-server/src/test/java/org/apache/zookeeper/util/TestCircularBlockingQueue.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)