INT-330: switched namespace support for aggregator
This commit is contained in:
@@ -38,6 +38,7 @@ public class CorrelatingMessageHandlerIntegrationTest {
|
||||
|
||||
@Before public void setupHandler(){
|
||||
defaultHandler.setOutputChannel(outputChannel);
|
||||
defaultHandler.setSendTimeout(-1);
|
||||
}
|
||||
|
||||
private Message<?> correlatedMessage(Object correlationId,
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
@@ -76,14 +77,14 @@ public class CorrelatingMessageHandlerTests {
|
||||
return null;
|
||||
}
|
||||
}).when(processor).processAndSend(isA(MessageGroup.class),
|
||||
eq(outputChannel));
|
||||
isA(MessageChannelTemplate.class), eq(outputChannel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bufferCompletesNormally() throws Exception {
|
||||
String correlationKey = "key";
|
||||
Message<?> message1 = testMessage(1, 1);
|
||||
Message<?> message2 = testMessage(2, 2);
|
||||
Message<?> message1 = testMessage(correlationKey, 1, 1);
|
||||
Message<?> message2 = testMessage(correlationKey, 2, 2);
|
||||
List<Message<?>> storedMessages = new ArrayList<Message<?>>();
|
||||
|
||||
when(store.list(correlationKey)).thenReturn(storedMessages);
|
||||
@@ -108,7 +109,7 @@ public class CorrelatingMessageHandlerTests {
|
||||
verify(completionStrategy).isComplete(Arrays.asList(message1));
|
||||
verify(completionStrategy).isComplete(Arrays.asList(message1, message2));
|
||||
verify(processor).processAndSend(isA(MessageGroup.class),
|
||||
eq(outputChannel)
|
||||
isA(MessageChannelTemplate.class), eq(outputChannel)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -120,8 +121,8 @@ public class CorrelatingMessageHandlerTests {
|
||||
@Test
|
||||
public void shouldNotPruneWhileCompleting() throws Exception {
|
||||
String correlationKey = "key";
|
||||
final Message<?> message1 = testMessage(1, 1);
|
||||
final Message<?> message2 = testMessage(2, 2);
|
||||
final Message<?> message1 = testMessage(correlationKey, 1, 1);
|
||||
final Message<?> message2 = testMessage(correlationKey, 2, 2);
|
||||
final List<Message<?>> storedMessages = new ArrayList<Message<?>>();
|
||||
|
||||
final CountDownLatch bothMessagesHandled = new CountDownLatch(2);
|
||||
@@ -159,9 +160,10 @@ public class CorrelatingMessageHandlerTests {
|
||||
verify(store).delete(2);
|
||||
}
|
||||
|
||||
private Message<?> testMessage(int id, int sequenceNumber) {
|
||||
private Message<?> testMessage(String correllationKey, int id, int sequenceNumber) {
|
||||
return MessageBuilder.withPayload("test" + id)
|
||||
.setHeader(MessageHeaders.ID, id)
|
||||
.setCorrelationId(correllationKey)
|
||||
.setSequenceNumber(sequenceNumber).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.integration.annotation.Aggregator;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
@@ -18,6 +19,7 @@ import java.util.List;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -36,6 +38,9 @@ public class MethodInvokingMessageGroupProcessorTests {
|
||||
@Mock
|
||||
private MessageGroup messageGroupMock;
|
||||
|
||||
@Mock
|
||||
private MessageChannelTemplate channelTemplate;
|
||||
|
||||
@Before
|
||||
public void initializeMessagesUpForProcessing() {
|
||||
messagesUpForProcessing.add(MessageBuilder.withPayload(1).build());
|
||||
@@ -68,10 +73,9 @@ public class MethodInvokingMessageGroupProcessorTests {
|
||||
.forClass(Message.class);
|
||||
when(outputChannel.send(isA(Message.class))).thenReturn(true);
|
||||
when(messageGroupMock.getMessages()).thenReturn(messagesUpForProcessing);
|
||||
processor.processAndSend(messageGroupMock, outputChannel
|
||||
);
|
||||
processor.processAndSend(messageGroupMock, channelTemplate, outputChannel);
|
||||
// verify
|
||||
verify(outputChannel).send(messageCaptor.capture());
|
||||
verify(channelTemplate).send(messageCaptor.capture(), eq(outputChannel));
|
||||
assertThat((Integer) messageCaptor.getValue().getPayload(), is(7));
|
||||
}
|
||||
|
||||
@@ -94,10 +98,9 @@ public class MethodInvokingMessageGroupProcessorTests {
|
||||
.forClass(Message.class);
|
||||
when(outputChannel.send(isA(Message.class))).thenReturn(true);
|
||||
when(messageGroupMock.getMessages()).thenReturn(messagesUpForProcessing);
|
||||
processor.processAndSend(messageGroupMock, outputChannel
|
||||
);
|
||||
processor.processAndSend(messageGroupMock, channelTemplate, outputChannel);
|
||||
// verify
|
||||
verify(outputChannel).send(messageCaptor.capture());
|
||||
verify(channelTemplate).send(messageCaptor.capture(), eq(outputChannel));
|
||||
assertThat((Integer) messageCaptor.getValue().getPayload(), is(7));
|
||||
}
|
||||
|
||||
@@ -132,10 +135,10 @@ public class MethodInvokingMessageGroupProcessorTests {
|
||||
|
||||
when(outputChannel.send(isA(Message.class))).thenReturn(true);
|
||||
when(messageGroupMock.getMessages()).thenReturn(messagesUpForProcessing);
|
||||
processor.processAndSend(messageGroupMock, outputChannel
|
||||
processor.processAndSend(messageGroupMock, channelTemplate, outputChannel
|
||||
);
|
||||
// verify
|
||||
verify(outputChannel).send(messageCaptor.capture());
|
||||
verify(channelTemplate).send(messageCaptor.capture(), eq(outputChannel));
|
||||
assertThat((Integer) messageCaptor.getValue().getPayload(), is(7));
|
||||
}
|
||||
|
||||
@@ -165,10 +168,10 @@ public class MethodInvokingMessageGroupProcessorTests {
|
||||
|
||||
when(outputChannel.send(isA(Message.class))).thenReturn(true);
|
||||
when(messageGroupMock.getMessages()).thenReturn(messagesUpForProcessing);
|
||||
processor.processAndSend(messageGroupMock, outputChannel
|
||||
processor.processAndSend(messageGroupMock, channelTemplate, outputChannel
|
||||
);
|
||||
// verify
|
||||
verify(outputChannel).send(messageCaptor.capture());
|
||||
verify(channelTemplate).send(messageCaptor.capture(), eq(outputChannel));
|
||||
assertThat((Integer) messageCaptor.getValue().getPayload(), is(7));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.aggregator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
@@ -251,14 +252,14 @@ public class NewAggregatorEndpointTests {
|
||||
|
||||
private class MultiplyingProcessor implements MessageGroupProcessor {
|
||||
public void processAndSend(MessageGroup group,
|
||||
MessageChannel outputChannel
|
||||
MessageChannelTemplate channelTemplate, MessageChannel outputChannel
|
||||
) {
|
||||
Integer product = 1;
|
||||
List<Message<?>> messagesUpForProcessing = group.getMessages();
|
||||
for (Message<?> message : messagesUpForProcessing) {
|
||||
product *= (Integer) message.getPayload();
|
||||
}
|
||||
outputChannel.send(MessageBuilder.withPayload(product).build());
|
||||
channelTemplate.send(MessageBuilder.withPayload(product).build(), outputChannel);
|
||||
|
||||
group.onProcessingOf(
|
||||
messagesUpForProcessing.toArray(new Message[messagesUpForProcessing.size()])
|
||||
@@ -268,7 +269,7 @@ public class NewAggregatorEndpointTests {
|
||||
}
|
||||
|
||||
private class NullReturningMessageProcessor implements MessageGroupProcessor {
|
||||
public void processAndSend(MessageGroup group, MessageChannel outputChannel) {
|
||||
public void processAndSend(MessageGroup group, MessageChannelTemplate channelTemplate, MessageChannel outputChannel) {
|
||||
//noop
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.channel.MessageChannelTemplate;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
@@ -320,14 +321,14 @@ public class NewConcurrentAggregatorEndpointTests {
|
||||
|
||||
private class MultiplyingProcessor implements MessageGroupProcessor {
|
||||
public void processAndSend(MessageGroup group,
|
||||
MessageChannel outputChannel
|
||||
MessageChannelTemplate channelTemplate, MessageChannel outputChannel
|
||||
) {
|
||||
Integer product = 1;
|
||||
List<Message<?>> messagesUpForProcessing = group.getMessages();
|
||||
for (Message<?> message : messagesUpForProcessing) {
|
||||
product *= (Integer) message.getPayload();
|
||||
}
|
||||
outputChannel.send(MessageBuilder.withPayload(product).build());
|
||||
channelTemplate.send(MessageBuilder.withPayload(product).build(), outputChannel);
|
||||
|
||||
group.onProcessingOf(
|
||||
messagesUpForProcessing.toArray(new Message[messagesUpForProcessing.size()])
|
||||
@@ -337,7 +338,7 @@ public class NewConcurrentAggregatorEndpointTests {
|
||||
}
|
||||
|
||||
private class NullReturningMessageProcessor implements MessageGroupProcessor {
|
||||
public void processAndSend(MessageGroup group, MessageChannel outputChannel) {
|
||||
public void processAndSend(MessageGroup group, MessageChannelTemplate channelTemplate, MessageChannel outputChannel) {
|
||||
//noop
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@
|
||||
</channel>
|
||||
|
||||
<beans:bean id="summer"
|
||||
class="org.springframework.integration.aggregator.integration.ConcurrentAggregatorIntegrationTests$SummingAggregator" />
|
||||
class="org.springframework.integration.aggregator.integration.AggregatorIntegrationTests$SummingAggregator" />
|
||||
|
||||
</beans:beans>
|
||||
@@ -16,15 +16,10 @@
|
||||
|
||||
package org.springframework.integration.aggregator.integration;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.aggregator.AbstractMessageAggregator;
|
||||
import org.springframework.integration.aggregator.MethodInvokingAggregator;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
@@ -36,6 +31,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
* @author Alex Peters
|
||||
@@ -43,7 +40,7 @@ import java.util.Map;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class ConcurrentAggregatorIntegrationTests {
|
||||
public class AggregatorIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("input")
|
||||
@@ -53,14 +50,6 @@ public class ConcurrentAggregatorIntegrationTests {
|
||||
@Qualifier("output")
|
||||
private PollableChannel output;
|
||||
|
||||
@Autowired
|
||||
AbstractMessageAggregator aggregator;
|
||||
|
||||
@Test
|
||||
public void configOk() throws Exception {
|
||||
assertThat(aggregator, is(MethodInvokingAggregator.class));
|
||||
}
|
||||
|
||||
@Test(timeout=5000)
|
||||
public void aggregate() throws Exception {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
@@ -16,22 +16,10 @@
|
||||
|
||||
package org.springframework.integration.aggregator.integration;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.aggregator.AbstractMessageAggregator;
|
||||
import org.springframework.integration.aggregator.DefaultMessageAggregator;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
@@ -39,6 +27,15 @@ import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Alex Peters
|
||||
* @author Iwein Fuld
|
||||
@@ -55,15 +52,6 @@ public class DefaultMessageAggregatorIntegrationTests {
|
||||
@Qualifier("output")
|
||||
private PollableChannel output;
|
||||
|
||||
@Autowired
|
||||
private AbstractMessageAggregator aggregator;
|
||||
|
||||
|
||||
@Test
|
||||
public void configOk() throws Exception {
|
||||
assertThat(aggregator, is(DefaultMessageAggregator.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(timeout = 1000)
|
||||
public void aggregate() throws Exception {
|
||||
|
||||
@@ -16,80 +16,81 @@
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.aggregator.CompletionStrategy;
|
||||
import org.springframework.integration.aggregator.CompletionStrategyAdapter;
|
||||
import org.springframework.integration.aggregator.CorrelationStrategy;
|
||||
import org.springframework.integration.aggregator.MethodInvokingAggregator;
|
||||
import org.springframework.integration.aggregator.*;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.util.MethodInvoker;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.util.MethodInvoker;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class AggregatorParserTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
private ApplicationContext context;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.context = new ClassPathXmlApplicationContext("aggregatorParserTests.xml", this.getClass());
|
||||
}
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.context = new ClassPathXmlApplicationContext("aggregatorParserTests.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggregation() {
|
||||
MessageChannel input = (MessageChannel) context.getBean("aggregatorWithReferenceInput");
|
||||
TestAggregatorBean aggregatorBean = (TestAggregatorBean) context.getBean("aggregatorBean");
|
||||
List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
|
||||
outboundMessages.add(createMessage("123", "id1", 3, 1, null));
|
||||
outboundMessages.add(createMessage("789", "id1", 3, 3, null));
|
||||
outboundMessages.add(createMessage("456", "id1", 3, 2, null));
|
||||
for (Message<?> message : outboundMessages) {
|
||||
input.send(message);
|
||||
}
|
||||
Assert.assertEquals("One and only one message must have been aggregated", 1, aggregatorBean
|
||||
.getAggregatedMessages().size());
|
||||
Message<?> aggregatedMessage = aggregatorBean.getAggregatedMessages().get("id1");
|
||||
Assert.assertEquals("The aggreggated message payload is not correct", "123456789", aggregatedMessage
|
||||
.getPayload());
|
||||
}
|
||||
@Test
|
||||
public void testAggregation() {
|
||||
MessageChannel input = (MessageChannel) context.getBean("aggregatorWithReferenceInput");
|
||||
TestAggregatorBean aggregatorBean = (TestAggregatorBean) context.getBean("aggregatorBean");
|
||||
List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
|
||||
outboundMessages.add(createMessage("123", "id1", 3, 1, null));
|
||||
outboundMessages.add(createMessage("789", "id1", 3, 3, null));
|
||||
outboundMessages.add(createMessage("456", "id1", 3, 2, null));
|
||||
for (Message<?> message : outboundMessages) {
|
||||
input.send(message);
|
||||
}
|
||||
assertEquals("One and only one message must have been aggregated", 1, aggregatorBean
|
||||
.getAggregatedMessages().size());
|
||||
Message<?> aggregatedMessage = aggregatorBean.getAggregatedMessages().get("id1");
|
||||
assertEquals("The aggregated message payload is not correct", "123456789", aggregatedMessage
|
||||
.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertyAssignment() throws Exception {
|
||||
EventDrivenConsumer endpoint =
|
||||
(EventDrivenConsumer) context.getBean("completelyDefinedAggregator");
|
||||
CompletionStrategy completionStrategy = (CompletionStrategy) context.getBean("completionStrategy");
|
||||
@Test
|
||||
public void testPropertyAssignment() throws Exception {
|
||||
EventDrivenConsumer endpoint =
|
||||
(EventDrivenConsumer) context.getBean("completelyDefinedAggregator");
|
||||
CompletionStrategy completionStrategy = (CompletionStrategy) context.getBean("completionStrategy");
|
||||
CorrelationStrategy correlationStrategy = (CorrelationStrategy) context.getBean("correlationStrategy");
|
||||
MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
|
||||
MessageChannel discardChannel = (MessageChannel) context.getBean("discardChannel");
|
||||
Object consumer = TestUtils.getPropertyValue(endpoint, "handler");
|
||||
Assert.assertEquals(MethodInvokingAggregator.class, consumer.getClass());
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
|
||||
Method expectedMethod = TestAggregatorBean.class.getMethod("createSingleMessageFromGroup", List.class);
|
||||
Assert.assertEquals("The MethodInvokingAggregator is not injected with the appropriate aggregation method",
|
||||
expectedMethod, new DirectFieldAccessor(accessor.getPropertyValue("methodInvoker")).getPropertyValue("method"));
|
||||
Assert.assertEquals(
|
||||
"The AggregatorEndpoint is not injected with the appropriate CompletionStrategy instance",
|
||||
completionStrategy, accessor.getPropertyValue("completionStrategy"));
|
||||
Assert.assertEquals("The AggregatorEndpoint is not injected with the appropriate CorrelationStrategy instance",
|
||||
MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
|
||||
MessageChannel discardChannel = (MessageChannel) context.getBean("discardChannel");
|
||||
Object consumer = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
|
||||
assertThat(consumer, is(CorrelatingMessageHandler.class));
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
|
||||
Method expectedMethod = TestAggregatorBean.class.getMethod("createSingleMessageFromGroup", List.class);
|
||||
assertEquals("The MethodInvokingAggregator is not injected with the appropriate aggregation method",
|
||||
expectedMethod, ((MessageListMethodAdapter) new DirectFieldAccessor(accessor.getPropertyValue("outputProcessor")).getPropertyValue("adapter")).getMethod());
|
||||
assertEquals(
|
||||
"The AggregatorEndpoint is not injected with the appropriate CompletionStrategy instance",
|
||||
completionStrategy, accessor.getPropertyValue("completionStrategy"));
|
||||
assertEquals("The AggregatorEndpoint is not injected with the appropriate CorrelationStrategy instance",
|
||||
correlationStrategy, accessor.getPropertyValue("correlationStrategy"));
|
||||
Assert.assertEquals("The AggregatorEndpoint is not injected with the appropriate output channel",
|
||||
outputChannel, accessor.getPropertyValue("outputChannel"));
|
||||
@@ -102,9 +103,6 @@ public class AggregatorParserTests {
|
||||
true, accessor.getPropertyValue("sendPartialResultOnTimeout"));
|
||||
Assert.assertEquals("The AggregatorEndpoint is not configured with the appropriate reaper interval",
|
||||
135l, accessor.getPropertyValue("reaperInterval"));
|
||||
Assert.assertEquals(
|
||||
"The AggregatorEndpoint is not configured with the appropriate tracked correlationId capacity",
|
||||
99, accessor.getPropertyValue("trackedCorrelationIdCapacity"));
|
||||
Assert.assertEquals("The AggregatorEndpoint is not configured with the appropriate timeout",
|
||||
42l, accessor.getPropertyValue("timeout"));
|
||||
}
|
||||
@@ -136,43 +134,43 @@ public class AggregatorParserTests {
|
||||
"completionStrategyMethodWithMissingReference.xml", this.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggregatorWithPojoCompletionStrategy() {
|
||||
MessageChannel input = (MessageChannel) context.getBean("aggregatorWithPojoCompletionStrategyInput");
|
||||
EventDrivenConsumer endpoint =
|
||||
(EventDrivenConsumer) context.getBean("aggregatorWithPojoCompletionStrategy");
|
||||
CompletionStrategy completionStrategy = TestUtils.getPropertyValue(endpoint,
|
||||
"handler.completionStrategy", CompletionStrategy.class);
|
||||
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"));
|
||||
input.send(createMessage(1l, "id1", 0 , 0, null));
|
||||
input.send(createMessage(2l, "id1", 0 , 0, null));
|
||||
input.send(createMessage(3l, "id1", 0 , 0, null));
|
||||
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
Assert.assertNull(reply);
|
||||
input.send(createMessage(5l, "id1", 0 , 0, null));
|
||||
reply = outputChannel.receive(0);
|
||||
Assert.assertNotNull(reply);
|
||||
Assert.assertEquals(11l, reply.getPayload());
|
||||
}
|
||||
@Test
|
||||
public void testAggregatorWithPojoCompletionStrategy() {
|
||||
MessageChannel input = (MessageChannel) context.getBean("aggregatorWithPojoCompletionStrategyInput");
|
||||
EventDrivenConsumer endpoint =
|
||||
(EventDrivenConsumer) context.getBean("aggregatorWithPojoCompletionStrategy");
|
||||
CompletionStrategy completionStrategy = (CompletionStrategy) new DirectFieldAccessor(
|
||||
new DirectFieldAccessor(endpoint).getPropertyValue("handler")).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"));
|
||||
input.send(createMessage(1l, "correllationId", 0, 0, null));
|
||||
input.send(createMessage(2l, "correllationId", 0, 1, null));
|
||||
input.send(createMessage(3l, "correllationId", 0, 2, null));
|
||||
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
Assert.assertNull(reply);
|
||||
input.send(createMessage(5l, "correllationId", 0, 3, null));
|
||||
reply = outputChannel.receive(0);
|
||||
Assert.assertNotNull(reply);
|
||||
assertEquals(11l, reply.getPayload());
|
||||
}
|
||||
|
||||
@Test(expected=BeanCreationException.class)
|
||||
public void testAggregatorWithInvalidCompletionStrategyMethod() {
|
||||
context = new ClassPathXmlApplicationContext("invalidCompletionStrategyMethod.xml", this.getClass());
|
||||
}
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void testAggregatorWithInvalidCompletionStrategyMethod() {
|
||||
context = new ClassPathXmlApplicationContext("invalidCompletionStrategyMethod.xml", this.getClass());
|
||||
}
|
||||
|
||||
|
||||
private static <T> Message<T> createMessage(T payload, Object correlationId, int sequenceSize, int sequenceNumber,
|
||||
MessageChannel outputChannel) {
|
||||
return MessageBuilder.withPayload(payload)
|
||||
.setCorrelationId(correlationId)
|
||||
.setSequenceSize(sequenceSize)
|
||||
.setSequenceNumber(sequenceNumber)
|
||||
.setReplyChannel(outputChannel).build();
|
||||
}
|
||||
private static <T> Message<T> createMessage(T payload, Object correlationId, int sequenceSize, int sequenceNumber,
|
||||
MessageChannel outputChannel) {
|
||||
return MessageBuilder.withPayload(payload)
|
||||
.setCorrelationId(correlationId)
|
||||
.setSequenceSize(sequenceSize)
|
||||
.setSequenceNumber(sequenceNumber)
|
||||
.setReplyChannel(outputChannel).build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<beans:bean id="correlationStrategy" class="org.springframework.integration.config.AggregatorWithCorrelationStrategyTests$FirstLetterCorrelationStrategy"/>
|
||||
<beans:bean id="correlationStrategy"
|
||||
class="org.springframework.integration.config.AggregatorWithCorrelationStrategyTests$FirstLetterCorrelationStrategy"/>
|
||||
|
||||
<beans:bean id="pojoCorrelationStrategy" class="org.springframework.integration.config.AggregatorWithCorrelationStrategyTests$PojoCorrelationStrategy"/>
|
||||
<beans:bean id="pojoCorrelationStrategy"
|
||||
class="org.springframework.integration.config.AggregatorWithCorrelationStrategyTests$PojoCorrelationStrategy"/>
|
||||
|
||||
<beans:bean id="completionStrategy" class="org.springframework.integration.config.AggregatorWithCorrelationStrategyTests$MessageCountCompletionStrategy">
|
||||
<beans:constructor-arg value="3"/>
|
||||
|
||||
@@ -16,12 +16,9 @@
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.aggregator.CompletionStrategy;
|
||||
@@ -34,8 +31,14 @@ import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.matchers.JUnitMatchers.containsString;
|
||||
|
||||
/**
|
||||
* @author: Marius Bogoevici
|
||||
* @author Marius Bogoevici
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -60,42 +63,40 @@ public class AggregatorWithCorrelationStrategyTests {
|
||||
|
||||
@Test
|
||||
public void testCorrelationAndCompletion() {
|
||||
inputChannel.send(MessageBuilder.withPayload("A1").build());
|
||||
inputChannel.send(MessageBuilder.withPayload("B2").build());
|
||||
inputChannel.send(MessageBuilder.withPayload("C3").build());
|
||||
inputChannel.send(MessageBuilder.withPayload("A4").build());
|
||||
inputChannel.send(MessageBuilder.withPayload("B5").build());
|
||||
inputChannel.send(MessageBuilder.withPayload("C6").build());
|
||||
inputChannel.send(MessageBuilder.withPayload("A7").build());
|
||||
inputChannel.send(MessageBuilder.withPayload("B8").build());
|
||||
inputChannel.send(MessageBuilder.withPayload("C9").build());
|
||||
receiveAndCompare(outputChannel, "A1A4A7");
|
||||
receiveAndCompare(outputChannel, "B2B5B8");
|
||||
receiveAndCompare(outputChannel, "C3C6C9");
|
||||
inputChannel.send(MessageBuilder.withPayload("A1").setSequenceNumber(0).build());
|
||||
inputChannel.send(MessageBuilder.withPayload("B2").setSequenceNumber(0).build());
|
||||
inputChannel.send(MessageBuilder.withPayload("C3").setSequenceNumber(0).build());
|
||||
inputChannel.send(MessageBuilder.withPayload("A4").setSequenceNumber(1).build());
|
||||
inputChannel.send(MessageBuilder.withPayload("B5").setSequenceNumber(1).build());
|
||||
inputChannel.send(MessageBuilder.withPayload("C6").setSequenceNumber(1).build());
|
||||
inputChannel.send(MessageBuilder.withPayload("A7").setSequenceNumber(2).build());
|
||||
inputChannel.send(MessageBuilder.withPayload("B8").setSequenceNumber(2).build());
|
||||
inputChannel.send(MessageBuilder.withPayload("C9").setSequenceNumber(2).build());
|
||||
receiveAndCompare(outputChannel, "A1","A4","A7");
|
||||
receiveAndCompare(outputChannel, "B2","B5","B8");
|
||||
receiveAndCompare(outputChannel, "C3","C6","C9");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorrelationAndCompletionWithPojo() {
|
||||
// the test verifies how a pojo strategy is applied
|
||||
// Strings are correlated by their first letter, integers are correlated by the last digit
|
||||
pojoInputChannel.send(MessageBuilder.withPayload("X1").build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload("Y2").build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload(93).build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload("X4").build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload("Y5").build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload(113).build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload("X7").build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload("Y8").build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload(213).build());
|
||||
receiveAndCompare(pojoOutputChannel, "X1X4X7");
|
||||
receiveAndCompare(pojoOutputChannel, "Y2Y5Y8");
|
||||
receiveAndCompare(pojoOutputChannel, "93113213");
|
||||
pojoInputChannel.send(MessageBuilder.withPayload("X1").setSequenceNumber(0).build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload(93).setSequenceNumber(0).build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload("X4").setSequenceNumber(1).build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload(113).setSequenceNumber(1).build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload("X7").setSequenceNumber(2).build());
|
||||
pojoInputChannel.send(MessageBuilder.withPayload(213).setSequenceNumber(2).build());
|
||||
receiveAndCompare(pojoOutputChannel, "X1","X4","X7");
|
||||
receiveAndCompare(pojoOutputChannel, "93","113","213");
|
||||
}
|
||||
|
||||
private void receiveAndCompare(PollableChannel outputChannel, String expectedValue) {
|
||||
Message<?> firstResult = outputChannel.receive(500);
|
||||
Assert.assertNotNull(firstResult);
|
||||
Assert.assertEquals(expectedValue, firstResult.getPayload());
|
||||
private void receiveAndCompare(PollableChannel outputChannel, String... expectedValues) {
|
||||
Message<?> message = outputChannel.receive(500);
|
||||
Assert.assertNotNull(message);
|
||||
for (String expectedValue : expectedValues) {
|
||||
assertThat((String)message.getPayload(), containsString(expectedValue));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,8 +129,8 @@ public class AggregatorWithCorrelationStrategyTests {
|
||||
return message.substring(0,1);
|
||||
}
|
||||
|
||||
public String correlate(Integer mesage) {
|
||||
return Integer.toString(mesage % 10);
|
||||
public String correlate(Integer message) {
|
||||
return Integer.toString(message % 10);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -137,7 +138,7 @@ public class AggregatorWithCorrelationStrategyTests {
|
||||
public static class SimpleAggregator {
|
||||
|
||||
@Aggregator
|
||||
protected String concatenate(List<Object> payloads) {
|
||||
public String concatenate(List<Object> payloads) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (Object payload: payloads) {
|
||||
buffer.append(payload.toString());
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
</channel>
|
||||
|
||||
<channel id="aggregatorWithReferenceInput"/>
|
||||
<aggregator id="aggregatorWithReference" ref="aggregatorBean" input-channel="aggregatorWithReferenceInput"/>
|
||||
<aggregator id="aggregatorWithReference" ref="aggregatorBean"
|
||||
input-channel="aggregatorWithReferenceInput" output-channel="outputChannel"/>
|
||||
|
||||
<channel id="completelyDefinedAggregatorInput"/>
|
||||
<aggregator id="completelyDefinedAggregator"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<util:properties id="testConfigurations" location="classpath:org/springframework/integration/config/xml/innerdefaware.properties"/>
|
||||
<util:properties id="testConfigurations"
|
||||
location="classpath:org/springframework/integration/config/xml/innerdefaware.properties"/>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -16,20 +16,9 @@
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
@@ -42,7 +31,6 @@ import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -50,6 +38,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
@@ -253,11 +246,11 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
MessageChannel inChannel = (MessageChannel) ac.getBean("inChannel");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Map<String, Object> headers = stubHeaders(i, 5, 1);
|
||||
Message<Integer> message = new GenericMessage<Integer>(i, headers);
|
||||
Message<Integer> message = MessageBuilder.withPayload(i).copyHeaders(headers).build();
|
||||
inChannel.send(message);
|
||||
}
|
||||
PollableChannel output = (PollableChannel) ac.getBean("outChannel");
|
||||
assertEquals(0 + 1 + 2 + 3 + 4, output.receive().getPayload());
|
||||
assertEquals(0 + 1 + 2 + 3 + 4, output.receive(100).getPayload());
|
||||
}
|
||||
|
||||
private void testFilterDefinitionSuccess(String configProperty){
|
||||
@@ -284,7 +277,6 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
headers.put(MessageHeaders.SEQUENCE_NUMBER, sequenceNumber);
|
||||
headers.put(MessageHeaders.SEQUENCE_SIZE, sequenceSize);
|
||||
headers.put(MessageHeaders.CORRELATION_ID, correllationId);
|
||||
headers.put(MessageHeaders.ID, 1);
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user