Skip to content

Commit

Permalink
Fix ContentEnricherTests for dangling threads
Browse files Browse the repository at this point in the history
https://build.spring.io/browse/INT-MJATS41-1353/

**Cherry-pick to 5.0.x and 4.3.x**

(cherry picked from commit 5e73919)
  • Loading branch information
artembilan committed May 15, 2018
1 parent ac23d8c commit eced157
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -32,7 +32,6 @@
import java.util.HashMap;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;

import org.springframework.beans.factory.BeanFactory;
Expand Down Expand Up @@ -69,14 +68,6 @@
*/
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
Expand Down Expand Up @@ -142,6 +133,11 @@ protected Object handleRequestMessage(Message<?> requestMessage) {

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();
Expand All @@ -158,6 +154,10 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
e.getMessage());
return;
}
finally {
consumer.stop();
taskScheduler.destroy();
}

fail("ReplyRequiredException expected.");

Expand Down Expand Up @@ -474,6 +474,8 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
assertFalse(enricher.isRunning());
enricher.start();
assertTrue(enricher.isRunning());

enricher.stop();
}

/**
Expand Down

0 comments on commit eced157

Please sign in to comment.