Skip to content

Commit 07b20c1

Browse files
committed
Fix ContentEnricherTests for dangling threads
https://build.spring.io/browse/INT-MJATS41-1353/ **Cherry-pick to 5.0.x and 4.3.x** (cherry picked from commit 5e73919)
1 parent f912aad commit 07b20c1

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

spring-integration-core/src/test/java/org/springframework/integration/transformer/ContentEnricherTests.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@
3030
import java.util.HashMap;
3131
import java.util.Map;
3232

33-
import org.junit.Before;
3433
import org.junit.Test;
3534

3635
import org.springframework.beans.factory.BeanFactory;
@@ -64,14 +63,6 @@
6463
*/
6564
public class ContentEnricherTests {
6665

67-
private final ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
68-
69-
@Before
70-
public void init() throws Exception {
71-
taskScheduler.setPoolSize(2);
72-
taskScheduler.afterPropertiesSet();
73-
}
74-
7566
/**
7667
* In this test a {@link Target} message is passed into a {@link ContentEnricher}.
7768
* The Enricher passes the message to a "request-channel" that is backed by a
@@ -137,6 +128,11 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
137128

138129
consumer.setTrigger(new PeriodicTrigger(0));
139130
consumer.setErrorHandler(errorHandler);
131+
132+
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
133+
taskScheduler.setPoolSize(2);
134+
taskScheduler.afterPropertiesSet();
135+
140136
consumer.setTaskScheduler(taskScheduler);
141137
consumer.setBeanFactory(mock(BeanFactory.class));
142138
consumer.afterPropertiesSet();
@@ -153,6 +149,10 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
153149
e.getMessage());
154150
return;
155151
}
152+
finally {
153+
consumer.stop();
154+
taskScheduler.destroy();
155+
}
156156

157157
fail("ReplyRequiredException expected.");
158158

@@ -469,6 +469,8 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
469469
assertFalse(enricher.isRunning());
470470
enricher.start();
471471
assertTrue(enricher.isRunning());
472+
473+
enricher.stop();
472474
}
473475

474476
/**

0 commit comments

Comments
 (0)