|
1 | 1 | package com.rabbitmq.client.test.functional;
|
2 | 2 |
|
3 | 3 | import com.rabbitmq.client.*;
|
4 |
| -import com.rabbitmq.client.impl.recovery.AutorecoveringChannel; |
5 |
| -import com.rabbitmq.client.impl.recovery.AutorecoveringConnection; |
| 4 | +import com.rabbitmq.client.impl.AMQConnection; |
| 5 | +import com.rabbitmq.client.impl.recovery.*; |
6 | 6 | import com.rabbitmq.client.Recoverable;
|
7 | 7 | import com.rabbitmq.client.RecoveryListener;
|
8 |
| -import com.rabbitmq.client.impl.recovery.ConsumerRecoveryListener; |
9 |
| -import com.rabbitmq.client.impl.recovery.QueueRecoveryListener; |
10 | 8 | import com.rabbitmq.client.test.BrokerTestCase;
|
11 | 9 | import com.rabbitmq.tools.Host;
|
12 | 10 |
|
@@ -90,6 +88,44 @@ public void testConnectionRecoveryWithDisabledTopologyRecovery()
|
90 | 88 | }
|
91 | 89 | }
|
92 | 90 |
|
| 91 | + // see https://github.com/rabbitmq/rabbitmq-java-client/issues/135 |
| 92 | + public void testThatShutdownHooksOnConnectionFireBeforeRecoveryStarts() throws IOException, InterruptedException { |
| 93 | + final List<String> events = new ArrayList<String>(); |
| 94 | + final CountDownLatch latch = new CountDownLatch(1); |
| 95 | + connection.addShutdownListener(new ShutdownListener() { |
| 96 | + public void shutdownCompleted(ShutdownSignalException cause) { |
| 97 | + events.add("shutdown hook 1"); |
| 98 | + } |
| 99 | + }); |
| 100 | + connection.addShutdownListener(new ShutdownListener() { |
| 101 | + public void shutdownCompleted(ShutdownSignalException cause) { |
| 102 | + events.add("shutdown hook 2"); |
| 103 | + } |
| 104 | + }); |
| 105 | + // note: we do not want to expose RecoveryCanBeginListener so this |
| 106 | + // test does not use it |
| 107 | + ((AutorecoveringConnection)connection).getDelegate().addRecoveryCanBeginListener(new RecoveryCanBeginListener() { |
| 108 | + @Override |
| 109 | + public void recoveryCanBegin(ShutdownSignalException cause) { |
| 110 | + events.add("recovery start hook 1"); |
| 111 | + } |
| 112 | + }); |
| 113 | + ((AutorecoveringConnection)connection).addRecoveryListener(new RecoveryListener() { |
| 114 | + @Override |
| 115 | + public void handleRecovery(Recoverable recoverable) { |
| 116 | + latch.countDown(); |
| 117 | + } |
| 118 | + }); |
| 119 | + assertTrue(connection.isOpen()); |
| 120 | + closeAndWaitForRecovery(); |
| 121 | + assertTrue(connection.isOpen()); |
| 122 | + assertEquals("shutdown hook 1", events.get(0)); |
| 123 | + assertEquals("shutdown hook 2", events.get(1)); |
| 124 | + assertEquals("recovery start hook 1", events.get(2)); |
| 125 | + connection.close(); |
| 126 | + wait(latch); |
| 127 | + } |
| 128 | + |
93 | 129 | public void testShutdownHooksRecoveryOnConnection() throws IOException, InterruptedException {
|
94 | 130 | final CountDownLatch latch = new CountDownLatch(2);
|
95 | 131 | connection.addShutdownListener(new ShutdownListener() {
|
|
0 commit comments