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.
This commit is contained in:
Gary Russell
2016-04-20 14:12:59 -04:00
parent 818387f0a4
commit d8e4a9d114

View File

@@ -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));