Speed up Sentinel related tests
* remove FIXME sleep codes for Sentinel related tests ** add functions for Sentinel tests (JedisSentinelTestUtil) *** waitForSentinelRecognizeRedisReplication *** waitForNewPromotedMaster *** waitForSentinelsRecognizeEachOthers **** TODO: there're no command for sentinel to list recognized sentinel **** sleep 5.5 sec (sentinel pings to master every 5 sec) * set HostAndPort class to public(no longer inner) class ** reason: We cannot know pool's current master if HostAndPort class is private inner class / HostAndPort classes are duplicated (main/test) ** make getter method and parameterized constructor *** set fields once, get anytime
This commit is contained in:
@@ -3,52 +3,37 @@ package redis.clients.jedis.tests;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.HostAndPort;
|
||||
import redis.clients.jedis.Protocol;
|
||||
|
||||
public class HostAndPortUtil {
|
||||
private static List<HostAndPort> redisHostAndPortList = new ArrayList<HostAndPortUtil.HostAndPort>();
|
||||
private static List<HostAndPort> sentinelHostAndPortList = new ArrayList<HostAndPortUtil.HostAndPort>();
|
||||
private static List<HostAndPort> redisHostAndPortList = new ArrayList<HostAndPort>();
|
||||
private static List<HostAndPort> sentinelHostAndPortList = new ArrayList<HostAndPort>();
|
||||
|
||||
static {
|
||||
|
||||
HostAndPort defaulthnp1 = new HostAndPort();
|
||||
defaulthnp1.host = "localhost";
|
||||
defaulthnp1.port = Protocol.DEFAULT_PORT;
|
||||
HostAndPort defaulthnp1 = new HostAndPort("localhost", Protocol.DEFAULT_PORT);
|
||||
redisHostAndPortList.add(defaulthnp1);
|
||||
|
||||
HostAndPort defaulthnp2 = new HostAndPort();
|
||||
defaulthnp2.host = "localhost";
|
||||
defaulthnp2.port = Protocol.DEFAULT_PORT + 1;
|
||||
HostAndPort defaulthnp2 = new HostAndPort("localhost", Protocol.DEFAULT_PORT + 1);
|
||||
redisHostAndPortList.add(defaulthnp2);
|
||||
|
||||
HostAndPort defaulthnp3 = new HostAndPort();
|
||||
defaulthnp3.host = "localhost";
|
||||
defaulthnp3.port = Protocol.DEFAULT_PORT + 2;
|
||||
HostAndPort defaulthnp3 = new HostAndPort("localhost", Protocol.DEFAULT_PORT + 2);
|
||||
redisHostAndPortList.add(defaulthnp3);
|
||||
|
||||
HostAndPort defaulthnp4 = new HostAndPort();
|
||||
defaulthnp4.host = "localhost";
|
||||
defaulthnp4.port = Protocol.DEFAULT_PORT + 3;
|
||||
HostAndPort defaulthnp4 = new HostAndPort("localhost", Protocol.DEFAULT_PORT + 3);
|
||||
redisHostAndPortList.add(defaulthnp4);
|
||||
|
||||
HostAndPort defaulthnp5 = new HostAndPort();
|
||||
defaulthnp5.host = "localhost";
|
||||
defaulthnp5.port = Protocol.DEFAULT_PORT + 4;
|
||||
HostAndPort defaulthnp5 = new HostAndPort("localhost", Protocol.DEFAULT_PORT + 4);
|
||||
redisHostAndPortList.add(defaulthnp5);
|
||||
|
||||
HostAndPort defaulthnp6 = new HostAndPort();
|
||||
defaulthnp6.host = "localhost";
|
||||
defaulthnp6.port = Protocol.DEFAULT_SENTINEL_PORT;
|
||||
HostAndPort defaulthnp6 = new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT);
|
||||
sentinelHostAndPortList.add(defaulthnp6);
|
||||
|
||||
HostAndPort defaulthnp7 = new HostAndPort();
|
||||
defaulthnp7.host = "localhost";
|
||||
defaulthnp7.port = Protocol.DEFAULT_SENTINEL_PORT + 1;
|
||||
HostAndPort defaulthnp7 = new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 1);
|
||||
sentinelHostAndPortList.add(defaulthnp7);
|
||||
|
||||
HostAndPort defaulthnp8 = new HostAndPort();
|
||||
defaulthnp8.host = "localhost";
|
||||
defaulthnp8.port = Protocol.DEFAULT_SENTINEL_PORT + 2;
|
||||
HostAndPort defaulthnp8 = new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 2);
|
||||
sentinelHostAndPortList.add(defaulthnp8);
|
||||
|
||||
String envRedisHosts = System.getProperty("redis-hosts");
|
||||
@@ -66,24 +51,22 @@ public class HostAndPortUtil {
|
||||
|
||||
if (null != hostDefs && 2 <= hostDefs.length) {
|
||||
|
||||
List<HostAndPort> envHostsAndPorts = new ArrayList<HostAndPortUtil.HostAndPort>(hostDefs.length);
|
||||
List<HostAndPort> envHostsAndPorts = new ArrayList<HostAndPort>(hostDefs.length);
|
||||
|
||||
for (String hostDef : hostDefs) {
|
||||
|
||||
String[] hostAndPort = hostDef.split(":");
|
||||
|
||||
if (null != hostAndPort && 2 == hostAndPort.length) {
|
||||
String host = hostAndPort[0];
|
||||
int port = Protocol.DEFAULT_PORT;
|
||||
|
||||
HostAndPort hnp = new HostAndPort();
|
||||
hnp.host = hostAndPort[0];
|
||||
|
||||
try {
|
||||
hnp.port = Integer.parseInt(hostAndPort[1]);
|
||||
try {
|
||||
port = Integer.parseInt(hostAndPort[1]);
|
||||
} catch (final NumberFormatException nfe) {
|
||||
hnp.port = Protocol.DEFAULT_PORT;
|
||||
}
|
||||
|
||||
envHostsAndPorts.add(hnp);
|
||||
}
|
||||
|
||||
envHostsAndPorts.add(new HostAndPort(host, port));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,13 +85,4 @@ public class HostAndPortUtil {
|
||||
return sentinelHostAndPortList;
|
||||
}
|
||||
|
||||
public static class HostAndPort {
|
||||
public String host;
|
||||
public int port;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return host + ":" + port;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user