use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class AbstractCorrelatingMessageHandlerTests method testReapWithChangeInSameMillisecond.
@Test
public void testReapWithChangeInSameMillisecond() throws Exception {
MessageGroupProcessor mgp = new DefaultAggregatingMessageGroupProcessor();
AggregatingMessageHandler handler = new AggregatingMessageHandler(mgp);
handler.setReleaseStrategy(group -> true);
QueueChannel outputChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
MessageGroupStore mgs = TestUtils.getPropertyValue(handler, "messageStore", MessageGroupStore.class);
Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class);
forceComplete.setAccessible(true);
GenericMessage<String> secondMessage = new GenericMessage<String>("bar");
mgs.addMessagesToGroup("foo", new GenericMessage<String>("foo"), secondMessage);
MessageGroup group = mgs.getMessageGroup("foo");
// remove a message
mgs.removeMessagesFromGroup("foo", secondMessage);
// force lastModified to be the same
MessageGroup groupNow = mgs.getMessageGroup("foo");
new DirectFieldAccessor(group).setPropertyValue("lastModified", groupNow.getLastModified());
forceComplete.invoke(handler, group);
Message<?> message = outputChannel.receive(0);
assertNotNull(message);
Collection<?> payload = (Collection<?>) message.getPayload();
assertEquals(1, payload.size());
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class AggregatingMessageGroupProcessorHeaderTests method singleMessage.
private void singleMessage(MessageGroupProcessor processor) {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("k1", "value1");
headers.put("k2", new Integer(2));
Message<?> message = correlatedMessage(1, 1, 1, headers);
List<Message<?>> messages = Collections.<Message<?>>singletonList(message);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof Message<?>);
Message<?> resultMessage = (Message<?>) result;
assertEquals("value1", resultMessage.getHeaders().get("k1"));
assertEquals(2, resultMessage.getHeaders().get("k2"));
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class AggregatingMessageGroupProcessorHeaderTests method multipleValuesConflict.
private void multipleValuesConflict(MessageGroupProcessor processor) {
Map<String, Object> headers1 = new HashMap<String, Object>();
headers1.put("common", "valueForAll");
headers1.put("conflict", "valueFor1");
Message<?> message1 = correlatedMessage(1, 3, 1, headers1);
Map<String, Object> headers2 = new HashMap<String, Object>();
headers2.put("common", "valueForAll");
headers2.put("conflict", "valueFor2");
Message<?> message2 = correlatedMessage(1, 3, 2, headers2);
Map<String, Object> headers3 = new HashMap<String, Object>();
headers3.put("conflict", "valueFor3");
headers3.put("common", "valueForAll");
Message<?> message3 = correlatedMessage(1, 3, 3, headers3);
List<Message<?>> messages = Arrays.<Message<?>>asList(message1, message2, message3);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof Message<?>);
Message<?> resultMessage = (Message<?>) result;
assertEquals("valueForAll", resultMessage.getHeaders().get("common"));
assertNull(resultMessage.getHeaders().get("conflict"));
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class AggregatingMessageGroupProcessorHeaderTests method twoMessagesWithoutConflicts.
private void twoMessagesWithoutConflicts(MessageGroupProcessor processor) {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("k1", "value1");
headers.put("k2", new Integer(2));
Message<?> message1 = correlatedMessage(1, 2, 1, headers);
Message<?> message2 = correlatedMessage(1, 2, 2, headers);
List<Message<?>> messages = Arrays.<Message<?>>asList(message1, message2);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof Message<?>);
Message<?> resultMessage = (Message<?>) result;
assertEquals("value1", resultMessage.getHeaders().get("k1"));
assertEquals(2, resultMessage.getHeaders().get("k2"));
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class AggregatingMessageGroupProcessorHeaderTests method missingValuesDoNotConflict.
private void missingValuesDoNotConflict(MessageGroupProcessor processor) {
Map<String, Object> headers1 = new HashMap<String, Object>();
headers1.put("only1", "value1");
headers1.put("commonTo1And2", "foo");
headers1.put("commonToAll", new Integer(123));
headers1.put("conflictBetween1And2", "valueFor1");
Message<?> message1 = correlatedMessage(1, 3, 1, headers1);
Map<String, Object> headers2 = new HashMap<String, Object>();
headers2.put("only2", "value2");
headers2.put("commonTo1And2", "foo");
headers2.put("commonTo2And3", "bar");
headers2.put("conflictBetween1And2", "valueFor2");
headers2.put("conflictBetween2And3", "valueFor2");
headers2.put("commonToAll", new Integer(123));
Message<?> message2 = correlatedMessage(1, 3, 2, headers2);
Map<String, Object> headers3 = new HashMap<String, Object>();
headers3.put("only3", "value3");
headers3.put("commonTo2And3", "bar");
headers3.put("commonToAll", new Integer(123));
headers3.put("conflictBetween2And3", "valueFor3");
Message<?> message3 = correlatedMessage(1, 3, 3, headers3);
List<Message<?>> messages = Arrays.<Message<?>>asList(message1, message2, message3);
MessageGroup group = new SimpleMessageGroup(messages, 1);
Object result = processor.processMessageGroup(group);
assertNotNull(result);
assertTrue(result instanceof Message<?>);
Message<?> resultMessage = (Message<?>) result;
assertEquals("value1", resultMessage.getHeaders().get("only1"));
assertEquals("value2", resultMessage.getHeaders().get("only2"));
assertEquals("value3", resultMessage.getHeaders().get("only3"));
assertEquals("foo", resultMessage.getHeaders().get("commonTo1And2"));
assertEquals("bar", resultMessage.getHeaders().get("commonTo2And3"));
assertEquals(123, resultMessage.getHeaders().get("commonToAll"));
assertNull(resultMessage.getHeaders().get("conflictBetween1And2"));
assertNull(resultMessage.getHeaders().get("conflictBetween2And3"));
}
Aggregations