Search in sources :

Example 1 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup 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"));
}
Also used : Message(org.springframework.messaging.Message) HashMap(java.util.HashMap) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup)

Example 2 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup 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"));
}
Also used : Message(org.springframework.messaging.Message) HashMap(java.util.HashMap) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup)

Example 3 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup 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"));
}
Also used : Message(org.springframework.messaging.Message) HashMap(java.util.HashMap) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup)

Example 4 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup 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"));
}
Also used : Message(org.springframework.messaging.Message) HashMap(java.util.HashMap) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup)

Example 5 with SimpleMessageGroup

use of org.springframework.integration.store.SimpleMessageGroup in project spring-integration by spring-projects.

the class AggregatingMessageGroupProcessorHeaderTests method testNullHeaderValue.

@Test
public void testNullHeaderValue() {
    DefaultAggregatingMessageGroupProcessor processor = new DefaultAggregatingMessageGroupProcessor();
    DirectFieldAccessor dfa = new DirectFieldAccessor(processor);
    dfa.setPropertyValue("messageBuilderFactory", new MutableMessageBuilderFactory());
    Map<String, Object> headers1 = new HashMap<String, Object>();
    headers1.put("k1", "foo");
    headers1.put("k2", null);
    Message<?> message1 = MutableMessageBuilder.withPayload("test").setCorrelationId(1).setSequenceNumber(1).setSequenceSize(2).copyHeadersIfAbsent(headers1).build();
    Map<String, Object> headers2 = new HashMap<String, Object>();
    headers2.put("k1", "bar");
    headers2.put("k2", 123);
    Message<?> message2 = correlatedMessage(1, 2, 2, headers2);
    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;
    assertNull(resultMessage.getHeaders().get("k1"));
    assertNull(resultMessage.getHeaders().get("k2"));
    headers1 = new HashMap<String, Object>();
    headers1.put("k1", "foo");
    headers1.put("k2", 123);
    message1 = correlatedMessage(1, 2, 1, headers1);
    headers2 = new HashMap<String, Object>();
    headers2.put("k1", "bar");
    headers2.put("k2", null);
    message2 = MutableMessageBuilder.withPayload("test").setCorrelationId(1).setSequenceNumber(2).setSequenceSize(2).copyHeadersIfAbsent(headers2).build();
    messages = Arrays.<Message<?>>asList(message1, message2);
    group = new SimpleMessageGroup(messages, 1);
    result = processor.processMessageGroup(group);
    resultMessage = (Message<?>) result;
    assertNull(resultMessage.getHeaders().get("k1"));
    assertNull(resultMessage.getHeaders().get("k2"));
}
Also used : Message(org.springframework.messaging.Message) HashMap(java.util.HashMap) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MutableMessageBuilderFactory(org.springframework.integration.support.MutableMessageBuilderFactory) Test(org.junit.Test)

Aggregations

SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)31 Test (org.junit.Test)21 MessageGroup (org.springframework.integration.store.MessageGroup)13 Message (org.springframework.messaging.Message)8 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 List (java.util.List)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 Method (java.lang.reflect.Method)2 Query (org.springframework.data.mongodb.core.query.Query)2 QueueChannel (org.springframework.integration.channel.QueueChannel)2 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)2 Date (java.util.Date)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)1 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)1 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)1 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)1 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)1