The <aggregator/> element now creates a HandlerEndpoint instance. It now requires "input-channel" and "output-channel" (and it no longer accepts "default-reply-channel"). It also no longer accepts a <completion-strategy/> sub-element. Instead, for a pojo-based adapter, add the "completion-strategy-method" attribute along with the "completion-strategy" reference (INT-285).
This commit is contained in:
@@ -26,10 +26,10 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.endpoint.HandlerEndpoint;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.router.AggregatingMessageHandler;
|
||||
@@ -39,6 +39,7 @@ import org.springframework.integration.util.MethodInvoker;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class AggregatorParserTests {
|
||||
|
||||
@@ -52,8 +53,8 @@ public class AggregatorParserTests {
|
||||
|
||||
@Test
|
||||
public void testAggregation() {
|
||||
AggregatingMessageHandler aggregatingHandler = (AggregatingMessageHandler) context
|
||||
.getBean("aggregatorWithReference");
|
||||
HandlerEndpoint endpoint = (HandlerEndpoint) context.getBean("aggregatorWithReference");
|
||||
AggregatingMessageHandler aggregatingHandler = (AggregatingMessageHandler) endpoint.getHandler();
|
||||
TestAggregator aggregatorBean = (TestAggregator) context.getBean("aggregatorBean");
|
||||
List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
|
||||
outboundMessages.add(createMessage("123", "id1", 3, 1, null));
|
||||
@@ -71,8 +72,9 @@ public class AggregatorParserTests {
|
||||
|
||||
@Test
|
||||
public void testPropertyAssignment() throws Exception {
|
||||
AggregatingMessageHandler completeAggregatingMessageHandler = (AggregatingMessageHandler) context
|
||||
.getBean("completelyDefinedAggregator");
|
||||
HandlerEndpoint endpoint = (HandlerEndpoint) context.getBean("completelyDefinedAggregator");
|
||||
AggregatingMessageHandler completeAggregatingMessageHandler =
|
||||
(AggregatingMessageHandler) endpoint.getHandler();
|
||||
TestAggregator testAggregator = (TestAggregator) context.getBean("aggregatorBean");
|
||||
CompletionStrategy completionStrategy = (CompletionStrategy) context.getBean("completionStrategy");
|
||||
MessageChannel defaultReplyChannel = (MessageChannel) context.getBean("replyChannel");
|
||||
@@ -103,8 +105,9 @@ public class AggregatorParserTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleJavaBeanAggregator() {
|
||||
AggregatingMessageHandler addingAggregator = (AggregatingMessageHandler) context.getBean("aggregatorWithReferenceAndMethod");
|
||||
List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
|
||||
HandlerEndpoint endpoint = (HandlerEndpoint) context.getBean("aggregatorWithReferenceAndMethod");
|
||||
AggregatingMessageHandler addingAggregator = (AggregatingMessageHandler) endpoint.getHandler();
|
||||
outboundMessages.add(createMessage(1l, "id1", 3, 1, null));
|
||||
outboundMessages.add(createMessage(2l, "id1", 3, 3, null));
|
||||
outboundMessages.add(createMessage(3l, "id1", 3, 2, null));
|
||||
@@ -121,21 +124,23 @@ public class AggregatorParserTests {
|
||||
context = new ClassPathXmlApplicationContext("invalidMethodNameAggregator.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionParsingException.class)
|
||||
@Test(expected=BeanCreationException.class)
|
||||
public void testDuplicateCompletionStrategyDefinition() {
|
||||
context = new ClassPathXmlApplicationContext("completionStrategyMethodWithMissingReference.xml", this.getClass());
|
||||
context = new ClassPathXmlApplicationContext(
|
||||
"completionStrategyMethodWithMissingReference.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggregatorWithPojoCompletionStrategy(){
|
||||
AggregatingMessageHandler aggregatorWithPojoCompletionStrategy = (AggregatingMessageHandler) context.getBean("aggregatorWithPojoCompletionStrategy");
|
||||
CompletionStrategy completionStrategy = (CompletionStrategy)new DirectFieldAccessor(aggregatorWithPojoCompletionStrategy).getPropertyValue("completionStrategy");
|
||||
HandlerEndpoint endpoint = (HandlerEndpoint) context.getBean("aggregatorWithPojoCompletionStrategy");
|
||||
AggregatingMessageHandler aggregatorWithPojoCompletionStrategy = (AggregatingMessageHandler) endpoint.getHandler();
|
||||
CompletionStrategy completionStrategy = (CompletionStrategy)
|
||||
new DirectFieldAccessor(aggregatorWithPojoCompletionStrategy).getPropertyValue("completionStrategy");
|
||||
Assert.assertTrue(completionStrategy instanceof CompletionStrategyAdapter);
|
||||
DirectFieldAccessor completionStrategyAccessor = new DirectFieldAccessor(completionStrategy);
|
||||
MethodInvoker invoker = (MethodInvoker) completionStrategyAccessor.getPropertyValue("invoker");
|
||||
Assert.assertTrue(new DirectFieldAccessor(invoker).getPropertyValue("object") instanceof MaxValueCompletionStrategy);
|
||||
Assert.assertTrue(((Method)completionStrategyAccessor.getPropertyValue("method")).getName().equals("checkCompleteness"));
|
||||
|
||||
aggregatorWithPojoCompletionStrategy.handle(createMessage(1l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.handle(createMessage(2l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.handle(createMessage(3l, "id1", 0 , 0, null));
|
||||
@@ -148,9 +153,9 @@ public class AggregatorParserTests {
|
||||
Assert.assertEquals(11l, reply.getPayload());
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionParsingException.class)
|
||||
public void testAggregatorWithDuplicateCompletionStrategy() {
|
||||
context = new ClassPathXmlApplicationContext("duplicateCompletionStrategy.xml", this.getClass());
|
||||
@Test(expected=BeanCreationException.class)
|
||||
public void testAggregatorWithInvalidCompletionStrategyMethod() {
|
||||
context = new ClassPathXmlApplicationContext("invalidCompletionStrategyMethod.xml", this.getClass());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,27 +9,37 @@
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<aggregator id="aggregatorWithReference" ref="aggregatorBean" />
|
||||
<channel id="inputChannel"/>
|
||||
<channel id="replyChannel"/>
|
||||
<channel id="discardChannel"/>
|
||||
|
||||
<aggregator id="completelyDefinedAggregator" ref="aggregatorBean"
|
||||
<aggregator id="aggregatorWithReference" ref="aggregatorBean" input-channel="inputChannel"/>
|
||||
|
||||
<aggregator id="completelyDefinedAggregator"
|
||||
input-channel="inputChannel"
|
||||
output-channel="replyChannel"
|
||||
discard-channel="discardChannel"
|
||||
ref="aggregatorBean"
|
||||
completion-strategy="completionStrategy"
|
||||
default-reply-channel="replyChannel" discard-channel="discardChannel"
|
||||
send-timeout="86420000" send-partial-result-on-timeout="true"
|
||||
reaper-interval="135" tracked-correlation-id-capacity="99"
|
||||
timeout="42" />
|
||||
send-timeout="86420000"
|
||||
send-partial-result-on-timeout="true"
|
||||
reaper-interval="135"
|
||||
tracked-correlation-id-capacity="99"
|
||||
timeout="42"/>
|
||||
|
||||
<aggregator id="aggregatorWithReferenceAndMethod" ref="adderBean"
|
||||
method="add" default-reply-channel="replyChannel" />
|
||||
<aggregator id="aggregatorWithReferenceAndMethod"
|
||||
ref="adderBean"
|
||||
method="add"
|
||||
input-channel="inputChannel"
|
||||
output-channel="replyChannel"/>
|
||||
|
||||
<aggregator id="aggregatorWithPojoCompletionStrategy"
|
||||
ref="adderBean" method="add" default-reply-channel="replyChannel">
|
||||
<completion-strategy ref="pojoCompletionStrategy"
|
||||
method="checkCompleteness" />
|
||||
</aggregator>
|
||||
|
||||
<channel id="replyChannel" />
|
||||
|
||||
<channel id="discardChannel" />
|
||||
input-channel="inputChannel"
|
||||
output-channel="replyChannel"
|
||||
ref="adderBean"
|
||||
method="add"
|
||||
completion-strategy="pojoCompletionStrategy"
|
||||
completion-strategy-method="checkCompleteness"/>
|
||||
|
||||
<beans:bean id="aggregatorBean"
|
||||
class="org.springframework.integration.config.TestAggregator" />
|
||||
|
||||
@@ -9,14 +9,15 @@
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<aggregator id="aggregator" ref="adderBean" method="add" completion-strategy="testCompletionStrategy" default-reply-channel="replyChannel">
|
||||
<completion-strategy ref="testCompletionStrategy"/>
|
||||
<aggregator id="aggregator" ref="adderBean" method="add" completion-strategy="testCompletionStrategy"
|
||||
input-channel="input-channel" output-channel="replyChannel">
|
||||
</aggregator>
|
||||
|
||||
<channel id="inputChannel"/>
|
||||
<channel id="replyChannel"/>
|
||||
|
||||
<beans:bean id="adderBean" class="org.springframework.integration.config.Adder"/>
|
||||
|
||||
<beans:bean id="completionStrategyBean" class="org.springframework.integration.config.TestCompletionStrategy"></beans:bean>
|
||||
<beans:bean id="completionStrategyBean" class="org.springframework.integration.config.TestCompletionStrategy"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
<aggregator id="aggregatorWithPojoCompletionStrategy" completion-strategy="completionStrategy"
|
||||
ref="adderBean" method="add" default-reply-channel="replyChannel">
|
||||
<completion-strategy ref="pojoCompletionStrategy"
|
||||
method="checkCompleteness" />
|
||||
</aggregator>
|
||||
<aggregator id="aggregatorWithPojoCompletionStrategy"
|
||||
completion-strategy="completionStrategy"
|
||||
ref="adderBean" method="add"
|
||||
input-channel="inputChannel"
|
||||
output-channel="replyChannel"
|
||||
completion-strategy-method="invalidMethodName"/>
|
||||
|
||||
<channel id="replyChannel" />
|
||||
<channel id="inputChannel"/>
|
||||
<channel id="replyChannel"/>
|
||||
|
||||
<beans:bean id="adderBean"
|
||||
class="org.springframework.integration.config.Adder" />
|
||||
@@ -8,11 +8,13 @@
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<aggregator id="aggregatorWithReferenceAndMethod" ref="adderBean" method="substract" default-reply-channel="replyChannel"/>
|
||||
|
||||
<channel id="inputChannel"/>
|
||||
<channel id="replyChannel"/>
|
||||
|
||||
<aggregator id="aggregatorWithReferenceAndMethod" ref="adderBean" method="substract"
|
||||
input-channel="inputChannel" output-channel="replyChannel"/>
|
||||
|
||||
<beans:bean id="adderBean" class="org.springframework.integration.config.Adder"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.router.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class NumberAdder {
|
||||
|
||||
public Integer sum(List<Integer> values) {
|
||||
int result = 0;
|
||||
for (Integer value : values) {
|
||||
result += value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.router.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class NumberSplitter {
|
||||
|
||||
public List<Integer> split(Numbers numbers) {
|
||||
return numbers.getValues();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.router.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class Numbers {
|
||||
|
||||
private final List<Integer> values;
|
||||
|
||||
|
||||
public Numbers(List<Integer> values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public List<Integer> getValues() {
|
||||
return this.values;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.router.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class SplitterAggregatorTests {
|
||||
|
||||
private final AtomicInteger count = new AtomicInteger();
|
||||
|
||||
|
||||
@Test
|
||||
public void testSplitterAndAggregator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"splitterAggregatorTests.xml", this.getClass());
|
||||
MessageChannel inputChannel = (MessageChannel) context.getBean("numbers");
|
||||
MessageChannel outputChannel = (MessageChannel) context.getBean("results");
|
||||
inputChannel.send(new GenericMessage<Numbers>(this.nextTen()));
|
||||
Message<?> result1 = outputChannel.receive(1000);
|
||||
assertNotNull(result1);
|
||||
assertEquals(Integer.class, result1.getPayload().getClass());
|
||||
assertEquals(55, result1.getPayload());
|
||||
inputChannel.send(new GenericMessage<Numbers>(this.nextTen()));
|
||||
Message<?> result2 = outputChannel.receive(1000);
|
||||
assertNotNull(result2);
|
||||
assertEquals(Integer.class, result2.getPayload().getClass());
|
||||
assertEquals(155, result2.getPayload());
|
||||
}
|
||||
|
||||
private Numbers nextTen() {
|
||||
List<Integer> values = new ArrayList<Integer>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
values.add(this.count.incrementAndGet());
|
||||
}
|
||||
return new Numbers(values);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="numbers"/>
|
||||
<channel id="splits"/>
|
||||
<channel id="results"/>
|
||||
|
||||
<splitter ref="splitter" method="split" input-channel="numbers" output-channel="splits"/>
|
||||
<aggregator ref="aggregator" method="sum" input-channel="splits" output-channel="results"/>
|
||||
|
||||
<beans:bean id="splitter" class="org.springframework.integration.router.config.NumberSplitter"/>
|
||||
<beans:bean id="aggregator" class="org.springframework.integration.router.config.NumberAdder"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user