Search in sources :

Example 11 with RedisAvailable

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

the class RedisChannelParserTests method testPubSubChannelUsage.

@Test
@RedisAvailable
public void testPubSubChannelUsage() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("RedisChannelParserTests-context.xml", this.getClass());
    SubscribableChannel redisChannel = context.getBean("redisChannel", SubscribableChannel.class);
    this.awaitContainerSubscribed(TestUtils.getPropertyValue(redisChannel, "container", RedisMessageListenerContainer.class));
    final Message<?> m = new GenericMessage<String>("Hello Redis");
    final CountDownLatch latch = new CountDownLatch(1);
    redisChannel.subscribe(message -> {
        assertEquals(m.getPayload(), message.getPayload());
        latch.countDown();
    });
    redisChannel.send(m);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    context.close();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) CountDownLatch(java.util.concurrent.CountDownLatch) SubscribableChannel(org.springframework.messaging.SubscribableChannel) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 12 with RedisAvailable

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

the class RedisOutboundChannelAdapterParserTests method testOutboundChannelAdapterWithinChain.

// INT-2275
@Test
@RedisAvailable
public void testOutboundChannelAdapterWithinChain() throws Exception {
    MessageChannel sendChannel = context.getBean("redisOutboudChain", MessageChannel.class);
    this.awaitContainerSubscribed(TestUtils.getPropertyValue(fooInbound, "container", RedisMessageListenerContainer.class));
    sendChannel.send(new GenericMessage<String>("Hello Redis from chain"));
    QueueChannel receiveChannel = context.getBean("receiveChannel", QueueChannel.class);
    Message<?> message = receiveChannel.receive(5000);
    assertNotNull(message);
    assertEquals("Hello Redis from chain", message.getPayload());
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 13 with RedisAvailable

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

the class RedisOutboundChannelAdapterParserTests method testOutboundChannelAdapterMessaging.

@Test
@RedisAvailable
public void testOutboundChannelAdapterMessaging() throws Exception {
    MessageChannel sendChannel = context.getBean("sendChannel", MessageChannel.class);
    this.awaitContainerSubscribed(TestUtils.getPropertyValue(fooInbound, "container", RedisMessageListenerContainer.class));
    sendChannel.send(new GenericMessage<String>("Hello Redis"));
    QueueChannel receiveChannel = context.getBean("receiveChannel", QueueChannel.class);
    Message<?> message = receiveChannel.receive(5000);
    assertNotNull(message);
    assertEquals("Hello Redis", message.getPayload());
    sendChannel = context.getBean("sendChannel", MessageChannel.class);
    sendChannel.send(MessageBuilder.withPayload("Hello Redis").setHeader("topic", "bar").build());
    receiveChannel = context.getBean("barChannel", QueueChannel.class);
    message = receiveChannel.receive(5000);
    assertNotNull(message);
    assertEquals("Hello Redis", message.getPayload());
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 14 with RedisAvailable

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

the class RedisStoreInboundChannelAdapterIntegrationTests method testZsetInboundAdapter.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testZsetInboundAdapter() throws InterruptedException {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    this.prepareZset(jcf);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("zset-inbound-adapter.xml", this.getClass());
    // No Score test
    SourcePollingChannelAdapter zsetAdapterNoScore = context.getBean("zsetAdapterNoScore", SourcePollingChannelAdapter.class);
    zsetAdapterNoScore.start();
    QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
    Message<RedisZSet<Object>> message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(13, message.getPayload().size());
    // poll again, should get the same stuff
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(13, message.getPayload().size());
    zsetAdapterNoScore.stop();
    // ScoreRange test
    SourcePollingChannelAdapter zsetAdapterWithScoreRange = context.getBean("zsetAdapterWithScoreRange", SourcePollingChannelAdapter.class);
    zsetAdapterWithScoreRange.start();
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(11, message.getPayload().rangeByScore(18, 20).size());
    // poll again, should get the same stuff
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(11, message.getPayload().rangeByScore(18, 20).size());
    zsetAdapterWithScoreRange.stop();
    // SingleScore test
    SourcePollingChannelAdapter zsetAdapterWithSingleScore = context.getBean("zsetAdapterWithSingleScore", SourcePollingChannelAdapter.class);
    zsetAdapterWithSingleScore.start();
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(2, message.getPayload().rangeByScore(18, 18).size());
    // poll again, should get the same stuff
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(2, message.getPayload().rangeByScore(18, 18).size());
    zsetAdapterWithSingleScore.stop();
    // SingleScoreAndSynchronization test
    SourcePollingChannelAdapter zsetAdapterWithSingleScoreAndSynchronization = context.getBean("zsetAdapterWithSingleScoreAndSynchronization", SourcePollingChannelAdapter.class);
    QueueChannel otherRedisChannel = context.getBean("otherRedisChannel", QueueChannel.class);
    // get all 13 presidents
    zsetAdapterNoScore.start();
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(13, message.getPayload().size());
    zsetAdapterNoScore.stop();
    // get only presidents for 18th century
    zsetAdapterWithSingleScoreAndSynchronization.start();
    Message<Integer> sizeMessage = (Message<Integer>) otherRedisChannel.receive(10000);
    assertNotNull(sizeMessage);
    assertEquals(Integer.valueOf(2), sizeMessage.getPayload());
    // ... however other elements are still available 13-2=11
    zsetAdapterNoScore.start();
    message = (Message<RedisZSet<Object>>) redisChannel.receive(10000);
    assertNotNull(message);
    int n = 0;
    while (n++ < 100 && message.getPayload().size() != 11) {
        Thread.sleep(100);
    }
    assertTrue(n < 100);
    zsetAdapterNoScore.stop();
    zsetAdapterWithSingleScoreAndSynchronization.stop();
    this.deletePresidents(jcf);
    context.close();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisZSet(org.springframework.data.redis.support.collections.RedisZSet) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 15 with RedisAvailable

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

the class RedisStoreInboundChannelAdapterIntegrationTests method testListInboundConfigurationWithSynchronizationAndTemplate.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public // synchronization commit renames the list
void testListInboundConfigurationWithSynchronizationAndTemplate() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    StringRedisTemplate template = this.createStringRedisTemplate(jcf);
    template.delete("bar");
    this.prepareList(jcf);
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("list-inbound-adapter.xml", this.getClass());
    SourcePollingChannelAdapter spca = context.getBean("listAdapterWithSynchronizationAndRedisTemplate", SourcePollingChannelAdapter.class);
    spca.start();
    QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class);
    Message<Integer> message = (Message<Integer>) redisChannel.receive(10000);
    assertNotNull(message);
    assertEquals(Integer.valueOf(13), message.getPayload());
    // poll again, should get nothing since the collection was removed during synchronization
    message = (Message<Integer>) redisChannel.receive(100);
    assertNull(message);
    int n = 0;
    while (n++ < 100 && template.keys("bar").size() == 0) {
        Thread.sleep(100);
    }
    assertTrue("Rename didn't occur", n < 100);
    assertEquals(Long.valueOf(13), template.boundListOps("bar").size());
    template.delete("bar");
    spca.stop();
    context.close();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) 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)

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