|
30 | 30 |
|
31 | 31 | public class SharedThreadPoolTest extends BrokerTestCase { |
32 | 32 | @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); |
37 | 40 |
|
38 | | - AMQConnection conn1 = (AMQConnection)cf.newConnection(); |
39 | | - assertFalse(conn1.willShutDownConsumerExecutor()); |
| 41 | + AMQConnection conn1 = (AMQConnection)cf.newConnection(); |
| 42 | + assertFalse(conn1.willShutDownConsumerExecutor()); |
40 | 43 |
|
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()); |
43 | 47 |
|
44 | | - AMQConnection conn3 = (AMQConnection)cf.newConnection((ExecutorService)null); |
45 | | - assertTrue(conn3.willShutDownConsumerExecutor()); |
| 48 | + AMQConnection conn3 = (AMQConnection)cf.newConnection((ExecutorService)null); |
| 49 | + assertTrue(conn3.willShutDownConsumerExecutor()); |
46 | 50 |
|
47 | | - cf.setSharedExecutor(null); |
| 51 | + cf.setSharedExecutor(null); |
48 | 52 |
|
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 | + |
51 | 64 | } |
52 | 65 | } |
0 commit comments