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