diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests-context.xml
index 1625a4e3f6..a716ff292b 100644
--- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests-context.xml
+++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests-context.xml
@@ -10,26 +10,23 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">
-
+
+
+
-
-
-
-
-
-
+
-
-
+
+
-
+
@@ -44,7 +41,7 @@
-
+
diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests.java
index ccc8bd59c5..ce89f92c50 100644
--- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests.java
+++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,12 +25,17 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.integration.endpoint.AbstractEndpoint;
+import org.springframework.integration.store.MessageGroup;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
-import org.springframework.integration.store.MessageGroup;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
@@ -38,6 +43,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.BeforeTransaction;
import org.springframework.transaction.annotation.Transactional;
+/**
+ * @author Dave Syer
+ * @author Mark Fisher
+ * @author Oleg Zhurakousky
+ * @author Gary Russell
+ * @author Artem Bilan
+ */
+
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
@@ -85,9 +98,8 @@ public class JdbcMessageStoreChannelTests {
@Test
public void testSendAndActivateWithRollback() throws Exception {
- Service.reset(1);
Service.fail = true;
- input.send(new GenericMessage("foo"));
+ input.send(new GenericMessage<>("foo"));
Service.await(10000);
assertEquals(1, Service.messages.size());
// After a rollback in the poller the message is still waiting to be delivered
@@ -95,13 +107,12 @@ public class JdbcMessageStoreChannelTests {
}
@Test
- @Transactional
+ @Transactional(timeout = 1)
public void testSendAndActivateTransactionalSend() throws Exception {
- Service.reset(1);
- input.send(new GenericMessage("foo"));
+ input.send(new GenericMessage<>("foo"));
// This will time out because the transaction has not committed yet
try {
- Service.await(10000);
+ Service.await(10);
fail("Expected timeout");
}
catch (IllegalStateException e) {
@@ -114,21 +125,28 @@ public class JdbcMessageStoreChannelTests {
}
public static class Service {
+
private static boolean fail = false;
+
private static boolean alreadyFailed = false;
- private static List messages = new CopyOnWriteArrayList();
+
+ private static List messages = new CopyOnWriteArrayList<>();
+
private static CountDownLatch latch = new CountDownLatch(0);
+
public static void reset(int count) {
fail = false;
alreadyFailed = false;
messages.clear();
latch = new CountDownLatch(count);
}
+
public static void await(long timeout) throws InterruptedException {
if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
throw new IllegalStateException("Timed out waiting for message");
}
}
+
public String echo(String input) {
if (!alreadyFailed) {
messages.add(input);
@@ -140,6 +158,7 @@ public class JdbcMessageStoreChannelTests {
}
return input;
}
+
}
}