use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisPublishingMessageHandlerTests method testRedisPublishingMessageHandler.
@Test
@RedisAvailable
public void testRedisPublishingMessageHandler() throws Exception {
int numToTest = 10;
String topic = "si.test.channel";
final CountDownLatch latch = new CountDownLatch(numToTest * 2);
RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
MessageListenerAdapter listener = new MessageListenerAdapter();
listener.setDelegate(new Listener(latch));
listener.setSerializer(new StringRedisSerializer());
listener.afterPropertiesSet();
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.afterPropertiesSet();
container.addMessageListener(listener, Collections.<Topic>singletonList(new ChannelTopic(topic)));
container.start();
this.awaitContainerSubscribed(container);
final RedisPublishingMessageHandler handler = new RedisPublishingMessageHandler(connectionFactory);
handler.setTopicExpression(new LiteralExpression(topic));
for (int i = 0; i < numToTest; i++) {
handler.handleMessage(MessageBuilder.withPayload("test-" + i).build());
}
for (int i = 0; i < numToTest; i++) {
handler.handleMessage(MessageBuilder.withPayload(("test-" + i).getBytes()).build());
}
assertTrue(latch.await(10, TimeUnit.SECONDS));
container.stop();
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisStoreOutboundChannelAdapterIntegrationTests method testPropertiesSimple.
@Test
@RedisAvailable
public void testPropertiesSimple() {
RedisProperties redisProperties = new RedisProperties("foo", this.redisTemplate);
assertEquals(0, redisProperties.size());
Message<String> message = MessageBuilder.withPayload("bar").setHeader(RedisHeaders.KEY, "foo").setHeader("baz", "qux").build();
this.simplePropertyChannel.send(message);
assertEquals("bar", redisProperties.get("qux"));
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisStoreOutboundChannelAdapterIntegrationTests method testMapToMapAsSingleEntryWithKeyAsHeader.
@Test
@RedisAvailable
public void testMapToMapAsSingleEntryWithKeyAsHeader() {
RedisTemplate<String, Map<String, Map<String, String>>> redisTemplate = new RedisTemplate<String, Map<String, Map<String, String>>>();
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setConnectionFactory(getConnectionFactoryForTest());
redisTemplate.afterPropertiesSet();
RedisMap<String, Map<String, String>> redisMap = new DefaultRedisMap<String, Map<String, String>>("pepboys", redisTemplate);
assertEquals(0, redisMap.size());
Map<String, String> pepboys = new HashMap<String, String>();
pepboys.put("1", "Manny");
pepboys.put("2", "Moe");
pepboys.put("3", "Jack");
Message<Map<String, String>> message = MessageBuilder.withPayload(pepboys).setHeader(RedisHeaders.KEY, "pepboys").setHeader(RedisHeaders.MAP_KEY, "foo").build();
this.mapToMapBChannel.send(message);
Map<String, String> pepboyz = redisMap.get("foo");
assertEquals("Manny", pepboyz.get("1"));
assertEquals("Moe", pepboyz.get("2"));
assertEquals("Jack", pepboyz.get("3"));
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisStoreOutboundChannelAdapterIntegrationTests method testProperties.
@Test
@RedisAvailable
public void testProperties() {
RedisProperties redisProperties = new RedisProperties("pepboys", this.redisTemplate);
assertEquals(0, redisProperties.size());
Properties pepboys = new Properties();
pepboys.put("1", "Manny");
pepboys.put("2", "Moe");
pepboys.put("3", "Jack");
Message<Properties> message = MessageBuilder.withPayload(pepboys).build();
this.propertyChannel.send(message);
assertEquals("Manny", redisProperties.get("1"));
assertEquals("Moe", redisProperties.get("2"));
assertEquals("Jack", redisProperties.get("3"));
}
use of org.springframework.integration.redis.rules.RedisAvailable in project spring-integration by spring-projects.
the class RedisMessageStoreTests method testAddAndRemoveMessagesFromMessageGroup.
@Test
@RedisAvailable
public void testAddAndRemoveMessagesFromMessageGroup() throws Exception {
RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
RedisMessageStore messageStore = new RedisMessageStore(jcf);
String groupId = "X";
List<Message<?>> messages = new ArrayList<Message<?>>();
for (int i = 0; i < 25; i++) {
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessagesToGroup(groupId, message);
messages.add(message);
}
messageStore.removeMessagesFromGroup(groupId, messages);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
messageStore.removeMessageGroup("X");
}
Aggregations