Search in sources :

Example 86 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testConcurrentModifications.

@Test
@RedisAvailable
@Ignore
public void testConcurrentModifications() throws Exception {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    final RedisMessageStore store1 = new RedisMessageStore(jcf);
    final RedisMessageStore store2 = new RedisMessageStore(jcf);
    store1.removeMessageGroup(this.groupId);
    final Message<?> message = new GenericMessage<>("1");
    ExecutorService executor = null;
    final List<Object> failures = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        executor = Executors.newCachedThreadPool();
        executor.execute(() -> {
            MessageGroup group = store1.addMessageToGroup(this.groupId, message);
            if (group.getMessages().size() != 1) {
                failures.add("ADD");
                throw new AssertionFailedError("Failed on ADD");
            }
        });
        executor.execute(() -> {
            store2.removeMessagesFromGroup(this.groupId, message);
            MessageGroup group = store2.getMessageGroup(this.groupId);
            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) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 87 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testLastReleasedSequenceNumber.

@Test
@RedisAvailable
public void testLastReleasedSequenceNumber() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    MessageGroup messageGroup = store.getMessageGroup(this.groupId);
    Message<?> message = new GenericMessage<>("Hello");
    messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), message);
    store.setLastReleasedSequenceNumberForGroup(messageGroup.getGroupId(), 5);
    messageGroup = store.getMessageGroup(this.groupId);
    assertEquals(5, messageGroup.getLastReleasedMessageSequenceNumber());
}
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 88 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testMessageGroupWithAddedMessage.

@Test
@RedisAvailable
public void testMessageGroupWithAddedMessage() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Message<?> message = new GenericMessage<>("Hello");
    MessageGroup messageGroup = store.addMessageToGroup(this.groupId, message);
    assertEquals(1, messageGroup.size());
    // make sure the store is properly rebuild from Redis
    store = new RedisMessageStore(jcf);
    messageGroup = store.getMessageGroup(this.groupId);
    assertEquals(1, 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 89 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testRemoveMessageFromTheGroup.

@Test
@RedisAvailable
public void testRemoveMessageFromTheGroup() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    MessageGroup messageGroup = store.getMessageGroup(this.groupId);
    Message<?> message = new GenericMessage<>("2");
    store.addMessagesToGroup(messageGroup.getGroupId(), new GenericMessage<>("1"), message);
    messageGroup = store.addMessageToGroup(messageGroup.getGroupId(), new GenericMessage<>("3"));
    assertEquals(3, messageGroup.size());
    store.removeMessagesFromGroup(this.groupId, message);
    messageGroup = store.getMessageGroup(this.groupId);
    assertEquals(2, messageGroup.size());
    // 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 90 with RedisConnectionFactory

use of org.springframework.data.redis.connection.RedisConnectionFactory in project spring-integration by spring-projects.

the class RedisMessageGroupStoreTests method testIteratorOfMessageGroups.

@Test
@RedisAvailable
public void testIteratorOfMessageGroups() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store1 = new RedisMessageStore(jcf);
    RedisMessageStore store2 = new RedisMessageStore(jcf);
    store1.removeMessageGroup(this.groupId);
    UUID group2 = UUID.randomUUID();
    store1.removeMessageGroup(group2);
    UUID group3 = UUID.randomUUID();
    store1.removeMessageGroup(group3);
    store1.addMessagesToGroup(this.groupId, new GenericMessage<>("1"));
    store2.addMessagesToGroup(group2, new GenericMessage<>("2"));
    store1.addMessagesToGroup(group3, new GenericMessage<>("3"), new GenericMessage<>("3A"));
    Iterator<MessageGroup> messageGroups = store1.iterator();
    int counter = 0;
    while (messageGroups.hasNext()) {
        MessageGroup group = messageGroups.next();
        String groupId = (String) group.getGroupId();
        if (groupId.equals("1")) {
            assertEquals(1, group.getMessages().size());
        } else if (groupId.equals("2")) {
            assertEquals(1, group.getMessages().size());
        } else if (groupId.equals("3")) {
            assertEquals(2, group.getMessages().size());
        }
        counter++;
    }
    assertEquals(3, counter);
    store2.removeMessageGroup(group3);
    messageGroups = store1.iterator();
    counter = 0;
    while (messageGroups.hasNext()) {
        messageGroups.next();
        counter++;
    }
    assertEquals(2, counter);
}
Also used : MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Matchers.containsString(org.hamcrest.Matchers.containsString) UUID(java.util.UUID) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)95 Test (org.junit.Test)83 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)62 GenericMessage (org.springframework.messaging.support.GenericMessage)22 BeanFactory (org.springframework.beans.factory.BeanFactory)19 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)17 MessageGroup (org.springframework.integration.store.MessageGroup)14 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)13 ArrayList (java.util.ArrayList)12 Message (org.springframework.messaging.Message)10 Properties (java.util.Properties)9 ApplicationContext (org.springframework.context.ApplicationContext)9 List (java.util.List)8 DefaultRedisList (org.springframework.data.redis.support.collections.DefaultRedisList)8 RedisList (org.springframework.data.redis.support.collections.RedisList)8 RedisConnection (org.springframework.data.redis.connection.RedisConnection)7 DefaultRedisZSet (org.springframework.data.redis.support.collections.DefaultRedisZSet)7 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)6 TypedTuple (org.springframework.data.redis.core.ZSetOperations.TypedTuple)6 LiteralExpression (org.springframework.expression.common.LiteralExpression)6