|
54 | 54 | import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
55 | 55 | import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
|
56 | 56 | import org.springframework.amqp.rabbit.listener.adapter.ReplyingMessageListener;
|
| 57 | +import org.springframework.amqp.support.converter.MessageConversionException; |
57 | 58 | import org.springframework.amqp.support.converter.SimpleMessageConverter;
|
58 | 59 | import org.springframework.amqp.support.postprocessor.GUnzipPostProcessor;
|
59 | 60 | import org.springframework.amqp.support.postprocessor.GZipPostProcessor;
|
@@ -301,7 +302,7 @@ public void testMessageWithConfirmDirect() throws Exception {
|
301 | 302 | assertThat(confirm.get(10, TimeUnit.SECONDS)).isTrue();
|
302 | 303 | checkMessageResult(future, "SLEEP");
|
303 | 304 | }
|
304 |
| - |
| 305 | + |
305 | 306 | @SuppressWarnings("unchecked")
|
306 | 307 | @Test
|
307 | 308 | @DirtiesContext
|
@@ -386,6 +387,34 @@ public void testStopCancelled() throws Exception {
|
386 | 387 | assertThat(callback.result).isNull();
|
387 | 388 | }
|
388 | 389 |
|
| 390 | + @Test |
| 391 | + public void testConversionException() throws InterruptedException { |
| 392 | + CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost"); |
| 393 | + connectionFactory.setChannelCacheSize(1); |
| 394 | + RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); |
| 395 | + rabbitTemplate.setMessageConverter(new SimpleMessageConverter(){ |
| 396 | + @Override |
| 397 | + public Object fromMessage(Message message) throws MessageConversionException { |
| 398 | + throw new MessageConversionException("Failed to convert message"); |
| 399 | + } |
| 400 | + }); |
| 401 | + AsyncRabbitTemplate asyncRabbitTemplate = new AsyncRabbitTemplate(rabbitTemplate); |
| 402 | + asyncRabbitTemplate.start(); |
| 403 | + |
| 404 | + RabbitConverterFuture<String> replyFuture = asyncRabbitTemplate.convertSendAndReceive("conversionException"); |
| 405 | + |
| 406 | + CountDownLatch cdl = new CountDownLatch(1); |
| 407 | + replyFuture.whenComplete((result, ex) -> { |
| 408 | + cdl.countDown(); |
| 409 | + }); |
| 410 | + assertThat(cdl.await(10, TimeUnit.SECONDS)).isTrue(); |
| 411 | + assertThat(replyFuture).isCompletedExceptionally(); |
| 412 | + |
| 413 | + asyncRabbitTemplate.stop(); |
| 414 | + connectionFactory.destroy(); |
| 415 | + } |
| 416 | + |
| 417 | + |
389 | 418 | @Test
|
390 | 419 | void ctorCoverage() {
|
391 | 420 | AsyncRabbitTemplate template = new AsyncRabbitTemplate(mock(ConnectionFactory.class), "ex", "rk");
|
@@ -603,7 +632,7 @@ public SimpleMessageListenerContainer remoteContainer(ConnectionFactory connecti
|
603 | 632 | }
|
604 | 633 | else if ("noReply".equals(message)) {
|
605 | 634 | return null;
|
606 |
| - } |
| 635 | + } |
607 | 636 | return message.toUpperCase();
|
608 | 637 | });
|
609 | 638 |
|
|
0 commit comments