use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class AbstractCorrelatingMessageHandlerTests method testDontReapMessageOfOtherHandler.
@Test
public void testDontReapMessageOfOtherHandler() throws Exception {
MessageGroupStore groupStore = new SimpleMessageStore();
AggregatingMessageHandler handler1 = new AggregatingMessageHandler(group -> group, groupStore);
AggregatingMessageHandler handler2 = new AggregatingMessageHandler(group -> group, groupStore);
QueueChannel handler1DiscardChannel = new QueueChannel();
handler1.setDiscardChannel(handler1DiscardChannel);
QueueChannel handler2DiscardChannel = new QueueChannel();
handler2.setDiscardChannel(handler2DiscardChannel);
handler1.setReleaseStrategy(group -> false);
handler2.setReleaseStrategy(group -> false);
handler1.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
handler1.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
handler2.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("bar").build());
groupStore.expireMessageGroups(0);
assertTrue(handler1DiscardChannel.getQueueSize() == 2);
assertTrue(handler2DiscardChannel.getQueueSize() == 1);
}
use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class AggregatorIntegrationTests method testGroupTimeoutScheduling.
@Test
public void testGroupTimeoutScheduling() throws Exception {
for (int i = 0; i < 5; i++) {
Map<String, Object> headers = stubHeaders(i, 5, 1);
this.groupTimeoutAggregatorInput.send(new GenericMessage<Integer>(i, headers));
// Wait until 'group-timeout' does its stuff.
MessageGroupStore mgs = TestUtils.getPropertyValue(this.context.getBean("gta.handler"), "messageStore", MessageGroupStore.class);
int n = 0;
while (n++ < 100 && mgs.getMessageGroupCount() > 0) {
Thread.sleep(100);
}
assertTrue("Group did not complete", n < 100);
assertNotNull(this.output.receive(10000));
assertNull(this.discard.receive(0));
}
}
use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class DelayHandlerTests method testRescheduleForTheDateDelay.
@Test
public void testRescheduleForTheDateDelay() throws Exception {
this.delayHandler.setDelayExpression(new SpelExpressionParser().parseExpression("payload"));
this.delayHandler.setOutputChannel(new DirectChannel());
this.delayHandler.setIgnoreExpressionFailures(false);
startDelayerHandler();
Calendar releaseDate = Calendar.getInstance();
releaseDate.add(Calendar.HOUR, 1);
this.delayHandler.handleMessage(new GenericMessage<>(releaseDate.getTime()));
// emulate restart
this.taskScheduler.destroy();
MessageGroupStore messageStore = TestUtils.getPropertyValue(this.delayHandler, "messageStore", MessageGroupStore.class);
MessageGroup messageGroup = messageStore.getMessageGroup(DELAYER_MESSAGE_GROUP_ID);
Message<?> messageInStore = messageGroup.getMessages().iterator().next();
Object payload = messageInStore.getPayload();
DirectFieldAccessor dfa = new DirectFieldAccessor(payload);
long requestTime = (long) dfa.getPropertyValue("requestDate");
Calendar requestDate = Calendar.getInstance();
requestDate.setTimeInMillis(requestTime);
requestDate.add(Calendar.HOUR, -2);
dfa.setPropertyValue("requestDate", requestDate.getTimeInMillis());
this.taskScheduler.afterPropertiesSet();
this.delayHandler.reschedulePersistedMessages();
Queue<?> works = TestUtils.getPropertyValue(this.taskScheduler, "scheduledExecutor.workQueue", Queue.class);
int n = 0;
while (n++ < 2000 && works.size() == 0) {
Thread.sleep(10);
}
assertEquals(1, works.size());
}
use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class MessageGroupQueueTests method validateMgqInterruptionStoreLock.
@Test
public void validateMgqInterruptionStoreLock() throws Exception {
MessageGroupStore mgs = Mockito.mock(MessageGroupStore.class);
Mockito.doAnswer(invocation -> {
Thread.sleep(5000);
return null;
}).when(mgs).addMessageToGroup(Mockito.any(Integer.class), Mockito.any(Message.class));
MessageGroup mg = Mockito.mock(MessageGroup.class);
Mockito.when(mgs.getMessageGroup(Mockito.any())).thenReturn(mg);
Mockito.when(mg.size()).thenReturn(0);
final MessageGroupQueue queue = new MessageGroupQueue(mgs, 1, 1);
final AtomicReference<InterruptedException> exceptionHolder = new AtomicReference<InterruptedException>();
Thread t1 = new Thread(() -> queue.offer(new GenericMessage<String>("hello")));
t1.start();
Thread.sleep(500);
Thread t2 = new Thread(() -> {
queue.offer(new GenericMessage<String>("hello"));
try {
queue.offer(new GenericMessage<String>("hello"), 100, TimeUnit.SECONDS);
} catch (InterruptedException e) {
exceptionHolder.set(e);
}
});
t2.start();
Thread.sleep(1000);
t2.interrupt();
Thread.sleep(1000);
assertTrue(exceptionHolder.get() instanceof InterruptedException);
}
use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class DelayerHandlerRescheduleIntegrationTests method testDelayerHandlerRescheduleWithJdbcMessageStore.
// INT-1132
@Test
public void testDelayerHandlerRescheduleWithJdbcMessageStore() throws Exception {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("DelayerHandlerRescheduleIntegrationTests-context.xml", getClass());
MessageChannel input = context.getBean("input", MessageChannel.class);
MessageGroupStore messageStore = context.getBean("messageStore", MessageGroupStore.class);
assertEquals(0, messageStore.getMessageGroupCount());
Message<String> message1 = MessageBuilder.withPayload("test1").build();
input.send(message1);
input.send(MessageBuilder.withPayload("test2").build());
// Emulate restart and check DB state before next start
// Interrupt taskScheduler as quickly as possible
ThreadPoolTaskScheduler taskScheduler = (ThreadPoolTaskScheduler) IntegrationContextUtils.getTaskScheduler(context);
taskScheduler.shutdown();
taskScheduler.getScheduledExecutor().awaitTermination(10, TimeUnit.SECONDS);
context.close();
try {
context.getBean("input", MessageChannel.class);
fail("IllegalStateException expected");
} catch (Exception e) {
assertTrue(e instanceof IllegalStateException);
assertTrue(e.getMessage().contains("BeanFactory not initialized or already closed - call 'refresh'"));
}
String delayerMessageGroupId = UUIDConverter.getUUID(DELAYER_ID + ".messageGroupId").toString();
assertEquals(1, messageStore.getMessageGroupCount());
assertEquals(delayerMessageGroupId, messageStore.iterator().next().getGroupId());
assertEquals(2, messageStore.messageGroupSize(delayerMessageGroupId));
assertEquals(2, messageStore.getMessageCountForAllMessageGroups());
MessageGroup messageGroup = messageStore.getMessageGroup(delayerMessageGroupId);
// Ensure that with the lazyLoadMessageGroups = false the MessageStore doesn't return PersistentMessageGroup
assertThat(messageGroup, instanceOf(SimpleMessageGroup.class));
Message<?> messageInStore = messageGroup.getMessages().iterator().next();
Object payload = messageInStore.getPayload();
// INT-3049
assertTrue(payload instanceof DelayHandler.DelayedMessageWrapper);
assertEquals(message1, ((DelayHandler.DelayedMessageWrapper) payload).getOriginal());
context.refresh();
PollableChannel output = context.getBean("output", PollableChannel.class);
Message<?> message = output.receive(20000);
assertNotNull(message);
Object payload1 = message.getPayload();
message = output.receive(20000);
assertNotNull(message);
Object payload2 = message.getPayload();
assertNotSame(payload1, payload2);
assertEquals(1, messageStore.getMessageGroupCount());
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
context.close();
}
Aggregations