use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class DelayerHandlerRescheduleIntegrationTests method testRollbackOnDelayerHandlerReleaseTask.
// INT-2649
@Test
public void testRollbackOnDelayerHandlerReleaseTask() throws Exception {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("DelayerHandlerRescheduleIntegrationTests-context.xml", getClass());
MessageChannel input = context.getBean("transactionalDelayerInput", MessageChannel.class);
MessageGroupStore messageStore = context.getBean("messageStore", MessageGroupStore.class);
String delayerMessageGroupId = UUIDConverter.getUUID("transactionalDelayer.messageGroupId").toString();
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
input.send(MessageBuilder.withPayload("test").build());
Thread.sleep(1000);
assertEquals(1, messageStore.messageGroupSize(delayerMessageGroupId));
// To check that 'rescheduling' works in the transaction boundaries too
context.close();
context.refresh();
assertTrue(RollbackTxSync.latch.await(20, TimeUnit.SECONDS));
// On transaction rollback the delayed Message should remain in the persistent MessageStore
assertEquals(1, messageStore.messageGroupSize(delayerMessageGroupId));
context.close();
}
use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class DelayerHandlerRescheduleIntegrationTests method testDelayerHandlerRescheduleWithGemfireMessageStore.
@Test
public void testDelayerHandlerRescheduleWithGemfireMessageStore() throws Exception {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("DelayerHandlerRescheduleIntegrationTests-context.xml", this.getClass());
MessageChannel input = context.getBean("input", MessageChannel.class);
MessageGroupStore messageStore = context.getBean("messageStore", MessageGroupStore.class);
String delayerMessageGroupId = DELAYER_ID + ".messageGroupId";
Message<String> message1 = MessageBuilder.withPayload("test1").build();
input.send(message1);
input.send(MessageBuilder.withPayload("test2").build());
// Emulate restart and check Cache 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'"));
}
assertEquals(1, messageStore.getMessageGroupCount());
assertEquals(delayerMessageGroupId, messageStore.iterator().next().getGroupId());
assertEquals(2, messageStore.messageGroupSize(delayerMessageGroupId));
assertEquals(2, messageStore.getMessageCountForAllMessageGroups());
MessageGroup messageGroup = messageStore.getMessageGroup(delayerMessageGroupId);
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());
int n = 0;
while (n++ < 200 && messageStore.messageGroupSize(delayerMessageGroupId) > 0) {
Thread.sleep(100);
}
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
context.close();
}
use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class AbstractMongoDbMessageGroupStoreTests method testRemoveMessageGroup.
@Test
@MongoDbAvailable
public void testRemoveMessageGroup() throws Exception {
this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageGroupStore store = this.getMessageGroupStore();
MessageStore messageStore = this.getMessageStore();
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> message = new GenericMessage<String>("Hello");
UUID id = message.getHeaders().getId();
messageGroup = store.addMessageToGroup(1, message);
assertNotNull(messageGroup);
assertEquals(1, messageGroup.size());
message = messageStore.getMessage(id);
assertNotNull(message);
store.removeMessageGroup(1);
MessageGroup messageGroupA = store.getMessageGroup(1);
assertEquals(0, messageGroupA.size());
assertFalse(messageGroupA.equals(messageGroup));
}
use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class AbstractMongoDbMessageGroupStoreTests method testMessageGroupIterator.
@Test
@MongoDbAvailable
public void testMessageGroupIterator() throws Exception {
this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageGroupStore store1 = this.getMessageGroupStore();
MessageGroupStore store2 = this.getMessageGroupStore();
Message<?> message = new GenericMessage<String>("1");
store2.addMessagesToGroup("1", message);
store1.addMessagesToGroup("2", new GenericMessage<String>("2"));
store2.addMessagesToGroup("3", new GenericMessage<String>("3"));
MessageGroupStore store3 = this.getMessageGroupStore();
Iterator<MessageGroup> iterator = store3.iterator();
assertNotNull(iterator);
int counter = 0;
while (iterator.hasNext()) {
iterator.next();
counter++;
}
assertEquals(3, counter);
store2.removeMessagesFromGroup("1", message);
iterator = store3.iterator();
counter = 0;
while (iterator.hasNext()) {
iterator.next();
counter++;
}
assertEquals(2, counter);
}
use of org.springframework.integration.store.MessageGroupStore in project spring-integration by spring-projects.
the class AbstractMongoDbMessageGroupStoreTests method testCompleteMessageGroup.
@Test
@MongoDbAvailable
public void testCompleteMessageGroup() throws Exception {
this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageGroupStore store = this.getMessageGroupStore();
MessageGroup messageGroup = store.getMessageGroup(1);
assertNotNull(messageGroup);
Message<?> message = new GenericMessage<String>("Hello");
store.addMessagesToGroup(messageGroup.getGroupId(), message);
store.completeGroup(messageGroup.getGroupId());
messageGroup = store.getMessageGroup(1);
assertTrue(messageGroup.isComplete());
}
Aggregations