Search in sources :

Example 76 with RedisAvailable

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

the class RedisQueueMessageDrivenEndpointTests method testInt3014ExpectMessageTrue.

@Test
@RedisAvailable
@SuppressWarnings("unchecked")
public void testInt3014ExpectMessageTrue() {
    final String queueName = "si.test.redisQueueInboundChannelAdapterTests2";
    RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(this.connectionFactory);
    redisTemplate.setEnableDefaultSerializer(false);
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
    redisTemplate.afterPropertiesSet();
    Message<?> message = MessageBuilder.withPayload("testing").build();
    redisTemplate.boundListOps(queueName).leftPush(message);
    redisTemplate.boundListOps(queueName).leftPush("test");
    PollableChannel channel = new QueueChannel();
    PollableChannel errorChannel = new QueueChannel();
    RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory);
    endpoint.setBeanFactory(Mockito.mock(BeanFactory.class));
    endpoint.setExpectMessage(true);
    endpoint.setOutputChannel(channel);
    endpoint.setErrorChannel(errorChannel);
    endpoint.setReceiveTimeout(10);
    endpoint.afterPropertiesSet();
    endpoint.start();
    Message<Object> receive = (Message<Object>) channel.receive(10000);
    assertNotNull(receive);
    assertEquals(message, receive);
    receive = (Message<Object>) errorChannel.receive(10000);
    assertNotNull(receive);
    assertThat(receive, Matchers.instanceOf(ErrorMessage.class));
    assertThat(receive.getPayload(), Matchers.instanceOf(MessagingException.class));
    assertThat(((Exception) receive.getPayload()).getMessage(), Matchers.containsString("Deserialization of Message failed."));
    assertThat(((Exception) receive.getPayload()).getCause(), Matchers.instanceOf(ClassCastException.class));
    assertThat(((Exception) receive.getPayload()).getCause().getMessage(), Matchers.containsString("java.lang.String cannot be cast to org.springframework.messaging.Message"));
    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) MessagingException(org.springframework.messaging.MessagingException) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) RedisSystemException(org.springframework.data.redis.RedisSystemException) RedisConnectionFailureException(org.springframework.data.redis.RedisConnectionFailureException) MessagingException(org.springframework.messaging.MessagingException) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) PollableChannel(org.springframework.messaging.PollableChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) ErrorMessage(org.springframework.messaging.support.ErrorMessage) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 77 with RedisAvailable

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

the class RedisQueueMessageDrivenEndpointTests method testInt3017IntegrationSymmetrical.

@Test
@RedisAvailable
public void testInt3017IntegrationSymmetrical() {
    UUID payload = UUID.randomUUID();
    Message<UUID> message = MessageBuilder.withPayload(payload).setHeader("redis_queue", "si.test.Int3017IntegrationSymmetrical").build();
    this.symmetricalInputChannel.send(message);
    Message<?> receive = this.symmetricalOutputChannel.receive(10000);
    assertNotNull(receive);
    assertEquals(payload, receive.getPayload());
}
Also used : UUID(java.util.UUID) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 78 with RedisAvailable

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

the class RedisQueueMessageDrivenEndpointTests method testInt3017IntegrationInbound.

@Test
@RedisAvailable
public void testInt3017IntegrationInbound() {
    String payload = new Date().toString();
    RedisTemplate<String, String> redisTemplate = new StringRedisTemplate();
    redisTemplate.setConnectionFactory(this.connectionFactory);
    redisTemplate.afterPropertiesSet();
    redisTemplate.boundListOps("si.test.Int3017IntegrationInbound").leftPush("{\"payload\":\"" + payload + "\",\"headers\":{}}");
    Message<?> receive = this.fromChannel.receive(10000);
    assertNotNull(receive);
    assertEquals(payload, receive.getPayload());
}
Also used : Date(java.util.Date) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 79 with RedisAvailable

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

the class RedisOutboundGatewayTests method testMGetCommand.

@SuppressWarnings("unchecked")
@Test
@RedisAvailable
public void testMGetCommand() {
    RedisConnection connection = this.getConnectionFactoryForTest().getConnection();
    byte[] value1 = "bar1".getBytes();
    byte[] value2 = "bar2".getBytes();
    connection.set("foo1".getBytes(), value1);
    connection.set("foo2".getBytes(), value2);
    this.mgetCommandChannel.send(MessageBuilder.withPayload(new String[] { "foo1", "foo2" }).build());
    Message<?> receive = this.replyChannel.receive(1000);
    assertNotNull(receive);
    assertThat((List<byte[]>) receive.getPayload(), Matchers.contains(value1, value2));
    connection.del("foo1".getBytes(), "foo2".getBytes());
}
Also used : RedisConnection(org.springframework.data.redis.connection.RedisConnection) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 80 with RedisAvailable

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

the class RedisQueueOutboundChannelAdapterTests method testInt3015Default.

@Test
@RedisAvailable
public void testInt3015Default() throws Exception {
    final String queueName = "si.test.testRedisQueueOutboundChannelAdapter";
    final RedisQueueOutboundChannelAdapter handler = new RedisQueueOutboundChannelAdapter(queueName, this.connectionFactory);
    String payload = "testing";
    handler.handleMessage(MessageBuilder.withPayload(payload).build());
    RedisTemplate<String, ?> redisTemplate = new StringRedisTemplate();
    redisTemplate.setConnectionFactory(this.connectionFactory);
    redisTemplate.afterPropertiesSet();
    Object result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
    assertNotNull(result);
    assertEquals(payload, result);
    Date payload2 = new Date();
    handler.handleMessage(MessageBuilder.withPayload(payload2).build());
    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).rightPop(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)

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