Search in sources :

Example 66 with RedisConnectionFactory

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

the class RedisMetadataStoreTests method testGetValueFromMetadataStore.

@Test
@RedisAvailable
public void testGetValueFromMetadataStore() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMetadataStore metadataStore = new RedisMetadataStore(jcf, "testMetadata");
    metadataStore.put("RedisMetadataStoreTests-GetValue", "Hello Redis");
    String retrievedValue = metadataStore.get("RedisMetadataStoreTests-GetValue");
    assertEquals("Hello Redis", retrievedValue);
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 67 with RedisConnectionFactory

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

the class RedisMetadataStoreTests method testGetValueWithNullKeyFromMetadataStore.

@Test
@RedisAvailable
public void testGetValueWithNullKeyFromMetadataStore() {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMetadataStore metadataStore = new RedisMetadataStore(jcf, "testMetadata");
    try {
        metadataStore.get(null);
    } catch (IllegalArgumentException e) {
        assertEquals("'key' 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 68 with RedisConnectionFactory

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

the class RedisPublishingMessageHandlerTests method testRedisPublishingMessageHandler.

@Test
@RedisAvailable
public void testRedisPublishingMessageHandler() throws Exception {
    int numToTest = 10;
    String topic = "si.test.channel";
    final CountDownLatch latch = new CountDownLatch(numToTest * 2);
    RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
    MessageListenerAdapter listener = new MessageListenerAdapter();
    listener.setDelegate(new Listener(latch));
    listener.setSerializer(new StringRedisSerializer());
    listener.afterPropertiesSet();
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.afterPropertiesSet();
    container.addMessageListener(listener, Collections.<Topic>singletonList(new ChannelTopic(topic)));
    container.start();
    this.awaitContainerSubscribed(container);
    final RedisPublishingMessageHandler handler = new RedisPublishingMessageHandler(connectionFactory);
    handler.setTopicExpression(new LiteralExpression(topic));
    for (int i = 0; i < numToTest; i++) {
        handler.handleMessage(MessageBuilder.withPayload("test-" + i).build());
    }
    for (int i = 0; i < numToTest; i++) {
        handler.handleMessage(MessageBuilder.withPayload(("test-" + i).getBytes()).build());
    }
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    container.stop();
}
Also used : MessageListenerAdapter(org.springframework.data.redis.listener.adapter.MessageListenerAdapter) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) ChannelTopic(org.springframework.data.redis.listener.ChannelTopic) LiteralExpression(org.springframework.expression.common.LiteralExpression) RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) CountDownLatch(java.util.concurrent.CountDownLatch) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 69 with RedisConnectionFactory

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

the class RedisStoreOutboundChannelAdapterIntegrationTests method setup.

@Before
@After
public void setup() {
    RedisConnectionFactory jcf = getConnectionFactoryForTest();
    this.redisTemplate.setConnectionFactory(jcf);
    this.redisTemplate.afterPropertiesSet();
    this.redisTemplate.delete("pepboys");
    this.redisTemplate.delete("foo");
    this.redisTemplate.delete("bar");
    this.redisTemplate.delete("presidents");
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) Before(org.junit.Before) After(org.junit.After)

Example 70 with RedisConnectionFactory

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

the class RedisAvailableTests method getConnectionFactoryForTest.

protected RedisConnectionFactory getConnectionFactoryForTest() {
    if (this.connectionFactory != null) {
        return this.connectionFactory;
    }
    RedisConnectionFactory connectionFactory = RedisAvailableRule.connectionFactoryResource.get();
    this.connectionFactory = connectionFactory;
    return connectionFactory;
}
Also used : RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory)

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