Skip to content

Commit 1dd2d72

Browse files
committed
Refine test and update whats-new
This commit applies the final polishing suggestions from the review. - The test case is refactored to be more robust and efficient. It now verifies the warning log message via a spy instead of relying on unstable timing assertions. The shutdown timeout is also reduced to speed up the build. - The `whats-new.adoc` document is updated with the title and description suggested in the review. Signed-off-by: Jeongjun Min <[email protected]>
1 parent cc2e48c commit 1dd2d72

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -736,26 +736,28 @@ void testShutdownWithPendingReplies() {
736736

737737
template.setReplyAddress(container.getQueueNames()[0]);
738738

739-
long shutdownTimeout = 2000L;
739+
long shutdownTimeout = 500L;
740740
container.setShutdownTimeout(shutdownTimeout);
741741

742-
ActiveObjectCounter<Object> replyCounter =
743-
(ActiveObjectCounter<Object>) ReflectionTestUtils.getField(template, "pendingRepliesCounter");
742+
ActiveObjectCounter<Object> replyCounter = template.getPendingReplyCounter();
744743
assertThat(replyCounter).isNotNull();
745744

746745
Object pending = new Object();
747746
replyCounter.add(pending);
748747
assertThat(replyCounter.getCount()).isEqualTo(1);
749748

749+
Log logger = spy(TestUtils.getPropertyValue(container, "logger", Log.class));
750+
new DirectFieldAccessor(container).setPropertyValue("logger", logger);
751+
750752
container.start();
751753

752-
long startTime = System.currentTimeMillis();
753754
container.stop();
754-
long stopDuration = System.currentTimeMillis() - startTime;
755755

756-
replyCounter.release(pending);
756+
await().atMost(Duration.ofMillis(500)).untilAsserted(() ->
757+
verify(logger).warn("Shutdown timeout expired, but 1 pending replies still remain.")
758+
);
757759

758-
assertThat(stopDuration).isGreaterThanOrEqualTo(shutdownTimeout - 500);
760+
replyCounter.release(pending);
759761
}
760762

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

src/reference/antora/modules/ROOT/pages/whats-new.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Respective new classes have been introduced to support Jackson 3.
3838

3939
See xref:amqp/message-converters.adoc[] for more information.
4040

41-
[[x40-enhancements]]
42-
=== Enhancements
41+
[[x40-smlc-changes]]
42+
=== MessageListenerContainer Changes
4343

44-
Defer `SimpleMessageListenerContainer` shutdown for pending `RabbitTemplate` replies.
44+
The `SimpleMessageListenerContainer` now awaits at most `shutdownTimeout` for pending replies from the provided `RabbitTemplate` listener on its shutdown.

0 commit comments

Comments
 (0)