polishing Redis tests

This commit is contained in:
Oleg Zhurakousky
2011-08-02 08:52:50 -04:00
parent 563d1db0f1
commit ad10c92bd5
5 changed files with 22 additions and 10 deletions

View File

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

View File

@@ -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());

View File

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

View File

@@ -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();

View File

@@ -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);