diff --git a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java index d94968369..165b3d9cd 100644 --- a/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java +++ b/src/main/java/org/springframework/data/redis/listener/RedisMessageListenerContainer.java @@ -190,11 +190,13 @@ public class RedisMessageListenerContainer implements InitializingBean, Disposab // technically speaking we can only be notified right before the subscription starts synchronized (monitor) { lazyListen(); - try { - // wait up to 5 seconds - monitor.wait(initWait); - } catch (InterruptedException e) { - // stop waiting + if(listening) { + try { + // wait up to 5 seconds for Subscription thread + monitor.wait(initWait); + } catch (InterruptedException e) { + // stop waiting + } } } diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java index 23e79e285..a5235b324 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java @@ -45,6 +45,7 @@ import org.springframework.data.redis.support.collections.ObjectFactory; * Base test class for PubSub integration tests * * @author Costin Leau + * @author Jennifer Hickey */ @RunWith(Parameterized.class) public class PubSubTests { @@ -53,11 +54,13 @@ public class PubSubTests { protected RedisMessageListenerContainer container; protected ObjectFactory factory; + @SuppressWarnings("rawtypes") protected RedisTemplate template; private final BlockingDeque bag = new LinkedBlockingDeque(99); private final Object handler = new Object() { + @SuppressWarnings("unused") public void handleMessage(String message) { bag.add(message); } @@ -89,6 +92,7 @@ public class PubSubTests { container.destroy(); } + @SuppressWarnings("rawtypes") public PubSubTests(ObjectFactory factory, RedisTemplate template) { this.factory = factory; this.template = template; @@ -151,4 +155,12 @@ public class PubSubTests { assertNull(bag.poll(1, TimeUnit.SECONDS)); } + + @Test + public void testStartNoListeners() { + container.removeMessageListener(adapter, new ChannelTopic(CHANNEL)); + container.stop(); + // DATREDIS-207 This test previously took 5 seconds on start due to monitor wait + container.start(); + } } \ No newline at end of file