Search in sources :

Example 1 with ImapIdleExceptionEvent

use of org.springframework.integration.mail.ImapIdleChannelAdapter.ImapIdleExceptionEvent in project spring-integration by spring-projects.

the class ImapMailReceiverTests method testConnectionException.

@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(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.]"));
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) ImapIdleExceptionEvent(org.springframework.integration.mail.ImapIdleChannelAdapter.ImapIdleExceptionEvent) CountDownLatch(java.util.concurrent.CountDownLatch) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Test (org.junit.Test)1 ImapIdleExceptionEvent (org.springframework.integration.mail.ImapIdleChannelAdapter.ImapIdleExceptionEvent)1 LongRunningIntegrationTest (org.springframework.integration.test.support.LongRunningIntegrationTest)1 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)1