|
24 | 24 | import com.rabbitmq.client.impl.recovery.RecordedQueue;
|
25 | 25 | import com.rabbitmq.client.impl.recovery.TopologyRecoveryFilter;
|
26 | 26 | import com.rabbitmq.tools.Host;
|
| 27 | +import org.awaitility.Awaitility; |
| 28 | +import org.awaitility.Duration; |
27 | 29 | import org.junit.After;
|
28 | 30 | import org.junit.Before;
|
29 | 31 | import org.junit.Test;
|
|
37 | 39 | import java.util.concurrent.TimeoutException;
|
38 | 40 | import java.util.concurrent.atomic.AtomicInteger;
|
39 | 41 |
|
| 42 | +import static org.awaitility.Awaitility.waitAtMost; |
40 | 43 | import static org.junit.Assert.assertEquals;
|
41 | 44 | import static org.junit.Assert.assertTrue;
|
42 | 45 | import static org.junit.Assert.fail;
|
@@ -281,6 +284,28 @@ public void handleRecoveryStarted(Recoverable recoverable) {
|
281 | 284 | }
|
282 | 285 | }
|
283 | 286 |
|
| 287 | + @Test public void interruptingServerThreadShouldStopIt() throws Exception { |
| 288 | + rpcServer = new TestRpcServer(serverChannel, queue); |
| 289 | + Thread serverThread = new Thread(() -> { |
| 290 | + try { |
| 291 | + rpcServer.mainloop(); |
| 292 | + } catch (Exception e) { |
| 293 | + // safe to ignore when loops ends/server is canceled |
| 294 | + } |
| 295 | + }); |
| 296 | + serverThread.start(); |
| 297 | + RpcClient client = new RpcClient(new RpcClientParams() |
| 298 | + .channel(clientChannel).exchange("").routingKey(queue).timeout(1000)); |
| 299 | + RpcClient.Response response = client.doCall(null, "hello".getBytes()); |
| 300 | + assertEquals("*** hello ***", new String(response.getBody())); |
| 301 | + |
| 302 | + serverThread.interrupt(); |
| 303 | + |
| 304 | + waitAtMost(Duration.ONE_SECOND).until(() -> !serverThread.isAlive()) ; |
| 305 | + |
| 306 | + client.close(); |
| 307 | + } |
| 308 | + |
284 | 309 | private static class TestRpcServer extends RpcServer {
|
285 | 310 |
|
286 | 311 | public TestRpcServer(Channel channel, String queueName) throws IOException {
|
|
0 commit comments