Search in sources :

Example 16 with RedisConnectionFactory

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

the class RedisMetadataStoreTests method testPersistKeyValue.

@Test
@RedisAvailable
public void testPersistKeyValue() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMetadataStore metadataStore = new RedisMetadataStore(jcf, "testMetadata");
    metadataStore.put("RedisMetadataStoreTests-Spring", "Integration");
    StringRedisTemplate redisTemplate = new StringRedisTemplate(jcf);
    BoundHashOperations<String, Object, Object> ops = redisTemplate.boundHashOps("testMetadata");
    assertEquals("Integration", ops.get("RedisMetadataStoreTests-Spring"));
}
Also used : 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 17 with RedisConnectionFactory

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

the class RedisMetadataStoreTests method testPersistNullStringToMetadataStore.

@Test
@RedisAvailable
public void testPersistNullStringToMetadataStore() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMetadataStore metadataStore = new RedisMetadataStore(jcf, "testMetadata");
    try {
        metadataStore.put("RedisMetadataStoreTests-PersistEmpty", null);
    } catch (IllegalArgumentException e) {
        assertEquals("'value' must not be null.", e.getMessage());
        return;
    }
    fail("Expected an IllegalArgumentException to be thrown.");
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 18 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testListWithListPayloadParsedAndNoKey.

@RedisAvailable
@Test(expected = MessageHandlingException.class)
public void testListWithListPayloadParsedAndNoKey() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deleteKey(jcf, "foo");
    String key = "foo";
    RedisList<String> redisList = new DefaultRedisList<String>(key, this.initTemplate(jcf, new RedisTemplate<String, String>()));
    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).build();
    handler.handleMessage(message);
    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) 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) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 19 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testZsetWithMapPayloadPojoParsedHeaderKey.

@Test
@RedisAvailable
public void testZsetWithMapPayloadPojoParsedHeaderKey() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deletePresidents(jcf);
    String key = "presidents";
    RedisZSet<President> redisZset = new DefaultRedisZSet<President>(key, this.initTemplate(jcf, new RedisTemplate<String, President>()));
    assertEquals(0, redisZset.size());
    RedisTemplate<String, President> template = this.initTemplate(jcf, new RedisTemplate<String, President>());
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(template);
    handler.setKey(key);
    handler.setCollectionType(CollectionType.ZSET);
    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);
    presidents.put(new President("John Quincy Adams"), 19D);
    presidents.put(new President("Zachary Taylor"), 19D);
    presidents.put(new President("Theodore Roosevelt"), 20D);
    presidents.put(new President("Woodrow Wilson"), 20D);
    presidents.put(new President("George W. Bush"), 21D);
    presidents.put(new President("Franklin D. Roosevelt"), 20D);
    presidents.put(new President("Ronald Reagan"), 20D);
    presidents.put(new President("William J. Clinton"), 20D);
    presidents.put(new President("Abraham Lincoln"), 19D);
    presidents.put(new President("George Washington"), 18D);
    Message<Map<President, Double>> message = MessageBuilder.withPayload(presidents).setHeader("redis_key", key).build();
    handler.handleMessage(message);
    assertEquals(13, redisZset.size());
    Set<TypedTuple<President>> entries = redisZset.rangeByScoreWithScores(18, 19);
    assertEquals(6, entries.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) 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 20 with RedisConnectionFactory

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

the class RedisStoreWritingMessageHandlerTests method testPropertiesWithMapKeyExpression.

@Test
@RedisAvailable
public void testPropertiesWithMapKeyExpression() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.deleteKey(jcf, "foo");
    String key = "foo";
    RedisStoreWritingMessageHandler handler = new RedisStoreWritingMessageHandler(jcf);
    handler.setKey(key);
    handler.setCollectionType(CollectionType.PROPERTIES);
    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)

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