INT-3099 Add IMAP Idle Application Events
Allow an application to be informed of problems on the IMAP idle thread by emitting an event containing the exception. Introduce IntegrationApplicationEvent hierarchy for all events emitted by SI components. INT-3099 Polishing (PR Comments) Separate TCP events into discrete subclasses.
This commit is contained in:
@@ -36,6 +36,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import javax.mail.Flags;
|
||||
import javax.mail.Flags.Flag;
|
||||
@@ -53,8 +54,11 @@ import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.expression.Expression;
|
||||
@@ -64,6 +68,7 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.integration.mail.ImapIdleChannelAdapter.ImapIdleExceptionEvent;
|
||||
import org.springframework.integration.mail.config.ImapIdleChannelAdapterParserTests;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
@@ -612,6 +617,29 @@ public class ImapMailReceiverTests {
|
||||
adapter.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnectionException() throws Exception {
|
||||
ImapMailReceiver mailReceiver = new ImapMailReceiver("imap:foo");
|
||||
ImapIdleChannelAdapter adapter = new ImapIdleChannelAdapter(mailReceiver);
|
||||
final AtomicReference<ImapIdleExceptionEvent> theEvent = new AtomicReference<ImapIdleExceptionEvent>();
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
adapter.setApplicationEventPublisher(new ApplicationEventPublisher() {
|
||||
|
||||
@Override
|
||||
public void publishEvent(ApplicationEvent event) {
|
||||
assertNull("only one event expected", theEvent.get());
|
||||
theEvent.set((ImapIdleExceptionEvent) event);
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||
taskScheduler.initialize();
|
||||
adapter.setTaskScheduler(taskScheduler);
|
||||
adapter.start();
|
||||
assertTrue(latch.await(10, TimeUnit.SECONDS));
|
||||
assertTrue(theEvent.get().toString().endsWith("cause=java.lang.IllegalStateException: Failure in 'idle' task. Will resubmit.]"));
|
||||
}
|
||||
|
||||
@Test // see INT-1801
|
||||
public void testImapLifecycleForRaceCondition() throws Exception{
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.integration.mail.config;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -44,13 +45,13 @@ import org.springframework.util.ReflectionUtils;
|
||||
public class ImapIdelIntegrationTests {
|
||||
|
||||
@Test
|
||||
//@Ignore
|
||||
public void testWithTransactionSynchronization() throws Exception{
|
||||
final AtomicBoolean block = new AtomicBoolean(false);
|
||||
ClassPathXmlApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("imap-idle-mock-integration-config.xml", this.getClass());
|
||||
PostTransactionProcessor processor = context.getBean("syncProcessor", PostTransactionProcessor.class);
|
||||
ImapIdleChannelAdapter adapter = context.getBean("customAdapter", ImapIdleChannelAdapter.class);
|
||||
assertNotNull(TestUtils.getPropertyValue(adapter, "applicationEventPublisher"));
|
||||
ImapMailReceiver receiver = TestUtils.getPropertyValue(adapter, "mailReceiver", ImapMailReceiver.class);
|
||||
|
||||
// setup mock scenario
|
||||
|
||||
Reference in New Issue
Block a user