Search in sources :

Example 81 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testListWithListPayloadParsedAndProvidedKeyAsHeader.

@Test
@RedisAvailable
public void testListWithListPayloadParsedAndProvidedKeyAsHeader() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deleteKey(jcf, "foo");
    String key = "foo";
    RedisList<String> redisList = new DefaultRedisList<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
    assertEquals(0, redisList.size());
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    List<String> list = new ArrayList<String>();
    list.add("Manny");
    list.add("Moe");
    list.add("Jack");
    Message<List<String>> message = MessageBuilder.withPayload(list).setHeader("redis_key", key).build();
    handler.handleMessage(message);
    assertEquals(3, redisList.size());
    assertEquals("Manny", redisList.get(0));
    assertEquals("Moe", redisList.get(1));
    assertEquals("Jack", redisList.get(2));
    this.deleteKey(jcf, "foo");
}
Also used : DefaultRedisList(org.springframework.data.redis.support.collections.DefaultRedisList) BeanFactory(org.springframework.beans.factory.BeanFactory) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) DefaultRedisList(org.springframework.data.redis.support.collections.DefaultRedisList) List(java.util.List) RedisList(org.springframework.data.redis.support.collections.RedisList) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 82 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testListWithListPayloadParsedAndProvidedKey.

@Test
@RedisAvailable
public void testListWithListPayloadParsedAndProvidedKey() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deleteKey(jcf, "foo");
    String key = "foo";
    RedisList<String> redisList = new DefaultRedisList<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
    assertEquals(0, redisList.size());
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
    handler.setKey(key);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    List<String> list = new ArrayList<String>();
    list.add("Manny");
    list.add("Moe");
    list.add("Jack");
    Message<List<String>> message = new GenericMessage<List<String>>(list);
    handler.handleMessage(message);
    assertEquals(3, redisList.size());
    assertEquals("Manny", redisList.get(0));
    assertEquals("Moe", redisList.get(1));
    assertEquals("Jack", redisList.get(2));
    this.deleteKey(jcf, "foo");
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) DefaultRedisList(org.springframework.data.redis.support.collections.DefaultRedisList) BeanFactory(org.springframework.beans.factory.BeanFactory) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) DefaultRedisList(org.springframework.data.redis.support.collections.DefaultRedisList) List(java.util.List) RedisList(org.springframework.data.redis.support.collections.RedisList) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 83 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testListWithListPayloadAsSingleEntry.

@Test
@RedisAvailable
public void testListWithListPayloadAsSingleEntry() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deleteKey(jcf, "foo");
    String key = "foo";
    RedisList<List<String>> redisList = new DefaultRedisList<List<String>>(key, this.initTemplate(jcf, new RedisTemplate<String, List<String>>()));
    assertEquals(0, redisList.size());
    RedisTemplate<String, List<String>> template = this.initTemplate(jcf, new RedisTemplate<String, List<String>>());
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(template);
    handler.setKey(key);
    handler.setExtractPayloadElements(false);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    List<String> list = new ArrayList<String>();
    list.add("Manny");
    list.add("Moe");
    list.add("Jack");
    Message<List<String>> message = new GenericMessage<List<String>>(list);
    handler.handleMessage(message);
    assertEquals(1, redisList.size());
    List<String> resultList = redisList.get(0);
    assertEquals("Manny", resultList.get(0));
    assertEquals("Moe", resultList.get(1));
    assertEquals("Jack", resultList.get(2));
    this.deleteKey(jcf, "foo");
}
Also used : StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) DefaultRedisList(org.springframework.data.redis.support.collections.DefaultRedisList) ArrayList(java.util.ArrayList) GenericMessage(org.springframework.messaging.support.GenericMessage) BeanFactory(org.springframework.beans.factory.BeanFactory) ArrayList(java.util.ArrayList) DefaultRedisList(org.springframework.data.redis.support.collections.DefaultRedisList) List(java.util.List) RedisList(org.springframework.data.redis.support.collections.RedisList) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 84 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testZsetWithListPayloadParsedAndProvidedKeyScoreIncrement.

@Test
@RedisAvailable
public void testZsetWithListPayloadParsedAndProvidedKeyScoreIncrement() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deleteKey(jcf, "foo");
    String key = "foo";
    RedisZSet<String> redisZset = new DefaultRedisZSet<String>(key, this.initTemplate(jcf, new StringRedisTemplate()));
    assertEquals(0, redisZset.size());
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
    handler.setKey(key);
    handler.setCollectionType(CollectionType.ZSET);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    List<String> list = new ArrayList<String>();
    list.add("Manny");
    list.add("Moe");
    list.add("Jack");
    Message<List<String>> message = MessageBuilder.withPayload(list).setHeader(RedisHeaders.ZSET_INCREMENT_SCORE, Boolean.TRUE).build();
    handler.handleMessage(message);
    assertEquals(3, redisZset.size());
    Set<TypedTuple<String>> pepboys = redisZset.rangeByScoreWithScores(1, 1);
    for (TypedTuple<String> pepboy : pepboys) {
        assertTrue(pepboy.getScore() == 1);
    }
    handler.handleMessage(message);
    assertEquals(3, redisZset.size());
    pepboys = redisZset.rangeByScoreWithScores(1, 2);
    // should have incremented
    for (TypedTuple<String> pepboy : pepboys) {
        assertTrue(pepboy.getScore() == 2);
    }
    this.deleteKey(jcf, "foo");
}
Also used : DefaultRedisZSet(org.springframework.data.redis.support.collections.DefaultRedisZSet) ArrayList(java.util.ArrayList) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) BeanFactory(org.springframework.beans.factory.BeanFactory) ArrayList(java.util.ArrayList) DefaultRedisList(org.springframework.data.redis.support.collections.DefaultRedisList) List(java.util.List) RedisList(org.springframework.data.redis.support.collections.RedisList) TypedTuple(org.springframework.data.redis.core.ZSetOperations.TypedTuple) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 85 with RedisConnectionFactory

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

the class RedisMessageGroupStoreTests method testRemoveMessageGroup.

@Test
@RedisAvailable
public void testRemoveMessageGroup() {
    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);
    assertEquals(1, messageGroup.size());
    store.removeMessageGroup(this.groupId);
    MessageGroup messageGroupA = store.getMessageGroup(this.groupId);
    assertNotSame(messageGroup, messageGroupA);
    // assertEquals(0, messageGroupA.getMarked().size());
    assertEquals(0, messageGroupA.getMessages().size());
    assertEquals(0, messageGroupA.size());
    // make sure the store is properly rebuild from Redis
    store = new RedisMessageStore(jcf);
    messageGroup = store.getMessageGroup(this.groupId);
    assertEquals(0, messageGroup.getMessages().size());
    assertEquals(0, 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)

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