Search in sources :

Example 31 with RedisAvailable

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

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

Example 33 with RedisAvailable

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

the class RedisStoreWritingMessageHandlerTests method testMapWithMapKeyExpression.

@Test
@RedisAvailable
public void testMapWithMapKeyExpression() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deleteKey(jcf, "foo");
    String key = "foo";
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
    handler.setKey(key);
    handler.setCollectionType(CollectionType.MAP);
    handler.setMapKeyExpression(new LiteralExpression(key));
    handler.setBeanFactory(mock(BeanFactory.class));
    try {
        handler.afterPropertiesSet();
    } catch (Exception e) {
        fail("No exception expected:" + e.getMessage());
    }
    this.deleteKey(jcf, "foo");
}
Also used : LiteralExpression(org.springframework.expression.common.LiteralExpression) BeanFactory(org.springframework.beans.factory.BeanFactory) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) MessageHandlingException(org.springframework.messaging.MessageHandlingException) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 34 with RedisAvailable

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

the class RedisStoreWritingMessageHandlerTests method testZsetWithMapPayloadPojoAsSingleEntryHeaderKey.

@Test
@RedisAvailable
public void testZsetWithMapPayloadPojoAsSingleEntryHeaderKey() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deletePresidents(jcf);
    String key = "presidents";
    RedisZSet<Map<President, Double>> redisZset = new DefaultRedisZSet<Map<President, Double>>(key, this.initTemplate(jcf, new RedisTemplate<String, Map<President, Double>>()));
    assertEquals(0, redisZset.size());
    RedisTemplate<String, Map<President, Double>> template = this.initTemplate(jcf, new RedisTemplate<String, Map<President, Double>>());
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(template);
    handler.setKey(key);
    handler.setCollectionType(CollectionType.ZSET);
    handler.setExtractPayloadElements(false);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    Map<President, Double> presidents = new HashMap<President, Double>();
    presidents.put(new President("John Adams"), 18D);
    presidents.put(new President("Barack Obama"), 21D);
    presidents.put(new President("Thomas Jefferson"), 19D);
    Message<Map<President, Double>> message = MessageBuilder.withPayload(presidents).setHeader("redis_key", key).build();
    handler.handleMessage(message);
    assertEquals(1, redisZset.size());
    this.deletePresidents(jcf);
}
Also used : DefaultRedisZSet(org.springframework.data.redis.support.collections.DefaultRedisZSet) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) HashMap(java.util.HashMap) BeanFactory(org.springframework.beans.factory.BeanFactory) 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 35 with RedisAvailable

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

the class RedisMessageGroupStoreTests method testRemoveNonExistingMessageFromNonExistingTheGroup.

@Test
@RedisAvailable
public void testRemoveNonExistingMessageFromNonExistingTheGroup() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    store.removeMessagesFromGroup(this.groupId, new GenericMessage<>("2"));
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) 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