Search in sources :

Example 21 with SimpleMessageGroup

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

the class SequenceSizeReleaseStrategyTests method testEmptyGroup.

@Test
public void testEmptyGroup() {
    SequenceSizeReleaseStrategy releaseStrategy = new SequenceSizeReleaseStrategy();
    releaseStrategy.setReleasePartialSequences(true);
    SimpleMessageGroup messages = new SimpleMessageGroup("FOO");
    Message<String> message = MessageBuilder.withPayload("test1").setSequenceSize(1).build();
    messages.add(message);
    messages.remove(message);
    assertTrue(releaseStrategy.canRelease(messages));
}
Also used : SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 22 with SimpleMessageGroup

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

the class SequenceSizeReleaseStrategyTests 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 23 with SimpleMessageGroup

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

the class ResequencerParserTests method testReleaseStrategyRefAndMethod.

@Test
public void testReleaseStrategyRefAndMethod() throws Exception {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithReleaseStrategyRefAndMethod");
    ResequencingMessageHandler resequencer = getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    Object releaseStrategyBean = context.getBean("testReleaseStrategyPojo");
    assertTrue("Release strategy is not of the expected type", releaseStrategyBean instanceof TestReleaseStrategyPojo);
    TestReleaseStrategyPojo expectedReleaseStrategy = (TestReleaseStrategyPojo) releaseStrategyBean;
    int currentInvocationCount = expectedReleaseStrategy.invocationCount;
    ReleaseStrategy effectiveReleaseStrategy = (ReleaseStrategy) getPropertyValue(resequencer, "releaseStrategy");
    assertTrue("The release strategy is expected to be a MethodInvokingReleaseStrategy", effectiveReleaseStrategy instanceof MethodInvokingReleaseStrategy);
    effectiveReleaseStrategy.canRelease(new SimpleMessageGroup("test"));
    assertEquals("The ResequencerEndpoint was not invoked the expected number of times;", currentInvocationCount + 1, expectedReleaseStrategy.invocationCount);
    assertTrue(TestUtils.getPropertyValue(resequencer, "expireGroupsUponTimeout", Boolean.class));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) ReleaseStrategy(org.springframework.integration.aggregator.ReleaseStrategy) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 24 with SimpleMessageGroup

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

the class AbstractCorrelatingMessageHandlerTests method testDontReapIfAlreadyCompleteAfterRefetch.

/*
	 * INT-3216 - Verifies the complete early exit is taken after a refresh.
	 */
@Test
public void testDontReapIfAlreadyCompleteAfterRefetch() 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);
    mgs.addMessagesToGroup("foo", new GenericMessage<String>("foo"));
    MessageGroup group = new SimpleMessageGroup(mgs.getMessageGroup("foo"));
    mgs.completeGroup("foo");
    mgs = spy(mgs);
    new DirectFieldAccessor(handler).setPropertyValue("messageStore", mgs);
    Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class);
    forceComplete.setAccessible(true);
    MessageGroup groupInStore = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class).get("foo");
    assertTrue(groupInStore.isComplete());
    assertFalse(group.isComplete());
    new DirectFieldAccessor(group).setPropertyValue("lastModified", groupInStore.getLastModified());
    forceComplete.invoke(handler, group);
    verify(mgs).getMessageGroup("foo");
    assertNull(outputChannel.receive(0));
}
Also used : MessageGroupStore(org.springframework.integration.store.MessageGroupStore) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Method(java.lang.reflect.Method) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 25 with SimpleMessageGroup

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

the class AbstractCorrelatingMessageHandlerTests method testDontReapIfNewGroupFoundDuringRefetch.

/*
	 * INT-3216 - Verifies we don't complete if it's a completely new group (different timestamp).
	 */
@Test
public void testDontReapIfNewGroupFoundDuringRefetch() 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);
    mgs.addMessagesToGroup("foo", new GenericMessage<String>("foo"));
    MessageGroup group = new SimpleMessageGroup(mgs.getMessageGroup("foo"));
    mgs = spy(mgs);
    new DirectFieldAccessor(handler).setPropertyValue("messageStore", mgs);
    Method forceComplete = AbstractCorrelatingMessageHandler.class.getDeclaredMethod("forceComplete", MessageGroup.class);
    forceComplete.setAccessible(true);
    MessageGroup groupInStore = (MessageGroup) TestUtils.getPropertyValue(mgs, "groupIdToMessageGroup", Map.class).get("foo");
    assertFalse(groupInStore.isComplete());
    assertFalse(group.isComplete());
    DirectFieldAccessor directFieldAccessor = new DirectFieldAccessor(group);
    directFieldAccessor.setPropertyValue("lastModified", groupInStore.getLastModified());
    directFieldAccessor.setPropertyValue("timestamp", groupInStore.getTimestamp() - 1);
    forceComplete.invoke(handler, group);
    verify(mgs).getMessageGroup("foo");
    assertNull(outputChannel.receive(0));
}
Also used : MessageGroupStore(org.springframework.integration.store.MessageGroupStore) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Method(java.lang.reflect.Method) 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