@Override protected void doStop() { this.template.stop(); super.doStop(); }
@Override public void stop(Runnable callback) { stop(); callback.run(); }
@Override public void stop(Runnable callback) { stop(); callback.run(); }
@Override protected void doStop() { this.template.stop(); super.doStop(); }
assertEquals("nacknack", nack.getNackReason()); asyncTemplate.stop(); receiver.stop(); ccf.destroy();
@Test public void testMessage1ArgDirect() throws Exception { this.latch.set(new CountDownLatch(1)); ListenableFuture<Message> future1 = this.asyncDirectTemplate.sendAndReceive(getFooMessage()); ListenableFuture<Message> future2 = this.asyncDirectTemplate.sendAndReceive(getFooMessage()); this.latch.get().countDown(); Message reply1 = checkMessageResult(future1, "FOO"); assertEquals(Address.AMQ_RABBITMQ_REPLY_TO, reply1.getMessageProperties().getConsumerQueue()); Message reply2 = checkMessageResult(future2, "FOO"); assertEquals(Address.AMQ_RABBITMQ_REPLY_TO, reply2.getMessageProperties().getConsumerQueue()); this.latch.set(null); waitForZeroInUseConsumers(); assertThat(TestUtils .getPropertyValue(this.asyncDirectTemplate, "directReplyToContainer.consumerCount", Integer.class), equalTo(2)); this.asyncDirectTemplate.stop(); this.asyncDirectTemplate.start(); assertThat(TestUtils .getPropertyValue(this.asyncDirectTemplate, "directReplyToContainer.consumerCount", Integer.class), equalTo(0)); }
@Test public void testConvert1ArgDirect() throws Exception { this.latch.set(new CountDownLatch(1)); ListenableFuture<String> future1 = this.asyncDirectTemplate.convertSendAndReceive("foo"); ListenableFuture<String> future2 = this.asyncDirectTemplate.convertSendAndReceive("bar"); this.latch.get().countDown(); checkConverterResult(future1, "FOO"); checkConverterResult(future2, "BAR"); this.latch.set(null); waitForZeroInUseConsumers(); assertThat(TestUtils .getPropertyValue(this.asyncDirectTemplate, "directReplyToContainer.consumerCount", Integer.class), equalTo(2)); final String missingQueue = UUID.randomUUID().toString(); this.asyncDirectTemplate.convertSendAndReceive("", missingQueue, "foo"); // send to nowhere this.asyncDirectTemplate.stop(); // should clear the inUse channel map waitForZeroInUseConsumers(); this.asyncDirectTemplate.start(); this.asyncDirectTemplate.setReceiveTimeout(1); this.asyncDirectTemplate.convertSendAndReceive("", missingQueue, "foo"); // send to nowhere waitForZeroInUseConsumers(); this.asyncDirectTemplate.setReceiveTimeout(10000); this.asyncDirectTemplate.convertSendAndReceive("", missingQueue, "foo").cancel(true); waitForZeroInUseConsumers(); }
@Test @DirtiesContext public void testStopCancelled() throws Exception { this.asyncTemplate.setReceiveTimeout(5000); RabbitConverterFuture<String> future = this.asyncTemplate.convertSendAndReceive("noReply"); TheCallback callback = new TheCallback(); future.addCallback(callback); assertEquals(1, TestUtils.getPropertyValue(this.asyncTemplate, "pending", Map.class).size()); this.asyncTemplate.stop(); // Second stop() to be sure that it is idempotent this.asyncTemplate.stop(); try { future.get(10, TimeUnit.SECONDS); fail("Expected CancellationException"); } catch (CancellationException e) { assertEquals("AsyncRabbitTemplate was stopped while waiting for reply", future.getNackCause()); } assertEquals(0, TestUtils.getPropertyValue(this.asyncTemplate, "pending", Map.class).size()); assertTrue(callback.latch.await(10, TimeUnit.SECONDS)); assertTrue(future.isCancelled()); assertNull(TestUtils.getPropertyValue(this.asyncTemplate, "taskScheduler")); /* * Test there's no harm if the reply is received after the cancel. This * should never happen because the container is stopped before canceling * and the future is removed from the pending map. */ future.set("foo"); assertNull(callback.result); }