Skip to content

Commit d7a08aa

Browse files
committed
Fix checkstyle violations
1 parent 368fe54 commit d7a08aa

File tree

2 files changed

+54
-37
lines changed

2 files changed

+54
-37
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/api/PendingReplyProvider.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2025-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.amqp.rabbit.listener.api;
218

319
/**
@@ -16,4 +32,4 @@ public interface PendingReplyProvider {
1632
* @return the number of pending replies.
1733
*/
1834
int getPendingReplyCount();
19-
}
35+
}

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

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,43 @@ void testWithConsumerStartWhenNotActive() {
718718
assertThat(start.getCount()).isEqualTo(0L);
719719
}
720720

721+
@Test
722+
@SuppressWarnings("unchecked")
723+
void testShutdownWithPendingReplies() {
724+
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
725+
Connection connection = mock(Connection.class);
726+
Channel channel = mock(Channel.class);
727+
given(connectionFactory.createConnection()).willReturn(connection);
728+
given(connection.createChannel(false)).willReturn(channel);
729+
given(channel.isOpen()).willReturn(true);
730+
731+
RabbitTemplate template = new RabbitTemplate(connectionFactory);
732+
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
733+
container.setQueueNames("foo");
734+
container.setMessageListener(mock(MessageListener.class));
735+
736+
long shutdownTimeout = 2000L;
737+
long checkInterval = 500L;
738+
container.setShutdownTimeout(shutdownTimeout);
739+
container.setPendingReplyCheckInterval(checkInterval);
740+
container.setPendingReplyProvider(template::getPendingReplyCount);
741+
742+
Map<String, Object> replyHolder = (Map<String, Object>) ReflectionTestUtils.getField(template, "replyHolder");
743+
assertThat(replyHolder).isNotNull();
744+
replyHolder.put("foo", new CompletableFuture<Message>());
745+
746+
assertThat(template.getPendingReplyCount()).isEqualTo(1);
747+
748+
container.start();
749+
750+
long startTime = System.currentTimeMillis();
751+
container.stop();
752+
long stopDuration = System.currentTimeMillis() - startTime;
753+
754+
assertThat(stopDuration).isGreaterThanOrEqualTo(shutdownTimeout - 500);
755+
assertThat(template.getPendingReplyCount()).isEqualTo(1);
756+
}
757+
721758
private Answer<Object> messageToConsumer(final Channel mockChannel, final SimpleMessageListenerContainer container,
722759
final boolean cancel, final CountDownLatch latch) {
723760
return invocation -> {
@@ -801,40 +838,4 @@ public void execute(Runnable task) {
801838

802839
}
803840

804-
@Test
805-
@SuppressWarnings("unchecked")
806-
void testShutdownWithPendingReplies() {
807-
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
808-
Connection connection = mock(Connection.class);
809-
Channel channel = mock(Channel.class);
810-
given(connectionFactory.createConnection()).willReturn(connection);
811-
given(connection.createChannel(false)).willReturn(channel);
812-
given(channel.isOpen()).willReturn(true);
813-
814-
RabbitTemplate template = new RabbitTemplate(connectionFactory);
815-
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
816-
container.setQueueNames("foo");
817-
container.setMessageListener(mock(MessageListener.class));
818-
819-
long shutdownTimeout = 2000L;
820-
long checkInterval = 500L;
821-
container.setShutdownTimeout(shutdownTimeout);
822-
container.setPendingReplyCheckInterval(checkInterval);
823-
container.setPendingReplyProvider(template::getPendingReplyCount);
824-
825-
Map<String, Object> replyHolder = (Map<String, Object>) ReflectionTestUtils.getField(template, "replyHolder");
826-
assertThat(replyHolder).isNotNull();
827-
replyHolder.put("foo", new CompletableFuture<Message>());
828-
829-
assertThat(template.getPendingReplyCount()).isEqualTo(1);
830-
831-
container.start();
832-
833-
long startTime = System.currentTimeMillis();
834-
container.stop();
835-
long stopDuration = System.currentTimeMillis() - startTime;
836-
837-
assertThat(stopDuration).isGreaterThanOrEqualTo(shutdownTimeout - 500);
838-
assertThat(template.getPendingReplyCount()).isEqualTo(1);
839-
}
840841
}

0 commit comments

Comments
 (0)