From a106e06a895f6bc0f8e8315daa0524635d0311c9 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 22 Jan 2014 16:43:21 -0500 Subject: [PATCH] Expose failing test in GenericMessagingTemplateTests Assertions made in callbacks invoked on separate thread were not reaching the test framework. This fix ensures failures are detected and cause tests to fail. --- .../core/GenericMessagingTemplateTests.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/spring-messaging/src/test/java/org/springframework/messaging/core/GenericMessagingTemplateTests.java b/spring-messaging/src/test/java/org/springframework/messaging/core/GenericMessagingTemplateTests.java index 4270552b74..6d1624b639 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/core/GenericMessagingTemplateTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/core/GenericMessagingTemplateTests.java @@ -18,6 +18,7 @@ package org.springframework.messaging.core; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; import org.junit.Before; import org.junit.Test; @@ -56,6 +57,7 @@ public class GenericMessagingTemplateTests { @Test public void sendAndReceive() { + SubscribableChannel channel = new ExecutorSubscribableChannel(this.executor); channel.subscribe(new MessageHandler() { @Override @@ -66,12 +68,13 @@ public class GenericMessagingTemplateTests { }); String actual = this.template.convertSendAndReceive(channel, "request", String.class); - assertEquals("response", actual); } @Test public void sendAndReceiveTimeout() throws InterruptedException { + + final AtomicReference failure = new AtomicReference(); final CountDownLatch latch = new CountDownLatch(1); this.template.setReceiveTimeout(1); @@ -85,14 +88,17 @@ public class GenericMessagingTemplateTests { Thread.sleep(500); MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel(); replyChannel.send(new GenericMessage("response")); - fail("Expected exception"); + failure.set(new IllegalStateException("Expected exception")); } catch (InterruptedException e) { - fail("Unexpected exception " + e.getMessage()); + failure.set(e); } catch (MessageDeliveryException ex) { - assertEquals("Reply message received but the receiving thread has already received a reply", - ex.getMessage()); + String expected = "Reply message received but the receiving thread has exited due to a timeout"; + String actual = ex.getMessage(); + if (!expected.equals(actual)) { + failure.set(new IllegalStateException("Unexpected error: '" + actual + "'")); + } } finally { latch.countDown(); @@ -101,8 +107,11 @@ public class GenericMessagingTemplateTests { }); assertNull(this.template.convertSendAndReceive(channel, "request", String.class)); - assertTrue(latch.await(1000, TimeUnit.MILLISECONDS)); + + if (failure.get() != null) { + throw new AssertionError(failure.get()); + } } }