|
18 | 18 |
|
19 | 19 | import static org.hamcrest.Matchers.containsString;
|
20 | 20 | import static org.hamcrest.Matchers.equalTo;
|
| 21 | +import static org.hamcrest.Matchers.instanceOf; |
21 | 22 | import static org.junit.Assert.assertEquals;
|
| 23 | +import static org.junit.Assert.assertFalse; |
22 | 24 | import static org.junit.Assert.assertSame;
|
23 | 25 | import static org.junit.Assert.assertThat;
|
24 | 26 | import static org.junit.Assert.assertTrue;
|
|
28 | 30 | import static org.mockito.ArgumentMatchers.isNull;
|
29 | 31 | import static org.mockito.BDDMockito.given;
|
30 | 32 | import static org.mockito.BDDMockito.willReturn;
|
| 33 | +import static org.mockito.BDDMockito.willThrow; |
31 | 34 | import static org.mockito.Mockito.doAnswer;
|
32 | 35 | import static org.mockito.Mockito.mock;
|
33 | 36 | import static org.mockito.Mockito.times;
|
|
49 | 52 | import org.mockito.Mockito;
|
50 | 53 |
|
51 | 54 | import org.springframework.amqp.AmqpAuthenticationException;
|
| 55 | +import org.springframework.amqp.AmqpConnectException; |
52 | 56 | import org.springframework.amqp.core.Address;
|
53 | 57 | import org.springframework.amqp.core.Message;
|
54 | 58 | import org.springframework.amqp.core.MessageProperties;
|
|
63 | 67 | import org.springframework.amqp.rabbit.support.PublisherCallbackChannel;
|
64 | 68 | import org.springframework.amqp.support.converter.SimpleMessageConverter;
|
65 | 69 | import org.springframework.amqp.utils.SerializationUtils;
|
| 70 | +import org.springframework.amqp.utils.test.TestUtils; |
66 | 71 | import org.springframework.context.ApplicationContext;
|
67 | 72 | import org.springframework.expression.Expression;
|
68 | 73 | import org.springframework.expression.spel.standard.SpelExpressionParser;
|
@@ -227,6 +232,23 @@ public void testRetry() throws Exception {
|
227 | 232 | assertEquals(3, count.get());
|
228 | 233 | }
|
229 | 234 |
|
| 235 | + @Test |
| 236 | + public void testEvaluateDirectReplyToWithConnectException() { |
| 237 | + org.springframework.amqp.rabbit.connection.ConnectionFactory mockConnectionFactory = |
| 238 | + mock(org.springframework.amqp.rabbit.connection.ConnectionFactory.class); |
| 239 | + willThrow(new AmqpConnectException(null)).given(mockConnectionFactory).createConnection(); |
| 240 | + RabbitTemplate template = new RabbitTemplate(mockConnectionFactory); |
| 241 | + |
| 242 | + try { |
| 243 | + template.convertSendAndReceive("foo"); |
| 244 | + } |
| 245 | + catch (Exception ex) { |
| 246 | + assertThat(ex, instanceOf(AmqpConnectException.class)); |
| 247 | + } |
| 248 | + |
| 249 | + assertFalse(TestUtils.getPropertyValue(template, "evaluatedFastReplyTo", Boolean.class)); |
| 250 | + } |
| 251 | + |
230 | 252 | @Test
|
231 | 253 | public void testRecovery() throws Exception {
|
232 | 254 | ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
|
|
0 commit comments