Remove 5 second wait starting MsgListenerContainer

with no listeners

DATAREDIS-207
This commit is contained in:
Jennifer Hickey
2013-07-26 13:59:10 -04:00
parent 800b8700f0
commit 352620d054
2 changed files with 19 additions and 5 deletions

View File

@@ -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
}
}
}

View File

@@ -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<T> {
@@ -53,11 +54,13 @@ public class PubSubTests<T> {
protected RedisMessageListenerContainer container;
protected ObjectFactory<T> factory;
@SuppressWarnings("rawtypes")
protected RedisTemplate template;
private final BlockingDeque<String> bag = new LinkedBlockingDeque<String>(99);
private final Object handler = new Object() {
@SuppressWarnings("unused")
public void handleMessage(String message) {
bag.add(message);
}
@@ -89,6 +92,7 @@ public class PubSubTests<T> {
container.destroy();
}
@SuppressWarnings("rawtypes")
public PubSubTests(ObjectFactory<T> factory, RedisTemplate template) {
this.factory = factory;
this.template = template;
@@ -151,4 +155,12 @@ public class PubSubTests<T> {
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();
}
}