|
34 | 34 | import com.rabbitmq.client.impl.recovery.RecordedQueue; |
35 | 35 | import com.rabbitmq.client.impl.recovery.TopologyRecoveryFilter; |
36 | 36 | import com.rabbitmq.tools.Host; |
| 37 | +import org.awaitility.Awaitility; |
| 38 | +import org.awaitility.Duration; |
37 | 39 | import org.junit.After; |
38 | 40 | import org.junit.Before; |
39 | 41 | import org.junit.Test; |
|
47 | 49 | import java.util.concurrent.TimeoutException; |
48 | 50 | import java.util.concurrent.atomic.AtomicInteger; |
49 | 51 |
|
| 52 | +import static org.awaitility.Awaitility.waitAtMost; |
50 | 53 | import static org.junit.Assert.assertEquals; |
51 | 54 | import static org.junit.Assert.assertTrue; |
52 | 55 | import static org.junit.Assert.fail; |
@@ -315,6 +318,28 @@ public void handleRecoveryStarted(Recoverable recoverable) { |
315 | 318 | } |
316 | 319 | } |
317 | 320 |
|
| 321 | + @Test public void interruptingServerThreadShouldStopIt() throws Exception { |
| 322 | + rpcServer = new TestRpcServer(serverChannel, queue); |
| 323 | + Thread serverThread = new Thread(() -> { |
| 324 | + try { |
| 325 | + rpcServer.mainloop(); |
| 326 | + } catch (Exception e) { |
| 327 | + // safe to ignore when loops ends/server is canceled |
| 328 | + } |
| 329 | + }); |
| 330 | + serverThread.start(); |
| 331 | + RpcClient client = new RpcClient(new RpcClientParams() |
| 332 | + .channel(clientChannel).exchange("").routingKey(queue).timeout(1000)); |
| 333 | + RpcClient.Response response = client.doCall(null, "hello".getBytes()); |
| 334 | + assertEquals("*** hello ***", new String(response.getBody())); |
| 335 | + |
| 336 | + serverThread.interrupt(); |
| 337 | + |
| 338 | + waitAtMost(Duration.ONE_SECOND).until(() -> !serverThread.isAlive()) ; |
| 339 | + |
| 340 | + client.close(); |
| 341 | + } |
| 342 | + |
318 | 343 | private static class TestRpcServer extends RpcServer { |
319 | 344 |
|
320 | 345 | public TestRpcServer(Channel channel, String queueName) throws IOException { |
|
0 commit comments