polishing Redis tests
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.redis.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
@@ -49,16 +50,25 @@ public class RedisChannelParserTests extends RedisAvailableTests{
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testPubSubChannelUsage(){
|
||||
public void testPubSubChannelUsage() throws Exception {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("RedisChannelParserTests-context.xml", this.getClass());
|
||||
SubscribableChannel redisChannel = context.getBean("redisChannel", SubscribableChannel.class);
|
||||
redisChannel.subscribe(new MessageHandler() {
|
||||
|
||||
final Message<?> m = new GenericMessage<String>("Hello Redis");
|
||||
|
||||
final Marker marker = Mockito.mock(Marker.class);
|
||||
redisChannel.subscribe(new MessageHandler() {
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
System.out.println("Message: " + message);
|
||||
assertEquals(m.getPayload(), message.getPayload());
|
||||
marker.mark();
|
||||
}
|
||||
});
|
||||
redisChannel.send(new GenericMessage<String>("Hello Redis"));
|
||||
redisChannel.send(m);
|
||||
Thread.sleep(1000);
|
||||
Mockito.verify(marker, Mockito.times(1)).mark();
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
interface Marker {
|
||||
void mark();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,11 +58,12 @@ public class RedisInboundChannelAdapterParserTests extends RedisAvailableTests{
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testInboundChannelAdapterMessaging() {
|
||||
public void testInboundChannelAdapterMessaging() throws Exception{
|
||||
JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
|
||||
connectionFactory.setPort(7379);
|
||||
connectionFactory.afterPropertiesSet();
|
||||
connectionFactory.getConnection().publish("foo".getBytes(), "Hello Redis from foo".getBytes());
|
||||
Thread.sleep(1000);
|
||||
QueueChannel receiveChannel = context.getBean("receiveChannel", QueueChannel.class);
|
||||
assertEquals("Hello Redis from foo", receiveChannel.receive(1000).getPayload());
|
||||
connectionFactory.getConnection().publish("bar".getBytes(), "Hello Redis from bar".getBytes());
|
||||
|
||||
@@ -60,9 +60,10 @@ public class RedisOutboundChannelAdapterParserTests extends RedisAvailableTests{
|
||||
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testOutboundChannelAdapterMessaging(){
|
||||
public void testOutboundChannelAdapterMessaging() throws Exception{
|
||||
MessageChannel sendChannel = context.getBean("sendChannel", MessageChannel.class);
|
||||
sendChannel.send(new GenericMessage<String>("Hello Redis"));
|
||||
Thread.sleep(1000);
|
||||
QueueChannel receiveChannel = context.getBean("receiveChannel", QueueChannel.class);
|
||||
assertEquals("Hello Redis", receiveChannel.receive(1000).getPayload());
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class RedisInboundChannelAdapterTests extends RedisAvailableTests{
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testRedisInboundChannelAdapter() throws Exception {
|
||||
int numToTest = 100;
|
||||
int numToTest = 10;
|
||||
String redisChannelName = "testRedisInboundChannelAdapterChannel";
|
||||
QueueChannel channel = new QueueChannel();
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class RedisPublishingMessageHandlerTests extends RedisAvailableTests{
|
||||
@Test
|
||||
@RedisAvailable
|
||||
public void testRedisPublishingMessageHandler() throws Exception {
|
||||
int numToTest = 100;
|
||||
int numToTest = 10;
|
||||
String topic = "si.test.channel";
|
||||
final CountDownLatch latch = new CountDownLatch(numToTest);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class RedisPublishingMessageHandlerTests extends RedisAvailableTests{
|
||||
container.afterPropertiesSet();
|
||||
container.addMessageListener(listener, Collections.<Topic>singletonList(new ChannelTopic(topic)));
|
||||
container.start();
|
||||
Thread.sleep(500);
|
||||
Thread.sleep(1000);
|
||||
|
||||
final RedisPublishingMessageHandler handler = new RedisPublishingMessageHandler(connectionFactory);
|
||||
handler.setDefaultTopic(topic);
|
||||
|
||||
Reference in New Issue
Block a user