last changes rolled back. New tests for failed connection exception added

pull/395/head
Nikita 9 years ago
parent 39dc3579cf
commit e2d2861eb3

@ -202,22 +202,16 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
if (config.getReadMode() == ReadMode.MASTER) {
SingleEntry entry = new SingleEntry(slots, this, config);
Future<Void> f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
if (!f.awaitUninterruptibly(config.getConnectTimeout(), TimeUnit.MILLISECONDS)) {
throw new RedisConnectionException("Can't connect to server " + config.getMasterAddress() + " due to connection timeout (" + config.getConnectTimeout() + " ms) has reached!", f.cause());
}
f.syncUninterruptibly();
addEntry(singleSlotRange, entry);
} else {
MasterSlaveEntry entry = new MasterSlaveEntry(slots, this, config);
List<Future<Void>> fs = entry.initSlaveBalancer();
for (Future<Void> future : fs) {
if (!future.awaitUninterruptibly(config.getConnectTimeout(), TimeUnit.MILLISECONDS)) {
throw new RedisConnectionException("Can't connect to slave server due to connection timeout (" + config.getConnectTimeout() + " ms) has reached!", future.cause());
}
future.syncUninterruptibly();
}
Future<Void> f = entry.setupMasterEntry(config.getMasterAddress().getHost(), config.getMasterAddress().getPort());
if (!f.awaitUninterruptibly(config.getConnectTimeout(), TimeUnit.MILLISECONDS)) {
throw new RedisConnectionException("Can't connect to server " + config.getMasterAddress() + " due to connection timeout (" + config.getConnectTimeout() + " ms) has reached!", f.cause());
}
f.syncUninterruptibly();
addEntry(singleSlotRange, entry);
}
}

@ -61,7 +61,7 @@ public class SingleEntry extends MasterSlaveEntry {
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
res.setFailure(future.cause());
res.tryFailure(future.cause());
return;
}
if (counter.decrementAndGet() == 0) {

@ -12,12 +12,30 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Test;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisConnectionException;
import org.redisson.client.WriteRedisConnectionException;
import org.redisson.client.handler.CommandDecoder;
import org.redisson.client.handler.CommandEncoder;
import org.redisson.client.handler.CommandsListEncoder;
import org.redisson.client.handler.CommandsQueue;
import org.redisson.client.handler.ConnectionWatchdog;
import org.redisson.codec.SerializationCodec;
import org.redisson.connection.ConnectionListener;
import org.redisson.core.ClusterNode;
import org.redisson.core.Node;
import org.redisson.core.NodesGroup;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.GenericFutureListener;
import static com.jayway.awaitility.Awaitility.*;
public class RedissonTest {
@ -142,7 +160,6 @@ public class RedissonTest {
RedissonClient r = Redisson.create();
String t = r.getConfig().toJSON();
Config c = Config.fromJSON(t);
System.out.println(t);
assertThat(c.toJSON()).isEqualTo(t);
}
@ -153,7 +170,6 @@ public class RedissonTest {
String t = c2.toJSON();
Config c = Config.fromJSON(t);
System.out.println(t);
assertThat(c.toJSON()).isEqualTo(t);
}
@ -171,4 +187,50 @@ public class RedissonTest {
Assert.assertTrue(nodes.pingAll());
}
@Test(expected = RedisConnectionException.class)
public void testSingleConnectionFail() throws InterruptedException {
Config config = new Config();
config.useSingleServer().setAddress("127.0.0.1:1111");
Redisson.create(config);
Thread.sleep(1500);
}
@Test(expected = RedisConnectionException.class)
public void testClusterConnectionFail() throws InterruptedException {
Config config = new Config();
config.useClusterServers().addNodeAddress("127.0.0.1:1111");
Redisson.create(config);
Thread.sleep(1500);
}
@Test(expected = RedisConnectionException.class)
public void testElasticacheConnectionFail() throws InterruptedException {
Config config = new Config();
config.useElasticacheServers().addNodeAddress("127.0.0.1:1111");
Redisson.create(config);
Thread.sleep(1500);
}
@Test(expected = RedisConnectionException.class)
public void testMasterSlaveConnectionFail() throws InterruptedException {
Config config = new Config();
config.useMasterSlaveServers().setMasterAddress("127.0.0.1:1111");
Redisson.create(config);
Thread.sleep(1500);
}
@Test(expected = RedisConnectionException.class)
public void testSentinelConnectionFail() throws InterruptedException {
Config config = new Config();
config.useSentinelServers().addSentinelAddress("127.0.0.1:1111");
Redisson.create(config);
Thread.sleep(1500);
}
}

Loading…
Cancel
Save