|
51 | 51 | import org.springframework.amqp.AmqpAuthenticationException;
|
52 | 52 | import org.springframework.amqp.AmqpConnectException;
|
53 | 53 | import org.springframework.amqp.AmqpException;
|
| 54 | +import org.springframework.amqp.AmqpIOException; |
54 | 55 | import org.springframework.amqp.core.Address;
|
55 | 56 | import org.springframework.amqp.core.Message;
|
56 | 57 | import org.springframework.amqp.core.MessagePostProcessor;
|
|
61 | 62 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
62 | 63 | import org.springframework.amqp.rabbit.connection.ChannelProxy;
|
63 | 64 | import org.springframework.amqp.rabbit.connection.PublisherCallbackChannel;
|
| 65 | +import org.springframework.amqp.rabbit.connection.RabbitUtils; |
64 | 66 | import org.springframework.amqp.rabbit.connection.SimpleRoutingConnectionFactory;
|
65 | 67 | import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
|
66 | 68 | import org.springframework.amqp.support.converter.SimpleMessageConverter;
|
@@ -241,6 +243,62 @@ public void testEvaluateDirectReplyToWithConnectException() throws Exception {
|
241 | 243 | assertThat(TestUtils.getPropertyValue(template, "evaluatedFastReplyTo", Boolean.class)).isFalse();
|
242 | 244 | }
|
243 | 245 |
|
| 246 | + @Test |
| 247 | + public void testEvaluateDirectReplyToWithIOException() throws Exception { |
| 248 | + org.springframework.amqp.rabbit.connection.ConnectionFactory mockConnectionFactory = |
| 249 | + mock(org.springframework.amqp.rabbit.connection.ConnectionFactory.class); |
| 250 | + willThrow(new AmqpIOException(null)).given(mockConnectionFactory).createConnection(); |
| 251 | + RabbitTemplate template = new RabbitTemplate(mockConnectionFactory); |
| 252 | + assertThatThrownBy(() -> template.convertSendAndReceive("foo")).isInstanceOf(AmqpIOException.class); |
| 253 | + assertThat(TestUtils.getPropertyValue(template, "evaluatedFastReplyTo", Boolean.class)).isFalse(); |
| 254 | + } |
| 255 | + |
| 256 | + @Test |
| 257 | + public void testEvaluateDirectReplyToWithIOExceptionDeclareFailed() throws Exception { |
| 258 | + ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); |
| 259 | + Connection mockConnection = mock(Connection.class); |
| 260 | + Channel mockChannel = mock(Channel.class); |
| 261 | + |
| 262 | + given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); |
| 263 | + given(mockConnection.isOpen()).willReturn(true); |
| 264 | + given(mockConnection.createChannel()).willReturn(mockChannel); |
| 265 | + AMQP.Channel.Close mockMethod = mock(AMQP.Channel.Close.class); |
| 266 | + given(mockMethod.getReplyCode()).willReturn(AMQP.NOT_FOUND); |
| 267 | + given(mockMethod.getClassId()).willReturn(RabbitUtils.QUEUE_CLASS_ID_50); |
| 268 | + given(mockMethod.getMethodId()).willReturn(RabbitUtils.DECLARE_METHOD_ID_10); |
| 269 | + willThrow(new ShutdownSignalException(true, false, mockMethod, null)).given(mockChannel) |
| 270 | + .queueDeclarePassive(Address.AMQ_RABBITMQ_REPLY_TO); |
| 271 | + given(mockChannel.queueDeclare()).willReturn(new AMQImpl.Queue.DeclareOk("foo", 0, 0)); |
| 272 | + SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); |
| 273 | + connectionFactory.setExecutor(mock(ExecutorService.class)); |
| 274 | + RabbitTemplate template = new RabbitTemplate(connectionFactory); |
| 275 | + template.setReplyTimeout(1); |
| 276 | + template.convertSendAndReceive("foo"); |
| 277 | + assertThat(TestUtils.getPropertyValue(template, "evaluatedFastReplyTo", Boolean.class)).isTrue(); |
| 278 | + assertThat(TestUtils.getPropertyValue(template, "usingFastReplyTo", Boolean.class)).isFalse(); |
| 279 | + } |
| 280 | + |
| 281 | + @Test |
| 282 | + public void testEvaluateDirectReplyToOK() throws Exception { |
| 283 | + ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); |
| 284 | + Connection mockConnection = mock(Connection.class); |
| 285 | + Channel mockChannel = mock(Channel.class); |
| 286 | + given(mockChannel.isOpen()).willReturn(true); |
| 287 | + |
| 288 | + given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection); |
| 289 | + given(mockConnection.isOpen()).willReturn(true); |
| 290 | + given(mockConnection.createChannel()).willReturn(mockChannel); |
| 291 | + given(mockChannel.queueDeclarePassive(Address.AMQ_RABBITMQ_REPLY_TO)) |
| 292 | + .willReturn(new AMQImpl.Queue.DeclareOk(Address.AMQ_RABBITMQ_REPLY_TO, 0, 0)); |
| 293 | + SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); |
| 294 | + connectionFactory.setExecutor(mock(ExecutorService.class)); |
| 295 | + RabbitTemplate template = new RabbitTemplate(connectionFactory); |
| 296 | + template.setReplyTimeout(1); |
| 297 | + template.convertSendAndReceive("foo"); |
| 298 | + assertThat(TestUtils.getPropertyValue(template, "evaluatedFastReplyTo", Boolean.class)).isTrue(); |
| 299 | + assertThat(TestUtils.getPropertyValue(template, "usingFastReplyTo", Boolean.class)).isTrue(); |
| 300 | + } |
| 301 | + |
244 | 302 | @Test
|
245 | 303 | public void testRecovery() throws Exception {
|
246 | 304 | ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
|
|
0 commit comments