Search in sources :

Example 1 with MessageGroup

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());
}
Also used : MessageGroupStore(org.springframework.integration.store.MessageGroupStore) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Method(java.lang.reflect.Method) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Collection(java.util.Collection) Test(org.junit.Test)

Example 2 with MessageGroup

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"));
}
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 MessageGroup

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"));
}
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 MessageGroup

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"));
}
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 MessageGroup

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"));
}
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)

Aggregations

MessageGroup (org.springframework.integration.store.MessageGroup)98 Test (org.junit.Test)79 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)54 GenericMessage (org.springframework.messaging.support.GenericMessage)36 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)25 Message (org.springframework.messaging.Message)20 ArrayList (java.util.ArrayList)19 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)15 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)14 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)13 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)13 MongoClient (com.mongodb.MongoClient)12 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)12 Transactional (org.springframework.transaction.annotation.Transactional)10 LinkedList (java.util.LinkedList)8 List (java.util.List)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 UUID (java.util.UUID)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 HashMap (java.util.HashMap)5