Search in sources :

Example 16 with RedisAvailable

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

the class RedisStoreInboundChannelAdapterIntegrationTests method testListInboundConfigurationWithSynchronization.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public // synchronization commit renames the list
void testListInboundConfigurationWithSynchronization() 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("listAdapterWithSynchronization", 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)

Example 17 with RedisAvailable

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

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

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

the class RedisQueueMessageDrivenEndpointTests method testInt3932ReadFromLeft.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testInt3932ReadFromLeft() {
    String queueName = "si.test.redisQueueInboundChannelAdapterTests3932";
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(this.connectionFactory);
    redisTemplate.setEnableDefaultSerializer(false);
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
    redisTemplate.afterPropertiesSet();
    String payload = "testing";
    redisTemplate.boundListOps(queueName).rightPush(payload);
    Date payload2 = new Date();
    redisTemplate.boundListOps(queueName).rightPush(payload2);
    PollableChannel channel = new QueueChannel();
    RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory);
    endpoint.setBeanFactory(Mockito.mock(BeanFactory.class));
    endpoint.setOutputChannel(channel);
    endpoint.setReceiveTimeout(10);
    endpoint.setRightPop(false);
    endpoint.afterPropertiesSet();
    endpoint.start();
    Message<Object> receive = (Message<Object>) channel.receive(10000);
    assertNotNull(receive);
    assertEquals(payload, receive.getPayload());
    receive = (Message<Object>) channel.receive(10000);
    assertNotNull(receive);
    assertEquals(payload2, receive.getPayload());
    endpoint.stop();
}
Also used : StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) QueueChannel(org.springframework.integration.channel.QueueChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Message(org.springframework.messaging.Message) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) Date(java.util.Date) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) PollableChannel(org.springframework.messaging.PollableChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 20 with RedisAvailable

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

the class RedisQueueMessageDrivenEndpointTests method testInt3196Recovery.

@Test
@RedisAvailable
@Ignore("JedisConnectionFactory doesn't support proper 'destroy()' and allows to create new fresh Redis connection")
public void testInt3196Recovery() throws Exception {
    String queueName = "test.si.Int3196Recovery";
    QueueChannel channel = new QueueChannel();
    final List<ApplicationEvent> exceptionEvents = new ArrayList<>();
    final CountDownLatch exceptionsLatch = new CountDownLatch(2);
    RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory);
    endpoint.setBeanFactory(Mockito.mock(BeanFactory.class));
    endpoint.setApplicationEventPublisher(event -> {
        exceptionEvents.add((ApplicationEvent) event);
        exceptionsLatch.countDown();
    });
    endpoint.setOutputChannel(channel);
    endpoint.setReceiveTimeout(100);
    endpoint.setRecoveryInterval(200);
    endpoint.afterPropertiesSet();
    endpoint.start();
    waitListening(endpoint);
    ((DisposableBean) this.connectionFactory).destroy();
    assertTrue(exceptionsLatch.await(10, TimeUnit.SECONDS));
    for (ApplicationEvent exceptionEvent : exceptionEvents) {
        assertThat(exceptionEvent, Matchers.instanceOf(RedisExceptionEvent.class));
        assertSame(endpoint, exceptionEvent.getSource());
        assertThat(((IntegrationEvent) exceptionEvent).getCause().getClass(), Matchers.isIn(Arrays.asList(RedisSystemException.class, RedisConnectionFailureException.class)));
    }
    ((InitializingBean) this.connectionFactory).afterPropertiesSet();
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
    redisTemplate.setConnectionFactory(this.getConnectionFactoryForTest());
    redisTemplate.setEnableDefaultSerializer(false);
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
    redisTemplate.afterPropertiesSet();
    String payload = "testing";
    redisTemplate.boundListOps(queueName).leftPush(payload);
    Message<?> receive = channel.receive(10000);
    assertNotNull(receive);
    assertEquals(payload, receive.getPayload());
    endpoint.stop();
}
Also used : StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) QueueChannel(org.springframework.integration.channel.QueueChannel) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) ApplicationEvent(org.springframework.context.ApplicationEvent) ArrayList(java.util.ArrayList) RedisExceptionEvent(org.springframework.integration.redis.event.RedisExceptionEvent) CountDownLatch(java.util.concurrent.CountDownLatch) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) DisposableBean(org.springframework.beans.factory.DisposableBean) BeanFactory(org.springframework.beans.factory.BeanFactory) IntegrationEvent(org.springframework.integration.events.IntegrationEvent) InitializingBean(org.springframework.beans.factory.InitializingBean) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Ignore(org.junit.Ignore) 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