From d8e4a9d1147399ae332732fa05df717bd3d82b27 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 20 Apr 2016 14:12:59 -0400 Subject: [PATCH] Fix Partial Stubbing Problem in AMQP Tests https://build.spring.io/browse/INT-SONAR-1700/ We set up some stubbing on the `AsyncAmqpTemplate` to test nacks which are not easy to generate on a real broker. However, some acks might not have been consumed yet - this can cause partial stubbing errors, depending on timing. Be sure to consume all acks before stubbing the template. --- .../integration/amqp/outbound/AsyncAmqpGatewayTests.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java index 8ec916af21..727a7c682d 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java @@ -159,6 +159,8 @@ public class AsyncAmqpGatewayTests { }); gateway.handleMessage(message); assertNull(errorChannel.receive(1000)); + ack = ackChannel.receive(10000); + assertNotNull(ack); gateway.setRequiresReply(true); gateway.handleMessage(message); @@ -170,6 +172,8 @@ public class AsyncAmqpGatewayTests { assertThat(((MessagingException) error.getPayload()).getCause(), instanceOf(AmqpReplyTimeoutException.class)); asyncTemplate.setReceiveTimeout(30000); receiver.setMessageListener(messageListener); + ack = ackChannel.receive(10000); + assertNotNull(ack); // error on sending result DirectChannel errorForce = new DirectChannel(); @@ -195,7 +199,9 @@ public class AsyncAmqpGatewayTests { assertNotNull(returned); assertEquals("foo", returned.getPayload()); - // Simulate a nack - hard to get Rabbit to generate one + // Simulate a nack - it's hard to get Rabbit to generate one + // We must have consumed all the real acks by now, though, to prevent partial stubbing errors + RabbitMessageFuture future = asyncTemplate.new RabbitMessageFuture(null, null); doReturn(future).when(asyncTemplate).sendAndReceive(anyString(), anyString(), any(org.springframework.amqp.core.Message.class));