Skip to content

Commit cea5e97

Browse files
committed
Close ExecutorServices in test
1 parent f312fa5 commit cea5e97

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.rabbitmq.client.impl;
2+
3+
/**
4+
*
5+
*/
6+
public class WorkPoolFullException {
7+
8+
}

src/test/java/com/rabbitmq/client/test/SharedThreadPoolTest.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,36 @@
3030

3131
public class SharedThreadPoolTest extends BrokerTestCase {
3232
@Test public void willShutDownExecutor() throws IOException, TimeoutException {
33-
ConnectionFactory cf = TestUtils.connectionFactory();
34-
cf.setAutomaticRecoveryEnabled(false);
35-
ExecutorService executor = Executors.newFixedThreadPool(8);
36-
cf.setSharedExecutor(executor);
33+
ExecutorService executor1 = null;
34+
ExecutorService executor2 = null;
35+
try {
36+
ConnectionFactory cf = TestUtils.connectionFactory();
37+
cf.setAutomaticRecoveryEnabled(false);
38+
executor1 = Executors.newFixedThreadPool(8);
39+
cf.setSharedExecutor(executor1);
3740

38-
AMQConnection conn1 = (AMQConnection)cf.newConnection();
39-
assertFalse(conn1.willShutDownConsumerExecutor());
41+
AMQConnection conn1 = (AMQConnection)cf.newConnection();
42+
assertFalse(conn1.willShutDownConsumerExecutor());
4043

41-
AMQConnection conn2 = (AMQConnection)cf.newConnection(Executors.newSingleThreadExecutor());
42-
assertFalse(conn2.willShutDownConsumerExecutor());
44+
executor2 = Executors.newSingleThreadExecutor();
45+
AMQConnection conn2 = (AMQConnection)cf.newConnection(executor2);
46+
assertFalse(conn2.willShutDownConsumerExecutor());
4347

44-
AMQConnection conn3 = (AMQConnection)cf.newConnection((ExecutorService)null);
45-
assertTrue(conn3.willShutDownConsumerExecutor());
48+
AMQConnection conn3 = (AMQConnection)cf.newConnection((ExecutorService)null);
49+
assertTrue(conn3.willShutDownConsumerExecutor());
4650

47-
cf.setSharedExecutor(null);
51+
cf.setSharedExecutor(null);
4852

49-
AMQConnection conn4 = (AMQConnection)cf.newConnection();
50-
assertTrue(conn4.willShutDownConsumerExecutor());
53+
AMQConnection conn4 = (AMQConnection)cf.newConnection();
54+
assertTrue(conn4.willShutDownConsumerExecutor());
55+
} finally {
56+
if (executor1 != null) {
57+
executor1.shutdownNow();
58+
}
59+
if (executor2 != null) {
60+
executor2.shutdownNow();
61+
}
62+
}
63+
5164
}
5265
}

0 commit comments

Comments
 (0)