Permalink
Browse files

Added delayer example based on http://stackoverflow.com/questions/136…

  • Loading branch information...
1 parent 6ca1fa6 commit c274a12f057b6750dcf18663486a99970368e68e @iwein committed May 8, 2010
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
+ xmlns="http://www.springframework.org/schema/integration"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/integration
+ http://www.springframework.org/schema/integration/spring-integration.xsd">
+
+ <channel id="in"/>
+
+ <filter
+ input-channel="in"
+ ref="retryFilter"
+ method="doRetry"
+ output-channel="delayChannel"/>
+
+ <channel id="delayChannel"/>
+
+ <delayer input-channel="delayChannel" default-delay="10000" output-channel="out"/>
+
+ <channel id="out">
+ <queue capacity="100"/>
+ </channel>
+
+ <poller id="poller" default="true">
+ <interval-trigger interval="1000"/>
+ </poller>
+
+ <beans:bean id="retryFilter" class="iwein.samples.spring.integration.DelayerTest$RetryFilter"/>
+</beans:beans>
@@ -0,0 +1,48 @@
+package iwein.samples.spring.integration;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.channel.PollableChannel;
+import org.springframework.integration.core.Message;
+import org.springframework.integration.core.MessageChannel;
+import org.springframework.integration.message.MessageBuilder;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Iwein Fuld
+ */
+@ContextConfiguration(locations = "/delayer.xml")
+@RunWith(SpringJUnit4ClassRunner.class)
+public class DelayerTest {
+ @Autowired
+ private MessageChannel in;
+
+ @Autowired
+ private PollableChannel out;
+
+ @Test
+ public void shouldLoadContext() {
+ //no errors here proves that the context can be loaded by Spring
+ }
+
+ @Test
+ public void shouldSendMessageThroughDelayer() {
+ Message<?> testMessage = MessageBuilder.withPayload("test").build();
+ in.send(testMessage);
+ assertThat(out.receive(10), is(nullValue()));
+ assertThat(out.receive(), is(notNullValue()));
+ }
+
+ public static class RetryFilter {
+ public boolean doRetry(Message m){
+ return true;
+ }
+ }
+}

0 comments on commit c274a12

Please sign in to comment.