INT-1708, INT-1709 added error-channel to the poller

This commit is contained in:
Oleg Zhurakousky
2011-01-20 09:09:41 -05:00
parent 21b5809057
commit a1d205e7a1
6 changed files with 73 additions and 12 deletions

View File

@@ -9,22 +9,30 @@
<int:inbound-channel-adapter id="withErrorHeader" expression="5/0" channel="serviceChannel" auto-startup="false">
<int:poller fixed-rate="1000"/>
<int:header name="errorChannel" value="eChannel"/>
<int:header name="eChannel" value="eChannel"/>
</int:inbound-channel-adapter>
<int:inbound-channel-adapter id="withErrorChannel" expression="5/0"
channel="serviceChannel" auto-startup="false" error-channel="eChannel">
<int:poller fixed-rate="1000"/>
channel="serviceChannel" auto-startup="false">
<int:poller fixed-rate="1000" error-channel="eChannel"/>
</int:inbound-channel-adapter>
<int:inbound-channel-adapter id="withErrorChannelAndHeader" expression="5/0"
channel="serviceChannel" auto-startup="false" error-channel="eChannel">
<int:poller fixed-rate="1000"/>
channel="serviceChannel" auto-startup="false">
<int:poller fixed-rate="1000" error-channel="eChannel"/>
<int:header name="errorChannel" value="errChannel"/>
</int:inbound-channel-adapter>
<int:inbound-channel-adapter id="withErrorChannelAndHeaderErrorOnSend" expression="5"
channel="serviceChannel" auto-startup="false">
<int:poller fixed-rate="1000" error-channel="eChannel"/>
<int:header name="errorChannel" value="errChannel"/>
</int:inbound-channel-adapter>
<int:channel id="serviceChannel"/>
<int:service-activator input-channel="serviceChannel" expression="payload/0"/>
<int:channel id="eChannel">
<int:queue/>
</int:channel>

View File

@@ -16,34 +16,49 @@
package org.springframework.integration.config.xml;
import static junit.framework.Assert.assertNotNull;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.core.SubscribableChannel;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
/**
* @author Oleg Zhurakousky
*
*/
public class PollerWithErrorChannel {
public class PollerWithErrorChannelTests {
@Test
@Ignore
/*
* Although adapter configuration specifies header-enricher pointing to the 'eChannel' as errorChannel
* the ErrorMessage will still be forwarded to the 'errorChannel' since exception occurs on
* receive() and not on send()
*/
public void testWithErrorChannelAsHeader() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorHeader", SourcePollingChannelAdapter.class);
SubscribableChannel errorChannel = ac.getBean("errorChannel", SubscribableChannel.class);
MessageHandler handler = mock(MessageHandler.class);
errorChannel.subscribe(handler);
adapter.start();
PollableChannel errorChannel = ac.getBean("eChannel", PollableChannel.class);
assertNotNull(errorChannel.receive(1000));
Thread.sleep(1000);
verify(handler, atLeastOnce()).handleMessage(Mockito.any(Message.class));
adapter.stop();
}
@Test
@Ignore
public void testWithErrorChannel() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannel", SourcePollingChannelAdapter.class);
@@ -54,11 +69,21 @@ public class PollerWithErrorChannel {
}
@Test
@Ignore
public void testWithErrorChannelAndHeader() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeader", SourcePollingChannelAdapter.class);
adapter.start();
PollableChannel errorChannel = ac.getBean("eChannel", PollableChannel.class);
assertNotNull(errorChannel.receive(1000));
adapter.stop();
}
@Test
// config the same as above but the error wil come from the send
public void testWithErrorChannelAndHeaderWithSendFailure() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorChannelAndHeaderErrorOnSend", SourcePollingChannelAdapter.class);
adapter.start();
PollableChannel errorChannel = ac.getBean("errChannel", PollableChannel.class);
assertNotNull(errorChannel.receive(1000));
adapter.stop();