Search in sources :

Example 21 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testSetWithMapKeyExpression.

@Test(expected = IllegalStateException.class)
@RedisAvailable
public void testSetWithMapKeyExpression() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    String key = "foo";
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
    handler.setKey(key);
    handler.setCollectionType(CollectionType.SET);
    handler.setMapKeyExpression(new LiteralExpression(key));
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
}
Also used : LiteralExpression(org.springframework.expression.common.LiteralExpression) BeanFactory(org.springframework.beans.factory.BeanFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 22 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testZsetWithListPayloadAsSingleEntryAndHeaderKeyHeaderScore.

@Test
@RedisAvailable
public void testZsetWithListPayloadAsSingleEntryAndHeaderKeyHeaderScore() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deleteKey(jcf, "foo");
    String key = "foo";
    RedisZSet<List<String>> redisZset = new DefaultRedisZSet<List<String>>(key, this.initTemplate(jcf, new RedisTemplate<String, List<String>>()));
    assertEquals(0, redisZset.size());
    RedisTemplate<String, List<String>> template = this.initTemplate(jcf, new RedisTemplate<String, List<String>>());
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(template);
    handler.setCollectionType(CollectionType.ZSET);
    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 = MessageBuilder.withPayload(list).setHeader("redis_key", key).setHeader("redis_zsetScore", 4).build();
    handler.handleMessage(message);
    assertEquals(1, redisZset.size());
    Set<TypedTuple<List<String>>> entries = redisZset.rangeByScoreWithScores(1, 4);
    for (TypedTuple<List<String>> pepboys : entries) {
        assertTrue(pepboys.getScore() == 4);
    }
    this.deleteKey(jcf, "foo");
}
Also used : DefaultRedisZSet(org.springframework.data.redis.support.collections.DefaultRedisZSet) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) ArrayList(java.util.ArrayList) 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 23 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testZsetWithListPayloadParsedAndProvidedKeyScoreIncrementAsStringHeader.

@Test
@RedisAvailable
public void testZsetWithListPayloadParsedAndProvidedKeyScoreIncrementAsStringHeader() {
    // see INT-2775
    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, "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 24 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testZsetWithMapPayloadParsedHeaderKey.

@Test
@RedisAvailable
public void testZsetWithMapPayloadParsedHeaderKey() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deletePresidents(jcf);
    String key = "presidents";
    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();
    Map<String, Double> presidents = new HashMap<String, Double>();
    presidents.put("John Adams", 18D);
    presidents.put("Barack Obama", 21D);
    presidents.put("Thomas Jefferson", 19D);
    presidents.put("John Quincy Adams", 19D);
    presidents.put("Zachary Taylor", 19D);
    presidents.put("Theodore Roosevelt", 20D);
    presidents.put("Woodrow Wilson", 20D);
    presidents.put("George W. Bush", 21D);
    presidents.put("Franklin D. Roosevelt", 20D);
    presidents.put("Ronald Reagan", 20D);
    presidents.put("William J. Clinton", 20D);
    presidents.put("Abraham Lincoln", 19D);
    presidents.put("George Washington", 18D);
    Message<Map<String, Double>> message = MessageBuilder.withPayload(presidents).setHeader("redis_key", key).build();
    handler.handleMessage(message);
    assertEquals(13, redisZset.size());
    Set<TypedTuple<String>> entries = redisZset.rangeByScoreWithScores(18, 19);
    assertEquals(6, entries.size());
    this.deletePresidents(jcf);
}
Also used : DefaultRedisZSet(org.springframework.data.redis.support.collections.DefaultRedisZSet) HashMap(java.util.HashMap) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) BeanFactory(org.springframework.beans.factory.BeanFactory) TypedTuple(org.springframework.data.redis.core.ZSetOperations.TypedTuple) HashMap(java.util.HashMap) Map(java.util.Map) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 25 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testZsetWithMapKeyExpression.

@Test(expected = IllegalStateException.class)
@RedisAvailable
public void testZsetWithMapKeyExpression() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    String key = "foo";
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
    handler.setKey(key);
    handler.setCollectionType(CollectionType.ZSET);
    handler.setMapKeyExpression(new LiteralExpression(key));
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
}
Also used : LiteralExpression(org.springframework.expression.common.LiteralExpression) BeanFactory(org.springframework.beans.factory.BeanFactory) 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)100 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 Properties (java.util.Properties)10 Message (org.springframework.messaging.Message)10 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