Search in sources :

Example 26 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testMultipleInstancesOfGroupStore.

@Test
@RedisAvailable
public void testMultipleInstancesOfGroupStore() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store1 = new RedisMessageStore(jcf);
    RedisMessageStore store2 = new RedisMessageStore(jcf);
    store1.removeMessageGroup(this.groupId);
    Message<?> message = new GenericMessage<>("1");
    store1.addMessagesToGroup(this.groupId, message);
    MessageGroup messageGroup = store2.addMessageToGroup(this.groupId, new GenericMessage<>("2"));
    assertEquals(2, messageGroup.getMessages().size());
    RedisMessageStore store3 = new RedisMessageStore(jcf);
    store3.removeMessagesFromGroup(this.groupId, message);
    messageGroup = store3.getMessageGroup(this.groupId);
    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) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 27 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testNonExistingEmptyMessageGroup.

@Test
@RedisAvailable
public void testNonExistingEmptyMessageGroup() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    MessageGroup messageGroup = store.getMessageGroup(this.groupId);
    assertNotNull(messageGroup);
    assertTrue(messageGroup instanceof SimpleMessageGroup);
    assertEquals(0, messageGroup.size());
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 28 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testMessageGroupUpdatedDateChangesWithEachAddedMessage.

@Test
@RedisAvailable
public void testMessageGroupUpdatedDateChangesWithEachAddedMessage() throws Exception {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Message<?> message = new GenericMessage<>("Hello");
    MessageGroup messageGroup = store.addMessageToGroup(this.groupId, message);
    assertEquals(1, messageGroup.size());
    long createdTimestamp = messageGroup.getTimestamp();
    long updatedTimestamp = messageGroup.getLastModified();
    assertEquals(createdTimestamp, updatedTimestamp);
    Thread.sleep(10);
    message = new GenericMessage<>("Hello");
    messageGroup = store.addMessageToGroup(this.groupId, message);
    createdTimestamp = messageGroup.getTimestamp();
    updatedTimestamp = messageGroup.getLastModified();
    assertTrue(updatedTimestamp > createdTimestamp);
    // make sure the store is properly rebuild from Redis
    store = new RedisMessageStore(jcf);
    messageGroup = store.getMessageGroup(this.groupId);
    assertEquals(2, messageGroup.size());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 29 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testRemoveNonExistingMessageFromTheGroup.

@Test
@RedisAvailable
public void testRemoveNonExistingMessageFromTheGroup() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    MessageGroup messageGroup = store.getMessageGroup(this.groupId);
    store.addMessagesToGroup(messageGroup.getGroupId(), new GenericMessage<>("1"));
    store.removeMessagesFromGroup(this.groupId, new GenericMessage<>("2"));
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 30 with MessageGroup

use of org.springframework.integration.store.MessageGroup in project spring-integration by spring-projects.

the class GemfireGroupStoreTests method testRemoveMessageFromTheGroup.

@Test
public void testRemoveMessageFromTheGroup() throws Exception {
    GemfireMessageStore store = new GemfireMessageStore(region);
    MessageGroup messageGroup = store.getMessageGroup(1);
    Message<?> message = new GenericMessage<String>("2");
    messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), new GenericMessage<String>("1"));
    messageGroup = store.getMessageGroup(1);
    assertEquals(1, messageGroup.size());
    // since it adds to a local region some times CREATED_DATE ends up to be the same
    Thread.sleep(1);
    // Unrealistic in a real scenario
    messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
    messageGroup = store.getMessageGroup(1);
    assertEquals(2, messageGroup.size());
    Thread.sleep(1);
    messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), new GenericMessage<String>("3"));
    messageGroup = store.getMessageGroup(1);
    assertEquals(3, messageGroup.size());
    store.removeMessagesFromGroup(messageGroup.getGroupId(), message);
    messageGroup = store.getMessageGroup(1);
    assertEquals(2, messageGroup.size());
    // make sure the store is properly rebuild from Gemfire
    store = new GemfireMessageStore(region);
    messageGroup = store.getMessageGroup(1);
    assertEquals(2, 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)

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