|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
48 | 48 | import java.util.concurrent.atomic.AtomicReference;
|
49 | 49 |
|
50 | 50 | import org.apache.commons.logging.Log;
|
| 51 | +import org.assertj.core.api.InstanceOfAssertFactories; |
51 | 52 | import org.junit.jupiter.api.AfterEach;
|
52 | 53 | import org.junit.jupiter.api.BeforeEach;
|
53 | 54 | import org.junit.jupiter.api.Test;
|
@@ -130,6 +131,7 @@ public void create() {
|
130 | 131 | connectionFactoryWithReturnsEnabled.setPort(BrokerTestUtils.getPort());
|
131 | 132 | connectionFactoryWithReturnsEnabled.setPublisherReturns(true);
|
132 | 133 | templateWithReturnsEnabled = new RabbitTemplate(connectionFactoryWithReturnsEnabled);
|
| 134 | + templateWithReturnsEnabled.setMandatory(true); |
133 | 135 | connectionFactoryWithConfirmsAndReturnsEnabled = new CachingConnectionFactory();
|
134 | 136 | connectionFactoryWithConfirmsAndReturnsEnabled.setHost("localhost");
|
135 | 137 | connectionFactoryWithConfirmsAndReturnsEnabled.setChannelCacheSize(100);
|
@@ -320,6 +322,7 @@ public void testPublisherConfirmNotReceived() throws Exception {
|
320 | 322 | Connection mockConnection = mock(Connection.class);
|
321 | 323 | Channel mockChannel = mock(Channel.class);
|
322 | 324 | given(mockChannel.isOpen()).willReturn(true);
|
| 325 | + given(mockChannel.getNextPublishSeqNo()).willReturn(1L); |
323 | 326 |
|
324 | 327 | given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection);
|
325 | 328 | given(mockConnection.isOpen()).willReturn(true);
|
@@ -863,4 +866,32 @@ public void testWithFuture() throws Exception {
|
863 | 866 | admin.deleteQueue(queue.getName());
|
864 | 867 | }
|
865 | 868 |
|
| 869 | + @Test |
| 870 | + void justReturns() throws InterruptedException { |
| 871 | + CorrelationData correlationData = new CorrelationData(); |
| 872 | + CountDownLatch latch = new CountDownLatch(1); |
| 873 | + this.templateWithReturnsEnabled.setReturnsCallback(returned -> { |
| 874 | + latch.countDown(); |
| 875 | + }); |
| 876 | + this.templateWithReturnsEnabled.setConfirmCallback((correlationData1, ack, cause) -> { |
| 877 | + // has callback but factory is not enabled |
| 878 | + }); |
| 879 | + this.templateWithReturnsEnabled.convertAndSend("", ROUTE, "foo", correlationData); |
| 880 | + ChannelProxy channel = (ChannelProxy) this.connectionFactoryWithReturnsEnabled.createConnection() |
| 881 | + .createChannel(false); |
| 882 | + assertThat(channel.getTargetChannel()) |
| 883 | + .extracting("pendingReturns") |
| 884 | + .asInstanceOf(InstanceOfAssertFactories.MAP) |
| 885 | + .isEmpty(); |
| 886 | + assertThat(channel.getTargetChannel()) |
| 887 | + .extracting("pendingConfirms") |
| 888 | + .asInstanceOf(InstanceOfAssertFactories.MAP) |
| 889 | + .extracting(map -> map.values().iterator().next()) |
| 890 | + .asInstanceOf(InstanceOfAssertFactories.MAP) |
| 891 | + .isEmpty(); |
| 892 | + |
| 893 | + this.templateWithReturnsEnabled.convertAndSend("", "___JUNK___", "foo", correlationData); |
| 894 | + assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); |
| 895 | + } |
| 896 | + |
866 | 897 | }
|
0 commit comments