Search in sources :

Example 11 with SimpleMessageGroup

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

the class SequenceSizeReleaseStrategyTests method shouldPartiallyReleaseAsEarlyAsPossible.

@Test
public void shouldPartiallyReleaseAsEarlyAsPossible() {
    SequenceSizeReleaseStrategy releaseStrategy = new SequenceSizeReleaseStrategy();
    releaseStrategy.setReleasePartialSequences(true);
    SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
    Message<String> message1 = MessageBuilder.withPayload("test1").setSequenceSize(5).setSequenceNumber(1).build();
    Message<String> message2 = MessageBuilder.withPayload("test2").setSequenceSize(5).setSequenceNumber(2).build();
    Message<String> message3 = MessageBuilder.withPayload("test3").setSequenceSize(5).setSequenceNumber(3).build();
    Message<String> message4 = MessageBuilder.withPayload("test4").setSequenceSize(5).setSequenceNumber(4).build();
    Message<String> message5 = MessageBuilder.withPayload("test5").setSequenceSize(5).setSequenceNumber(5).build();
    messages.add(message5);
    assertFalse(releaseStrategy.canRelease(messages));
    messages.add(message1);
    assertTrue(releaseStrategy.canRelease(messages));
    messages.add(message2);
    assertTrue(releaseStrategy.canRelease(messages));
    messages.add(message3);
    assertTrue(releaseStrategy.canRelease(messages));
    messages.add(message4);
    assertTrue(releaseStrategy.canRelease(messages));
}
Also used : SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 12 with SimpleMessageGroup

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

the class SequenceSizeReleaseStrategyTests method shouldReleaseHeadOfSequenceDeliveredInOrder.

@Test
public void shouldReleaseHeadOfSequenceDeliveredInOrder() {
    SequenceSizeReleaseStrategy releaseStrategy = new SequenceSizeReleaseStrategy();
    releaseStrategy.setReleasePartialSequences(true);
    SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
    assertTrue(releaseStrategy.canRelease(groupWithFirstMessagesOfIncompleteSequence(messages)));
}
Also used : SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 13 with SimpleMessageGroup

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

the class ResequencingMessageGroupProcessorTests method shouldProcessSequence.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void shouldProcessSequence() {
    Message prototypeMessage = MessageBuilder.withPayload("foo").setCorrelationId("x").setSequenceNumber(1).setSequenceSize(3).build();
    List<Message<?>> messages = new ArrayList<Message<?>>();
    Message message1 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(1).build();
    Message message2 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(2).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, message2, message3));
}
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 14 with SimpleMessageGroup

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

the class TimeoutCountSequenceSizeReleaseStrategyTests method testIncompleteListWithTimeout.

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

Example 15 with SimpleMessageGroup

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

the class TimeoutCountSequenceSizeReleaseStrategyTests method testIncompleteList.

@Test
public void testIncompleteList() {
    Message<String> message = MessageBuilder.withPayload("test1").setSequenceSize(2).build();
    SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
    messages.add(message);
    TimeoutCountSequenceSizeReleaseStrategy releaseStrategy = new TimeoutCountSequenceSizeReleaseStrategy();
    assertFalse(releaseStrategy.canRelease(messages));
}
Also used : 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