-
Notifications
You must be signed in to change notification settings - Fork 646
GH-3031: Defer SMLC shutdown for pending replies #3147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
368fe54
GH-3031: Defer SMLC shutdown for pending replies
m3k0813 1a48e51
Fix checkstyle violations
m3k0813 7a732db
Apply review suggestions for shutdown deferral
m3k0813 cc2e48c
Refactor shutdown deferral logic based on review feedback
m3k0813 1dd2d72
Refine test and update whats-new
m3k0813 00487ae
Refine shutdown deferral test for robustness
m3k0813 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,9 @@ | |
| import org.springframework.amqp.rabbit.connection.Connection; | ||
| import org.springframework.amqp.rabbit.connection.ConnectionFactory; | ||
| import org.springframework.amqp.rabbit.connection.SingleConnectionFactory; | ||
| import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
| import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter; | ||
| import org.springframework.amqp.rabbit.support.ActiveObjectCounter; | ||
| import org.springframework.amqp.utils.test.TestUtils; | ||
| import org.springframework.aop.support.AopUtils; | ||
| import org.springframework.beans.DirectFieldAccessor; | ||
|
|
@@ -102,6 +104,7 @@ | |
| * @author Yansong Ren | ||
| * @author Tim Bourquin | ||
| * @author Jeonggi Kim | ||
| * @author Jeongjun Min | ||
| */ | ||
| public class SimpleMessageListenerContainerTests { | ||
|
|
||
|
|
@@ -716,6 +719,47 @@ void testWithConsumerStartWhenNotActive() { | |
| assertThat(start.getCount()).isEqualTo(0L); | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressWarnings("unchecked") | ||
| void testShutdownWithPendingReplies() { | ||
| ConnectionFactory connectionFactory = mock(ConnectionFactory.class); | ||
| Connection connection = mock(Connection.class); | ||
| Channel channel = mock(Channel.class); | ||
| given(connectionFactory.createConnection()).willReturn(connection); | ||
| given(connection.createChannel(false)).willReturn(channel); | ||
| given(channel.isOpen()).willReturn(true); | ||
|
|
||
| RabbitTemplate template = new RabbitTemplate(connectionFactory); | ||
| SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); | ||
| container.setQueueNames("shutdown.test.queue"); | ||
| container.setMessageListener(template); | ||
|
|
||
| template.setReplyAddress(container.getQueueNames()[0]); | ||
|
|
||
| long shutdownTimeout = 500L; | ||
| container.setShutdownTimeout(shutdownTimeout); | ||
|
|
||
| ActiveObjectCounter<Object> replyCounter = template.getPendingReplyCounter(); | ||
| assertThat(replyCounter).isNotNull(); | ||
|
|
||
| Object pending = new Object(); | ||
| replyCounter.add(pending); | ||
| assertThat(replyCounter.getCount()).isEqualTo(1); | ||
|
|
||
| Log logger = spy(TestUtils.getPropertyValue(container, "logger", Log.class)); | ||
| new DirectFieldAccessor(container).setPropertyValue("logger", logger); | ||
|
|
||
| container.start(); | ||
|
|
||
| container.stop(); | ||
|
|
||
| await().atMost(Duration.ofMillis(500)).untilAsserted(() -> | ||
| verify(logger).warn("Shutdown timeout expired, but 1 pending replies still remain.") | ||
| ); | ||
|
|
||
| replyCounter.release(pending); | ||
|
||
| } | ||
|
|
||
| private Answer<Object> messageToConsumer(final Channel mockChannel, final SimpleMessageListenerContainer container, | ||
| final boolean cancel, final CountDownLatch latch) { | ||
| return invocation -> { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think those max 30 seconds by default is fine with us in our tests.
It is really not going to be blocked that long.
Might really maximum those 500 millis.
However, if we have it as exact our given time, there is no guarantee that CPU resources will be available for us in time to satisfy this expectation.