INT-2820 Shutdown Default Idle Executor

The default executor for sending messages from the IMAP IDLE
channel adapter is a single threaded thread pool.

If the default executor is used (no executor injected), shut
it down when the adapter is stopped.

INT-2820 Polishing

If using the default sendingTaskExecutor, create a new one
when restarted.

Add test to restart adapter after stop.

INT-2820 Polishing

Review comments; protect for null sendingTaskExecutor.
This commit is contained in:
Gary Russell
2012-11-19 19:50:03 -05:00
committed by Mark Fisher
parent 2461b3548d
commit cb87246d47
2 changed files with 42 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.mail;
import static org.junit.Assert.assertEquals;
@@ -33,6 +34,7 @@ import java.lang.reflect.Field;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -63,6 +65,7 @@ import org.springframework.integration.handler.AbstractReplyProducingMessageHand
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.mail.config.ImapIdleChannelAdapterParserTests;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.util.FileCopyUtils;
import com.sun.mail.imap.IMAPFolder;
@@ -71,7 +74,6 @@ import com.sun.mail.imap.IMAPMessage;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
*
*/
public class ImapMailReceiverTests {
@@ -663,4 +665,21 @@ public class ImapMailReceiverTests {
assertSame(folder, messages[0].getFolder());
}
@Test
public void testExecShutdown() {
ImapIdleChannelAdapter adapter = new ImapIdleChannelAdapter(new ImapMailReceiver());
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.initialize();
adapter.setTaskScheduler(taskScheduler);
adapter.start();
ExecutorService exec = TestUtils.getPropertyValue(adapter, "sendingTaskExecutor", ExecutorService.class);
adapter.stop();
assertTrue(exec.isShutdown());
adapter.start();
exec = TestUtils.getPropertyValue(adapter, "sendingTaskExecutor", ExecutorService.class);
adapter.stop();
assertTrue(exec.isShutdown());
}
}