Search in sources :

Example 31 with MessageGroup

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());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 32 with MessageGroup

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());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 33 with MessageGroup

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);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) AssertionFailedError(junit.framework.AssertionFailedError) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 34 with MessageGroup

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());
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ArrayList(java.util.ArrayList) MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test)

Example 35 with MessageGroup

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());
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ArrayList(java.util.ArrayList) MessageGroupMetadata(org.springframework.integration.store.MessageGroupMetadata) MessageGroup(org.springframework.integration.store.MessageGroup) Test(org.junit.Test)

Aggregations

MessageGroup (org.springframework.integration.store.MessageGroup)98 Test (org.junit.Test)79 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)54 GenericMessage (org.springframework.messaging.support.GenericMessage)36 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)25 Message (org.springframework.messaging.Message)20 ArrayList (java.util.ArrayList)19 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)15 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)14 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)13 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)13 MongoClient (com.mongodb.MongoClient)12 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)12 Transactional (org.springframework.transaction.annotation.Transactional)10 LinkedList (java.util.LinkedList)8 List (java.util.List)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 UUID (java.util.UUID)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)6 HashMap (java.util.HashMap)5