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();
}
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());
}
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());
}
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());
}
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);
}
Aggregations