diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/DelayerHandlerRescheduleIntegrationTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/DelayerHandlerRescheduleIntegrationTests.java index c6955ffb70..d80e49f358 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/DelayerHandlerRescheduleIntegrationTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/DelayerHandlerRescheduleIntegrationTests.java @@ -31,6 +31,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; import org.springframework.integration.MessagingException; +import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.MessageHandler; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.store.MessageGroup; @@ -41,6 +42,7 @@ import org.springframework.integration.util.UUIDConverter; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronizationAdapter; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -79,10 +81,12 @@ public class DelayerHandlerRescheduleIntegrationTests { input.send(MessageBuilder.withPayload("test2").build()); // Emulate restart and check DB state before next start + // Interrupt taskScheduler as quickly as possible + ThreadPoolTaskScheduler taskScheduler = (ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context); + taskScheduler.shutdown(); + taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS); context.destroy(); - Thread.sleep(100); - try { context.getBean("input", MessageChannel.class); fail("IllegalStateException expected"); diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/DelayerHandlerRescheduleIntegrationTests.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/DelayerHandlerRescheduleIntegrationTests.java index 97487fc79f..2fb73b724f 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/DelayerHandlerRescheduleIntegrationTests.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/DelayerHandlerRescheduleIntegrationTests.java @@ -21,13 +21,17 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.Iterator; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; import org.hamcrest.Matchers; -import org.junit.Test; + import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.Message; import org.springframework.integration.MessageChannel; +import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.core.PollableChannel; import org.springframework.integration.handler.DelayHandler; import org.springframework.integration.mongodb.rules.MongoDbAvailable; @@ -35,6 +39,7 @@ import org.springframework.integration.mongodb.rules.MongoDbAvailableTests; import org.springframework.integration.store.MessageGroup; import org.springframework.integration.store.MessageGroupStore; import org.springframework.integration.support.MessageBuilder; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; /** * @author Artem Bilan @@ -62,10 +67,12 @@ public class DelayerHandlerRescheduleIntegrationTests extends MongoDbAvailableTe input.send(MessageBuilder.withPayload("test2").build()); // Emulate restart and check DB state before next start + // Interrupt taskScheduler as quickly as possible + ThreadPoolTaskScheduler taskScheduler = (ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context); + taskScheduler.shutdown(); + taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS); context.destroy(); - Thread.sleep(100); - try { context.getBean("input", MessageChannel.class); fail("IllegalStateException expected");