Search in sources :

Example 41 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable 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 42 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable 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 43 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable 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 44 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable 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 45 with RedisAvailable

use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.

the class RedisLockRegistryTests method testExpireTwoRegistries.

@Test
@RedisAvailable
public void testExpireTwoRegistries() throws Exception {
    RedisLockRegistry registry1 = new RedisLockRegistry(this.getConnectionFactoryForTest(), this.registryKey, 100);
    RedisLockRegistry registry2 = new RedisLockRegistry(this.getConnectionFactoryForTest(), this.registryKey, 100);
    Lock lock1 = registry1.obtain("foo");
    Lock lock2 = registry2.obtain("foo");
    assertTrue(lock1.tryLock());
    assertFalse(lock2.tryLock());
    waitForExpire("foo");
    assertTrue(lock2.tryLock());
    assertFalse(lock1.tryLock());
}
Also used : Lock(java.util.concurrent.locks.Lock) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)99 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)99 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)62 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)28 GenericMessage (org.springframework.messaging.support.GenericMessage)24 BeanFactory (org.springframework.beans.factory.BeanFactory)23 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)16 MessageGroup (org.springframework.integration.store.MessageGroup)15 ArrayList (java.util.ArrayList)14 Lock (java.util.concurrent.locks.Lock)13 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)13 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)13 Message (org.springframework.messaging.Message)13 QueueChannel (org.springframework.integration.channel.QueueChannel)12 CountDownLatch (java.util.concurrent.CountDownLatch)11 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)9 JdkSerializationRedisSerializer (org.springframework.data.redis.serializer.JdkSerializationRedisSerializer)9 List (java.util.List)8 DefaultRedisList (org.springframework.data.redis.support.collections.DefaultRedisList)8 RedisList (org.springframework.data.redis.support.collections.RedisList)8