Search in sources :

Example 26 with SimpleMessageGroup

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

the class AggregatingMessageGroupProcessorHeaderTests method twoMessagesWithConflicts.

private void twoMessagesWithConflicts(MessageGroupProcessor processor) {
    Map<String, Object> headers1 = new HashMap<String, Object>();
    headers1.put("k1", "foo");
    headers1.put("k2", new Integer(123));
    Message<?> message1 = correlatedMessage(1, 2, 1, headers1);
    Map<String, Object> headers2 = new HashMap<String, Object>();
    headers2.put("k1", "bar");
    headers2.put("k2", new Integer(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"));
    assertEquals(123, 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 27 with SimpleMessageGroup

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

the class ResequencingMessageGroupProcessorTests method shouldPartiallProcessIncompleteSequence.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void shouldPartiallProcessIncompleteSequence() {
    Message prototypeMessage = MessageBuilder.withPayload("foo").setCorrelationId("x").setSequenceNumber(1).setSequenceSize(4).build();
    List<Message<?>> messages = new ArrayList<Message<?>>();
    Message message2 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(4).build();
    Message message1 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(1).build();
    Message message3 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(3).build();
    messages.add(message1);
    messages.add(message2);
    messages.add(message3);
    SimpleMessageGroup group = new SimpleMessageGroup(messages, "x");
    List<Message> processedMessages = (List<Message>) processor.processMessageGroup(group);
    assertThat(processedMessages, hasItems(message1));
    assertThat(processedMessages.size(), is(1));
}
Also used : Message(org.springframework.messaging.Message) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 28 with SimpleMessageGroup

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

the class TimeoutCountSequenceSizeReleaseStrategyTests method testCompleteList.

@Test
public void testCompleteList() {
    Message<String> message1 = MessageBuilder.withPayload("test1").setSequenceSize(2).build();
    Message<String> message2 = MessageBuilder.withPayload("test2").setSequenceSize(2).build();
    SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
    messages.add(message1);
    messages.add(message2);
    SequenceSizeReleaseStrategy releaseStrategy = new SequenceSizeReleaseStrategy();
    assertTrue(releaseStrategy.canRelease(messages));
}
Also used : SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 29 with SimpleMessageGroup

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

the class TimeoutCountSequenceSizeReleaseStrategyTests method testIncompleteListWithCount.

@Test
public void testIncompleteListWithCount() {
    Message<String> message = MessageBuilder.withPayload("test1").setSequenceSize(2).build();
    SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
    messages.add(message);
    TimeoutCountSequenceSizeReleaseStrategy releaseStrategy = new TimeoutCountSequenceSizeReleaseStrategy(1, TimeoutCountSequenceSizeReleaseStrategy.DEFAULT_TIMEOUT);
    assertTrue(releaseStrategy.canRelease(messages));
}
Also used : SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 30 with SimpleMessageGroup

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

the class GemfireGroupStoreTests method testNonExistingEmptyMessageGroup.

@Test
public void testNonExistingEmptyMessageGroup() throws Exception {
    GemfireMessageStore store = new GemfireMessageStore(region);
    MessageGroup messageGroup = store.getMessageGroup(1);
    assertNotNull(messageGroup);
    assertTrue(messageGroup instanceof SimpleMessageGroup);
    assertEquals(0, messageGroup.size());
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) 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