Search in sources :

Example 61 with RedisAvailable

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

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

the class RedisStoreOutboundChannelAdapterIntegrationTests method testPropertiesSimple.

@Test
@RedisAvailable
public void testPropertiesSimple() {
    RedisProperties redisProperties = new RedisProperties("foo", this.redisTemplate);
    assertEquals(0, redisProperties.size());
    Message<String> message = MessageBuilder.withPayload("bar").setHeader(RedisHeaders.KEY, "foo").setHeader("baz", "qux").build();
    this.simplePropertyChannel.send(message);
    assertEquals("bar", redisProperties.get("qux"));
}
Also used : RedisProperties(org.springframework.data.redis.support.collections.RedisProperties) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 63 with RedisAvailable

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

the class RedisStoreOutboundChannelAdapterIntegrationTests method testMapToMapAsSingleEntryWithKeyAsHeader.

@Test
@RedisAvailable
public void testMapToMapAsSingleEntryWithKeyAsHeader() {
    RedisTemplate<String, Map<String, Map<String, String>>> redisTemplate = new RedisTemplate<String, Map<String, Map<String, String>>>();
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setHashKeySerializer(new StringRedisSerializer());
    redisTemplate.setConnectionFactory(getConnectionFactoryForTest());
    redisTemplate.afterPropertiesSet();
    RedisMap<String, Map<String, String>> redisMap = new DefaultRedisMap<String, Map<String, String>>("pepboys", redisTemplate);
    assertEquals(0, redisMap.size());
    Map<String, String> pepboys = new HashMap<String, String>();
    pepboys.put("1", "Manny");
    pepboys.put("2", "Moe");
    pepboys.put("3", "Jack");
    Message<Map<String, String>> message = MessageBuilder.withPayload(pepboys).setHeader(RedisHeaders.KEY, "pepboys").setHeader(RedisHeaders.MAP_KEY, "foo").build();
    this.mapToMapBChannel.send(message);
    Map<String, String> pepboyz = redisMap.get("foo");
    assertEquals("Manny", pepboyz.get("1"));
    assertEquals("Moe", pepboyz.get("2"));
    assertEquals("Jack", pepboyz.get("3"));
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) HashMap(java.util.HashMap) DefaultRedisMap(org.springframework.data.redis.support.collections.DefaultRedisMap) HashMap(java.util.HashMap) Map(java.util.Map) RedisMap(org.springframework.data.redis.support.collections.RedisMap) DefaultRedisMap(org.springframework.data.redis.support.collections.DefaultRedisMap) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 64 with RedisAvailable

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

the class RedisStoreOutboundChannelAdapterIntegrationTests method testProperties.

@Test
@RedisAvailable
public void testProperties() {
    RedisProperties redisProperties = new RedisProperties("pepboys", this.redisTemplate);
    assertEquals(0, redisProperties.size());
    Properties pepboys = new Properties();
    pepboys.put("1", "Manny");
    pepboys.put("2", "Moe");
    pepboys.put("3", "Jack");
    Message<Properties> message = MessageBuilder.withPayload(pepboys).build();
    this.propertyChannel.send(message);
    assertEquals("Manny", redisProperties.get("1"));
    assertEquals("Moe", redisProperties.get("2"));
    assertEquals("Jack", redisProperties.get("3"));
}
Also used : RedisProperties(org.springframework.data.redis.support.collections.RedisProperties) RedisProperties(org.springframework.data.redis.support.collections.RedisProperties) Properties(java.util.Properties) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 65 with RedisAvailable

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

the class RedisMessageStoreTests method testAddAndRemoveMessagesFromMessageGroup.

@Test
@RedisAvailable
public void testAddAndRemoveMessagesFromMessageGroup() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore messageStore = new RedisMessageStore(jcf);
    String groupId = "X";
    List<Message<?>> messages = new ArrayList<Message<?>>();
    for (int i = 0; i < 25; i++) {
        Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
        messageStore.addMessagesToGroup(groupId, message);
        messages.add(message);
    }
    messageStore.removeMessagesFromGroup(groupId, messages);
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(0, group.size());
    messageStore.removeMessageGroup("X");
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ArrayList(java.util.ArrayList) MessageGroup(org.springframework.integration.store.MessageGroup) 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