Skip to content

Commit 8d41b89

Browse files
committed
AMQP-797: Defer caching publisher callback channel
JIRA: https://jira.spring.io/browse/AMQP-797 Additional test case (Ack Vs. Nack).
1 parent 8a38e65 commit 8d41b89

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplatePublisherCallbacksIntegrationTests3.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void testRepublishOnNackThreadNoExchange() throws Exception {
6666
}
6767

6868
@Test
69-
public void testDeferredChannelCache() throws Exception {
69+
public void testDeferredChannelCacheNack() throws Exception {
7070
final CachingConnectionFactory cf = new CachingConnectionFactory(
7171
RabbitAvailableCondition.getBrokerRunning().getConnectionFactory());
7272
cf.setPublisherReturns(true);
@@ -97,6 +97,32 @@ public void testDeferredChannelCache() throws Exception {
9797
cf.destroy();
9898
}
9999

100+
@Test
101+
public void testDeferredChannelCacheAck() throws Exception {
102+
final CachingConnectionFactory cf = new CachingConnectionFactory(
103+
RabbitAvailableCondition.getBrokerRunning().getConnectionFactory());
104+
cf.setPublisherConfirms(true);
105+
final RabbitTemplate template = new RabbitTemplate(cf);
106+
final CountDownLatch confirmLatch = new CountDownLatch(1);
107+
final AtomicInteger cacheCount = new AtomicInteger();
108+
template.setConfirmCallback((cd, a, c) -> {
109+
cacheCount.set(TestUtils.getPropertyValue(cf, "cachedChannelsNonTransactional", List.class).size());
110+
confirmLatch.countDown();
111+
});
112+
template.setMandatory(true);
113+
Connection conn = cf.createConnection();
114+
Channel channel1 = conn.createChannel(false);
115+
Channel channel2 = conn.createChannel(false);
116+
channel1.close();
117+
channel2.close();
118+
conn.close();
119+
assertThat(TestUtils.getPropertyValue(cf, "cachedChannelsNonTransactional", List.class).size()).isEqualTo(2);
120+
template.convertAndSend("", QUEUE2, "foo", new MyCD("foo"));
121+
assertThat(confirmLatch.await(10, TimeUnit.SECONDS)).isTrue();
122+
assertThat(cacheCount.get()).isEqualTo(1);
123+
cf.destroy();
124+
}
125+
100126
private static class MyCD extends CorrelationData {
101127

102128
private final String payload;

0 commit comments

Comments
 (0)