Skip to content

Commit 521ff0a

Browse files
committed
Fix SimpleMessageListenerContainerTests logic
Looks like the `logger` property cannot be spied. At least not all the time. * Rework `SimpleMessageListenerContainerTests.testShutdownWithPendingReplies()` logic to spy on the `ActiveObjectCounter` from the `RabbitTemplate` instead. * Verify that `ActiveObjectCounter.await()` is called from the listener container instead unreliable logger spy
1 parent a9024e0 commit 521ff0a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/SimpleMessageListenerContainerTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ void testWithConsumerStartWhenNotActive() {
720720
}
721721

722722
@Test
723-
@SuppressWarnings("unchecked")
724723
void testShutdownWithPendingReplies() {
725724
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
726725
Connection connection = mock(Connection.class);
@@ -742,19 +741,19 @@ void testShutdownWithPendingReplies() {
742741
ActiveObjectCounter<Object> replyCounter = template.getPendingReplyCounter();
743742
assertThat(replyCounter).isNotNull();
744743

745-
Object pending = new Object();
746-
replyCounter.add(pending);
747-
assertThat(replyCounter.getCount()).isEqualTo(1);
744+
var spyReplyCounter = spy(replyCounter);
745+
new DirectFieldAccessor(template).setPropertyValue("pendingRepliesCounter", spyReplyCounter);
748746

749-
Log logger = spy(TestUtils.getPropertyValue(container, "logger", Log.class));
750-
new DirectFieldAccessor(container).setPropertyValue("logger", logger);
747+
replyCounter.add(new Object());
751748

752749
container.start();
753750

754751
container.stop();
755752

756753
await().untilAsserted(() ->
757-
verify(logger).warn("Shutdown timeout expired, but 1 pending replies still remain."));
754+
assertThat(verify(spyReplyCounter).await(shutdownTimeout, TimeUnit.MILLISECONDS)).isFalse());
755+
756+
assertThat(replyCounter.getCount()).isEqualTo(1);
758757
}
759758

760759
private Answer<Object> messageToConsumer(final Channel mockChannel, final SimpleMessageListenerContainer container,

0 commit comments

Comments
 (0)