Skip to content

Commit eced157

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 ac23d8c commit eced157

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.
@@ -32,7 +32,6 @@
3232
import java.util.HashMap;
3333
import java.util.Map;
3434

35-
import org.junit.Before;
3635
import org.junit.Test;
3736

3837
import org.springframework.beans.factory.BeanFactory;
@@ -69,14 +68,6 @@
6968
*/
7069
public class ContentEnricherTests {
7170

72-
private final ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
73-
74-
@Before
75-
public void init() throws Exception {
76-
taskScheduler.setPoolSize(2);
77-
taskScheduler.afterPropertiesSet();
78-
}
79-
8071
/**
8172
* In this test a {@link Target} message is passed into a {@link ContentEnricher}.
8273
* The Enricher passes the message to a "request-channel" that is backed by a
@@ -142,6 +133,11 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
142133

143134
consumer.setTrigger(new PeriodicTrigger(0));
144135
consumer.setErrorHandler(errorHandler);
136+
137+
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
138+
taskScheduler.setPoolSize(2);
139+
taskScheduler.afterPropertiesSet();
140+
145141
consumer.setTaskScheduler(taskScheduler);
146142
consumer.setBeanFactory(mock(BeanFactory.class));
147143
consumer.afterPropertiesSet();
@@ -158,6 +154,10 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
158154
e.getMessage());
159155
return;
160156
}
157+
finally {
158+
consumer.stop();
159+
taskScheduler.destroy();
160+
}
161161

162162
fail("ReplyRequiredException expected.");
163163

@@ -474,6 +474,8 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
474474
assertFalse(enricher.isRunning());
475475
enricher.start();
476476
assertTrue(enricher.isRunning());
477+
478+
enricher.stop();
477479
}
478480

479481
/**

0 commit comments

Comments
 (0)