Search in sources :

Example 1 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer in project spring-integration by spring-projects.

the class RedisStoreOutboundChannelAdapterParserTests method validateWithStringObjectTemplate.

@Test
public void validateWithStringObjectTemplate() {
    RedisStoreWritingMessageHandler withStringObjectTemplate = TestUtils.getPropertyValue(context.getBean("withStringObjectTemplate.adapter"), "handler", RedisStoreWritingMessageHandler.class);
    assertEquals("pepboys", ((LiteralExpression) TestUtils.getPropertyValue(withStringObjectTemplate, "keyExpression")).getExpressionString());
    assertEquals("PROPERTIES", (TestUtils.getPropertyValue(withStringObjectTemplate, "collectionType")).toString());
    assertFalse(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate") instanceof StringRedisTemplate);
    assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.keySerializer") instanceof StringRedisSerializer);
    assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.hashKeySerializer") instanceof StringRedisSerializer);
    assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.valueSerializer") instanceof JdkSerializationRedisSerializer);
    assertTrue(TestUtils.getPropertyValue(withStringObjectTemplate, "redisTemplate.hashValueSerializer") instanceof JdkSerializationRedisSerializer);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisStoreWritingMessageHandler(org.springframework.integration.redis.outbound.RedisStoreWritingMessageHandler) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) Test(org.junit.Test)

Example 2 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer 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 3 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer 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)

Example 4 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer in project spring-integration by spring-projects.

the class RedisQueueOutboundChannelAdapterTests method testInt3932LeftPushFalse.

@Test
@RedisAvailable
public void testInt3932LeftPushFalse() throws Exception {
    final String queueName = "si.test.Int3932LeftPushFalse";
    final RedisQueueOutboundChannelAdapter handler = new RedisQueueOutboundChannelAdapter(queueName, this.connectionFactory);
    handler.setLeftPush(false);
    String payload = "testing";
    handler.handleMessage(MessageBuilder.withPayload(payload).build());
    Date payload2 = new Date();
    handler.handleMessage(MessageBuilder.withPayload(payload2).build());
    RedisTemplate<String, ?> redisTemplate = new StringRedisTemplate();
    redisTemplate.setConnectionFactory(this.connectionFactory);
    redisTemplate.afterPropertiesSet();
    Object result = redisTemplate.boundListOps(queueName).leftPop(5000, TimeUnit.MILLISECONDS);
    assertNotNull(result);
    assertEquals(payload, result);
    RedisTemplate<String, ?> redisTemplate2 = new RedisTemplate<String, Object>();
    redisTemplate2.setConnectionFactory(this.connectionFactory);
    redisTemplate2.setEnableDefaultSerializer(false);
    redisTemplate2.setKeySerializer(new StringRedisSerializer());
    redisTemplate2.setValueSerializer(new JdkSerializationRedisSerializer());
    redisTemplate2.afterPropertiesSet();
    Object result2 = redisTemplate2.boundListOps(queueName).leftPop(5000, TimeUnit.MILLISECONDS);
    assertNotNull(result2);
    assertEquals(payload2, result2);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) Date(java.util.Date) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 5 with JdkSerializationRedisSerializer

use of org.springframework.data.redis.serializer.JdkSerializationRedisSerializer in project spring-integration by spring-projects.

the class RedisQueueOutboundChannelAdapterTests method testInt3015ExtractPayloadFalse.

@Test
@RedisAvailable
public void testInt3015ExtractPayloadFalse() throws Exception {
    final String queueName = "si.test.testRedisQueueOutboundChannelAdapter2";
    final RedisQueueOutboundChannelAdapter handler = new RedisQueueOutboundChannelAdapter(queueName, this.connectionFactory);
    handler.setExtractPayload(false);
    Message<String> message = MessageBuilder.withPayload("testing").build();
    handler.handleMessage(message);
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
    redisTemplate.setConnectionFactory(this.connectionFactory);
    redisTemplate.setEnableDefaultSerializer(false);
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
    redisTemplate.afterPropertiesSet();
    Object result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
    assertNotNull(result);
    assertEquals(message, result);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

JdkSerializationRedisSerializer (org.springframework.data.redis.serializer.JdkSerializationRedisSerializer)18 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)14 Test (org.junit.Test)12 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)11 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)11 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)9 BeanFactory (org.springframework.beans.factory.BeanFactory)5 Date (java.util.Date)4 Bean (org.springframework.context.annotation.Bean)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 Message (org.springframework.messaging.Message)3 PollableChannel (org.springframework.messaging.PollableChannel)3 ErrorMessage (org.springframework.messaging.support.ErrorMessage)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ReactiveRedisTemplate (org.springframework.data.redis.core.ReactiveRedisTemplate)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 lombok.val (lombok.val)1 Ignore (org.junit.Ignore)1