diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java index 022eaa19ea..90fe1823ce 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.integration.Message; import org.springframework.integration.MessagingException; @@ -68,6 +69,9 @@ public class RedisChannelParserTests extends RedisAvailableTests{ public void testPubSubChannelUsage() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("RedisChannelParserTests-context.xml", this.getClass()); SubscribableChannel redisChannel = context.getBean("redisChannel", SubscribableChannel.class); + + this.awaitContainerSubscribed(TestUtils.getPropertyValue(redisChannel, "container", RedisMessageListenerContainer.class)); + final Message m = new GenericMessage("Hello Redis"); final CountDownLatch latch = new CountDownLatch(1); @@ -79,7 +83,7 @@ public class RedisChannelParserTests extends RedisAvailableTests{ }); redisChannel.send(m); - assertTrue(latch.await(2, TimeUnit.SECONDS)); + assertTrue(latch.await(5, TimeUnit.SECONDS)); context.stop(); } diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/inbound/RedisStoreInboundChannelAdapterIntegrationTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/inbound/RedisStoreInboundChannelAdapterIntegrationTests.java index 2a08b908ee..dda1589666 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/inbound/RedisStoreInboundChannelAdapterIntegrationTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/inbound/RedisStoreInboundChannelAdapterIntegrationTests.java @@ -38,7 +38,7 @@ import org.springframework.integration.redis.rules.RedisAvailableTests; * @author Artem Bilan * @since 2.2 */ -public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvailableTests{ +public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvailableTests { @Test @RedisAvailable @@ -111,113 +111,86 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila @Test @RedisAvailable @SuppressWarnings("unchecked") - public void testZsetInboundConfiguration(){ + public void testZsetInboundAdapter() throws InterruptedException { RedisConnectionFactory jcf = this.getConnectionFactoryForTest(); this.prepareZset(jcf); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("zset-inbound-adapter.xml", this.getClass()); + + //No Score test SourcePollingChannelAdapter zsetAdapterNoScore = context.getBean("zsetAdapterNoScore", SourcePollingChannelAdapter.class); zsetAdapterNoScore.start(); QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class); - Message> message = (Message>) redisChannel.receive(1000); + Message> message = (Message>) redisChannel.receive(2000); assertNotNull(message); assertEquals(13, message.getPayload().size()); //poll again, should get the same stuff - message = (Message>) redisChannel.receive(1000); + message = (Message>) redisChannel.receive(2000); assertNotNull(message); assertEquals(13, message.getPayload().size()); zsetAdapterNoScore.stop(); - context.close(); - } - @Test - @RedisAvailable - @SuppressWarnings("unchecked") - public void testZsetInboundConfigurationWithScoreRange(){ - RedisConnectionFactory jcf = this.getConnectionFactoryForTest(); - this.prepareZset(jcf); - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("zset-inbound-adapter.xml", this.getClass()); + + //ScoreRange test SourcePollingChannelAdapter zsetAdapterWithScoreRange = context.getBean("zsetAdapterWithScoreRange", SourcePollingChannelAdapter.class); zsetAdapterWithScoreRange.start(); - QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class); - - Message> message = (Message>) redisChannel.receive(1000); + message = (Message>) redisChannel.receive(2000); assertNotNull(message); assertEquals(11, message.getPayload().rangeByScore(18, 20).size()); //poll again, should get the same stuff - message = (Message>) redisChannel.receive(1000); + message = (Message>) redisChannel.receive(2000); assertNotNull(message); assertEquals(11, message.getPayload().rangeByScore(18, 20).size()); zsetAdapterWithScoreRange.stop(); - context.close(); - } - @Test - @RedisAvailable - @SuppressWarnings("unchecked") - public void testZsetInboundConfigurationWithSingleScore(){ - RedisConnectionFactory jcf = this.getConnectionFactoryForTest(); - this.prepareZset(jcf); - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("zset-inbound-adapter.xml", this.getClass()); + + //SingleScore test SourcePollingChannelAdapter zsetAdapterWithSingleScore = context.getBean("zsetAdapterWithSingleScore", SourcePollingChannelAdapter.class); zsetAdapterWithSingleScore.start(); - QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class); - - Message> message = (Message>) redisChannel.receive(1000); + message = (Message>) redisChannel.receive(2000); assertNotNull(message); assertEquals(2, message.getPayload().rangeByScore(18, 18).size()); //poll again, should get the same stuff - message = (Message>) redisChannel.receive(1000); + message = (Message>) redisChannel.receive(2000); assertNotNull(message); assertEquals(2, message.getPayload().rangeByScore(18, 18).size()); zsetAdapterWithSingleScore.stop(); - context.close(); - } - @Test - @RedisAvailable - @SuppressWarnings("unchecked") - public void testZsetInboundConfigurationWithSingleScoreAndSynchronization() throws Exception{ - RedisConnectionFactory jcf = this.getConnectionFactoryForTest(); - this.prepareZset(jcf); - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("zset-inbound-adapter.xml", this.getClass()); + + //SingleScoreAndSynchronization test SourcePollingChannelAdapter zsetAdapterWithSingleScoreAndSynchronization = context.getBean("zsetAdapterWithSingleScoreAndSynchronization", SourcePollingChannelAdapter.class); - SourcePollingChannelAdapter zsetAdapterNoScore = - context.getBean("zsetAdapterNoScore", SourcePollingChannelAdapter.class); - - QueueChannel redisChannel = context.getBean("redisChannel", QueueChannel.class); QueueChannel otherRedisChannel = context.getBean("otherRedisChannel", QueueChannel.class); // get all 13 presidents zsetAdapterNoScore.start(); - Message> message = (Message>) redisChannel.receive(1000); + message = (Message>) redisChannel.receive(2000); assertNotNull(message); assertEquals(13, message.getPayload().size()); zsetAdapterNoScore.stop(); // get only presidents for 18th century zsetAdapterWithSingleScoreAndSynchronization.start(); - message = (Message>) otherRedisChannel.receive(1000); + message = (Message>) otherRedisChannel.receive(2000); assertNotNull(message); assertEquals(2, message.getPayload().rangeByScore(18, 18).size()); // ... however other elements are still available 13-2=11 zsetAdapterNoScore.start(); - message = (Message>) redisChannel.receive(1000); + message = (Message>) redisChannel.receive(2000); assertNotNull(message); int n = 0; @@ -227,6 +200,7 @@ public class RedisStoreInboundChannelAdapterIntegrationTests extends RedisAvaila assertTrue(n < 100); zsetAdapterNoScore.stop(); + zsetAdapterWithSingleScoreAndSynchronization.stop(); context.close(); }