Fix ContentEnricherTests for dangling threads

https://build.spring.io/browse/INT-MJATS41-1353/

**Cherry-pick to 5.0.x and 4.3.x**
This commit is contained in:
Artem Bilan
2018-05-15 09:52:43 -04:00
parent 4be60552d0
commit 5e7391936e

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 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.
@@ -32,7 +32,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
@@ -69,14 +68,6 @@ import org.springframework.scheduling.support.PeriodicTrigger;
*/
public class ContentEnricherTests {
private final ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
@Before
public void init() throws Exception {
taskScheduler.setPoolSize(2);
taskScheduler.afterPropertiesSet();
}
/**
* In this test a {@link Target} message is passed into a {@link ContentEnricher}.
* The Enricher passes the message to a "request-channel" that is backed by a
@@ -142,6 +133,11 @@ public class ContentEnricherTests {
consumer.setTrigger(new PeriodicTrigger(0));
consumer.setErrorHandler(errorHandler);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(2);
taskScheduler.afterPropertiesSet();
consumer.setTaskScheduler(taskScheduler);
consumer.setBeanFactory(mock(BeanFactory.class));
consumer.afterPropertiesSet();
@@ -158,6 +154,10 @@ public class ContentEnricherTests {
e.getMessage());
return;
}
finally {
consumer.stop();
taskScheduler.destroy();
}
fail("ReplyRequiredException expected.");
@@ -474,6 +474,8 @@ public class ContentEnricherTests {
assertFalse(enricher.isRunning());
enricher.start();
assertTrue(enricher.isRunning());
enricher.stop();
}
/**