use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class GemfireGroupStoreTests method testMultipleInstancesOfGroupStore.
@Test
public void testMultipleInstancesOfGroupStore() throws Exception {
GemfireMessageStore store1 = new GemfireMessageStore(region);
GemfireMessageStore store2 = new GemfireMessageStore(region);
Message<?> message = new GenericMessage<String>("1");
store1.addMessagesToGroup(1, message);
MessageGroup messageGroup = store2.addMessageToGroup(1, new GenericMessage<String>("2"));
assertEquals(2, messageGroup.getMessages().size());
GemfireMessageStore store3 = new GemfireMessageStore(region);
store3.removeMessagesFromGroup(1, message);
messageGroup = store3.getMessageGroup(1);
assertEquals(1, messageGroup.getMessages().size());
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class GemfireGroupStoreTests method testMessageGroupWithAddedMessage.
@Test
public void testMessageGroupWithAddedMessage() throws Exception {
GemfireMessageStore store = new GemfireMessageStore(region);
MessageGroup messageGroup = store.getMessageGroup(1);
Message<?> message = new GenericMessage<String>("Hello");
messageGroup = store.addMessageToGroup(1, message);
assertEquals(1, messageGroup.size());
// make sure the store is properly rebuild from Gemfire
store = new GemfireMessageStore(region);
messageGroup = store.getMessageGroup(1);
assertEquals(1, messageGroup.size());
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class GemfireGroupStoreTests method testConcurrentModifications.
@Test
@Ignore
public void testConcurrentModifications() throws Exception {
final GemfireMessageStore store1 = new GemfireMessageStore(region);
final GemfireMessageStore store2 = new GemfireMessageStore(region);
final Message<?> message = new GenericMessage<String>("1");
ExecutorService executor = null;
final List<Object> failures = new ArrayList<Object>();
for (int i = 0; i < 100; i++) {
executor = Executors.newCachedThreadPool();
executor.execute(() -> {
MessageGroup group = store1.addMessageToGroup(1, message);
if (group.getMessages().size() != 1) {
failures.add("ADD");
throw new AssertionFailedError("Failed on ADD");
}
});
executor.execute(() -> {
store2.removeMessagesFromGroup(1, message);
MessageGroup group = store2.getMessageGroup(1);
if (group.getMessages().size() != 0) {
failures.add("REMOVE");
throw new AssertionFailedError("Failed on Remove");
}
});
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
// ensures that if ADD thread executed after REMOVE, the store is empty for the next cycle
store2.removeMessagesFromGroup(1, message);
}
assertTrue(failures.size() == 0);
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class GemfireMessageStoreTests method testAddAndRemoveMessagesFromMessageGroup.
@Test
public void testAddAndRemoveMessagesFromMessageGroup() throws Exception {
GemfireMessageStore messageStore = new GemfireMessageStore(region);
String groupId = "X";
List<Message<?>> messages = new ArrayList<Message<?>>();
for (int i = 0; i < 25; i++) {
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessagesToGroup(groupId, message);
messages.add(message);
}
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(25, group.size());
messageStore.removeMessagesFromGroup(groupId, messages);
group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
}
use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.
the class GemfireMessageStoreTests method testAddAndRemoveMessagesFromMessageGroupWithPrefix.
@Test
public void testAddAndRemoveMessagesFromMessageGroupWithPrefix() throws Exception {
GemfireMessageStore messageStore = new GemfireMessageStore(region, "foo_");
String groupId = "X";
List<Message<?>> messages = new ArrayList<Message<?>>();
for (int i = 0; i < 25; i++) {
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessagesToGroup(groupId, message);
messages.add(message);
}
MessageGroupMetadata messageGroupMetadata = (MessageGroupMetadata) region.get("foo_" + "MESSAGE_GROUP_" + groupId);
assertNotNull(messageGroupMetadata);
assertEquals(25, messageGroupMetadata.size());
messageStore.removeMessagesFromGroup(groupId, messages);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
}
Aggregations