From 0000aa2cfe74c21169c59284f02cb4e433dbc0a8 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Mon, 28 Jun 2010 18:37:16 +0000 Subject: [PATCH] INT-1221, Added test for pollable channel with executor --- .../config/spring-integration-event-2.0.xsd | 2 +- ...ventOutboundChannelAdapterParserTests.java | 34 +++++++++++++++++++ ...AdapterParserTestsWithPollable-context.xml | 24 +++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTestsWithPollable-context.xml diff --git a/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.0.xsd b/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.0.xsd index 1157418ce8..95204a8f5f 100644 --- a/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.0.xsd +++ b/spring-integration-event/src/main/resources/org/springframework/integration/event/config/spring-integration-event-2.0.xsd @@ -70,7 +70,7 @@ - + diff --git a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTests.java b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTests.java index 01442bfad1..0ebad6d578 100644 --- a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTests.java +++ b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTests.java @@ -15,6 +15,10 @@ */ package org.springframework.integration.event.config; +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.ExecutorService; + import junit.framework.Assert; import org.junit.Test; @@ -24,10 +28,13 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.core.Message; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.event.ApplicationEventPublishingMessageHandler; @@ -77,4 +84,31 @@ public class EventOutboundChannelAdapterParserTests { Assert.assertTrue(recievedEvent); } + @Test(timeout=2000) + public void validateUsageWithPollableChannel() throws Exception { + ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("EventOutboundChannelAdapterParserTestsWithPollable-context.xml", EventOutboundChannelAdapterParserTests.class); + final CyclicBarrier barier = new CyclicBarrier(2); + ApplicationListener listener = new ApplicationListener() { + public void onApplicationEvent(ApplicationEvent event) { + Object source = event.getSource(); + if (source instanceof Message){ + String payload = (String) ((Message)source).getPayload(); + if (payload.equals("hello")){ + recievedEvent = true; + try { + barier.await(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + }; + ac.addApplicationListener(listener); + QueueChannel channel = ac.getBean("input", QueueChannel.class); + channel.send(new StringMessage("hello")); + barier.await(); + Assert.assertTrue(recievedEvent); + } + } diff --git a/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTestsWithPollable-context.xml b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTestsWithPollable-context.xml new file mode 100644 index 0000000000..c8321ad960 --- /dev/null +++ b/spring-integration-event/src/test/java/org/springframework/integration/event/config/EventOutboundChannelAdapterParserTestsWithPollable-context.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + +