diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/TransactionSynchronizationQueueChannelTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/channel/TransactionSynchronizationQueueChannelTests-context.xml
index 7765d1791d..881217e7db 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/channel/TransactionSynchronizationQueueChannelTests-context.xml
+++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/TransactionSynchronizationQueueChannelTests-context.xml
@@ -5,6 +5,11 @@
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+
+
+
@@ -15,7 +20,6 @@
-
@@ -26,8 +30,6 @@
-
-
@@ -43,8 +45,4 @@
channel="good" />
-
-
-
-
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/channel/TransactionSynchronizationQueueChannelTests.java b/spring-integration-core/src/test/java/org/springframework/integration/channel/TransactionSynchronizationQueueChannelTests.java
index 843e39c3d8..9727d32992 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/channel/TransactionSynchronizationQueueChannelTests.java
+++ b/spring-integration-core/src/test/java/org/springframework/integration/channel/TransactionSynchronizationQueueChannelTests.java
@@ -18,20 +18,17 @@ package org.springframework.integration.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.messaging.Message;
-import org.springframework.messaging.PollableChannel;
-import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
+import org.springframework.messaging.Message;
+import org.springframework.messaging.support.GenericMessage;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -42,27 +39,30 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
+@DirtiesContext
public class TransactionSynchronizationQueueChannelTests {
@Autowired
- private PollableChannel queueChannel;
+ private QueueChannel queueChannel;
@Autowired
- private PollableChannel good;
+ private QueueChannel good;
@Autowired
- private Service service;
+ private QueueChannel queueChannel2;
- @Autowired
- private PollableChannel queueChannel2;
+ @Before
+ public void setup() {
+ this.good.purge(null);
+ this.queueChannel.purge(null);
+ this.queueChannel2.purge(null);
+ }
@Test
public void testCommit() throws Exception {
- service.latch = new CountDownLatch(1);
- GenericMessage sentMessage = new GenericMessage("hello");
- queueChannel.send(sentMessage);
- assertTrue(service.latch.await(10, TimeUnit.SECONDS));
- Message> message = good.receive(1000);
+ GenericMessage sentMessage = new GenericMessage<>("hello");
+ this.queueChannel.send(sentMessage);
+ Message> message = this.good.receive(10000);
assertNotNull(message);
assertEquals("hello", message.getPayload());
assertSame(message, sentMessage);
@@ -70,38 +70,32 @@ public class TransactionSynchronizationQueueChannelTests {
@Test
public void testRollback() throws Exception {
- service.latch = new CountDownLatch(1);
- queueChannel.send(new GenericMessage("fail"));
- assertTrue(service.latch.await(10, TimeUnit.SECONDS));
- Message> message = queueChannel.receive(1000);
+ this.queueChannel.send(new GenericMessage<>("fail"));
+ Message> message = this.good.receive(10000);
assertNotNull(message);
assertEquals("retry:fail", message.getPayload());
- assertNull(good.receive(0));
}
@Test
public void testIncludeChannelName() throws Exception {
- service.latch = new CountDownLatch(1);
Message sentMessage = MessageBuilder.withPayload("hello")
.setHeader("foo", "bar").build();
queueChannel2.send(sentMessage);
- assertTrue(service.latch.await(10, TimeUnit.SECONDS));
- Message> message = good.receive(1000);
+ Message> message = good.receive(10000);
assertNotNull(message);
assertEquals("hello processed ok from queueChannel2", message.getPayload());
assertNotNull(message.getHeaders().get("foo"));
assertEquals("bar", message.getHeaders().get("foo"));
- }
+ }
public static class Service {
- private CountDownLatch latch;
public void handle(String foo) {
- latch.countDown();
if (foo.startsWith("fail")) {
throw new RuntimeException("planned failure");
}
}
+
}
}