-
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
Changes from 4 commits
368fe54
1a48e51
7a732db
cc2e48c
1dd2d72
00487ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,45 @@ 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 = 2000L; | ||
| container.setShutdownTimeout(shutdownTimeout); | ||
|
|
||
| ActiveObjectCounter<Object> replyCounter = | ||
| (ActiveObjectCounter<Object>) ReflectionTestUtils.getField(template, "pendingRepliesCounter"); | ||
|
||
| assertThat(replyCounter).isNotNull(); | ||
|
|
||
| Object pending = new Object(); | ||
| replyCounter.add(pending); | ||
| assertThat(replyCounter.getCount()).isEqualTo(1); | ||
|
|
||
| container.start(); | ||
|
|
||
| long startTime = System.currentTimeMillis(); | ||
| container.stop(); | ||
| long stopDuration = System.currentTimeMillis() - startTime; | ||
|
||
|
|
||
| replyCounter.release(pending); | ||
|
||
|
|
||
| assertThat(stopDuration).isGreaterThanOrEqualTo(shutdownTimeout - 500); | ||
| } | ||
|
|
||
| private Answer<Object> messageToConsumer(final Channel mockChannel, final SimpleMessageListenerContainer container, | ||
| final boolean cancel, final CountDownLatch latch) { | ||
| return invocation -> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,4 +36,9 @@ There is no need to keep out-dated utilities and recommendation is to migrate to | |
| The Jackson 2 has been deprecated for removal in whole Spring portfolio. | ||
| Respective new classes have been introduced to support Jackson 3. | ||
|
|
||
| See xref:amqp/message-converters.adoc[] for more information. | ||
| See xref:amqp/message-converters.adoc[] for more information. | ||
|
|
||
| [[x40-enhancements]] | ||
| === Enhancements | ||
|
||
|
|
||
| Defer `SimpleMessageListenerContainer` shutdown for pending `RabbitTemplate` replies. | ||
|
||
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 don't think we need to wait for "never reply" so long.
We deliberately aware that reply never comes back to us in this testing scenario.
So, what is the point to block this test for those 2 seconds?
Now imaging that every single 3000 tests in the project is going to block for similar time.
That would be a disaster for development feedback loop.
I think we should make like
500millis at most.