INT-2863 Add Release Strategy to Resequencer
- allow the configuration of release strategies on resequencers -- adjust the xsd to allow the definition of a release strategy -- move release strategy parsing to AbstractCorrelatingMessageHandlerParser -- add unit tests For reference see: https://jira.springsource.org/browse/INT-2863 INT-2863 Polishing Fix white space; add @author; update copyright. INT-2863 Resequencer/Aggregator Docs Add docs for correlation and release strategis to Resequencer. Add *.expression docs to Aggregator.
This commit is contained in:
committed by
Gary Russell
parent
3c59d377f4
commit
f9aea7d5f5
@@ -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. You may obtain a copy of the License at
|
||||
@@ -18,18 +18,23 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.integration.test.util.TestUtils.getPropertyValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.aggregator.CorrelationStrategy;
|
||||
import org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy;
|
||||
import org.springframework.integration.aggregator.MethodInvokingReleaseStrategy;
|
||||
import org.springframework.integration.aggregator.ReleaseStrategy;
|
||||
import org.springframework.integration.aggregator.ResequencingMessageHandler;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.integration.store.SimpleMessageGroup;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
|
||||
@@ -38,6 +43,7 @@ import org.springframework.integration.test.util.TestUtils;
|
||||
* @author Mark Fisher
|
||||
* @author Dave Syer
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Stefan Ferstl
|
||||
*/
|
||||
public class ResequencerParserTests {
|
||||
|
||||
@@ -94,6 +100,34 @@ public class ResequencerParserTests {
|
||||
.getBean("testCorrelationStrategy"), getPropertyValue(resequencer, "correlationStrategy"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleaseStrategyRefOnly() throws Exception {
|
||||
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithReleaseStrategyRefOnly");
|
||||
ResequencingMessageHandler resequencer = getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
|
||||
assertEquals("The ResequencerEndpoint is not configured with the appropriate ReleaseStrategy",
|
||||
context.getBean("testReleaseStrategy"), getPropertyValue(resequencer, "releaseStrategy"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleaseStrategyRefAndMethod() throws Exception {
|
||||
EventDrivenConsumer endpoint = (EventDrivenConsumer) context
|
||||
.getBean("resequencerWithReleaseStrategyRefAndMethod");
|
||||
ResequencingMessageHandler resequencer = getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
|
||||
|
||||
Object releaseStrategyBean = context.getBean("testReleaseStrategyPojo");
|
||||
assertTrue("Release strategy is not of the expected type",
|
||||
releaseStrategyBean instanceof TestReleaseStrategyPojo);
|
||||
TestReleaseStrategyPojo expectedReleaseStrategy = (TestReleaseStrategyPojo) releaseStrategyBean;
|
||||
|
||||
int currentInvocationCount = expectedReleaseStrategy.invocationCount;
|
||||
ReleaseStrategy effectiveReleaseStrategy = (ReleaseStrategy) getPropertyValue(resequencer, "releaseStrategy");
|
||||
assertTrue("The release strategy is expected to be a MethodInvokingReleaseStrategy",
|
||||
effectiveReleaseStrategy instanceof MethodInvokingReleaseStrategy);
|
||||
effectiveReleaseStrategy.canRelease(new SimpleMessageGroup("test"));
|
||||
assertEquals("The ResequencerEndpoint was not invoked the expected number of times;",
|
||||
currentInvocationCount + 1, expectedReleaseStrategy.invocationCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetReleasePartialSequencesFlag(){
|
||||
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("completelyDefinedResequencer");
|
||||
@@ -137,4 +171,19 @@ public class ResequencerParserTests {
|
||||
}
|
||||
}
|
||||
|
||||
static class TestReleaseStrategy implements ReleaseStrategy {
|
||||
public boolean canRelease(MessageGroup group) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static class TestReleaseStrategyPojo {
|
||||
private int invocationCount = 0;
|
||||
|
||||
public boolean bar(List<Message<?>> messages) {
|
||||
invocationCount++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,10 +46,24 @@
|
||||
correlation-strategy="testCorrelationStrategyPojo"
|
||||
correlation-strategy-method="foo"/>
|
||||
|
||||
<resequencer id="resequencerWithReleaseStrategyRefOnly"
|
||||
input-channel="inputChannel5"
|
||||
release-strategy="testReleaseStrategy"/>
|
||||
|
||||
<resequencer id="resequencerWithReleaseStrategyRefAndMethod"
|
||||
input-channel="inputChannel6"
|
||||
release-strategy="testReleaseStrategyPojo"
|
||||
release-strategy-method="bar"/>
|
||||
|
||||
<beans:bean id="testCorrelationStrategy"
|
||||
class="org.springframework.integration.config.ResequencerParserTests$TestCorrelationStrategy"/>
|
||||
|
||||
<beans:bean id="testCorrelationStrategyPojo"
|
||||
class="org.springframework.integration.config.ResequencerParserTests$TestCorrelationStrategyPojo"/>
|
||||
|
||||
<beans:bean id="testReleaseStrategy"
|
||||
class="org.springframework.integration.config.ResequencerParserTests$TestReleaseStrategy" />
|
||||
|
||||
<beans:bean id="testReleaseStrategyPojo"
|
||||
class="org.springframework.integration.config.ResequencerParserTests$TestReleaseStrategyPojo" />
|
||||
</beans:beans>
|
||||
|
||||
Reference in New Issue
Block a user