DATAREDIS-242 - Listener Container start() Returns Before Container is Really Started.

We now wait for the subscription to be present in the connection in case of async connections by periodically checking whether the subscription is available in 100ms intervals. The max time to wait for the async subscription can be configured and is set to 2 seconds by default.

Moved SpinBarrier and TestCondition from test packages as static inner classes into RedisMessageListenerContainer. Included ConnectionUtils from tests into official API.
This commit is contained in:
Thomas Darimont
2014-01-17 17:16:06 +01:00
parent c6d2d7f9c9
commit b5adde7430
3 changed files with 184 additions and 27 deletions

View File

@@ -1,51 +0,0 @@
/*
* Copyright 2011-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jredis.JredisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.srp.SrpConnectionFactory;
/**
* Utilities for examining a {@link RedisConnection}
*
* @author Jennifer Hickey
*
*/
public abstract class ConnectionUtils {
public static boolean isAsync(RedisConnectionFactory connectionFactory) {
return (connectionFactory instanceof LettuceConnectionFactory)
|| (connectionFactory instanceof SrpConnectionFactory);
}
public static boolean isSrp(RedisConnectionFactory connectionFactory) {
return connectionFactory instanceof SrpConnectionFactory;
}
public static boolean isJredis(RedisConnectionFactory connectionFactory) {
return connectionFactory instanceof JredisConnectionFactory;
}
public static boolean isLettuce(RedisConnectionFactory connectionFactory) {
return connectionFactory instanceof LettuceConnectionFactory;
}
public static boolean isJedis(RedisConnectionFactory connectionFactory) {
return connectionFactory instanceof JedisConnectionFactory;
}
}

View File

@@ -172,4 +172,27 @@ public class PubSubTests<T> {
// DATREDIS-207 This test previously took 5 seconds on start due to monitor wait
container.start();
}
/**
* @see DATAREDIS-251
*/
@SuppressWarnings("unchecked")
@Test
public void testStartListenersToNoSpecificChannelTest() throws InterruptedException {
container.removeMessageListener(adapter, new ChannelTopic(CHANNEL));
container.addMessageListener(adapter, Arrays.asList(new PatternTopic("*")));
container.start();
Thread.sleep(1000); //give the container a little time to recover
T payload = getT();
template.convertAndSend(CHANNEL, payload);
Set<T> set = new LinkedHashSet<T>();
set.add((T) bag.poll(3, TimeUnit.SECONDS));
assertThat(set, hasItems(payload));
}
}