make jedis unit tests pass to Redis 2.8.1

* increase sentinel instance to test JedisSentinelTest
** clear() called, slave promoted to master (slave of no one), New
Sentinel force to restore it (demote) -> slave is not reusable
* ipv6 applied at Redis 2.8 -> localhost / 127.0.0.1 / ::1 is now all same

* Makefile: sleep some time for launch each sentinel (workaround to sentinel's issue)
** issue to sentinel leader vote: https://github.com/antirez/redis/issues/1419
*** sentinel may confused to vote with sentinels launched approximately same time
This commit is contained in:
Jungtaek Lim
2013-12-02 22:11:52 +09:00
parent e10cdda5c7
commit 15891c4117
5 changed files with 58 additions and 78 deletions

View File

@@ -27,14 +27,17 @@ public class HostAndPortUtil {
HostAndPort defaulthnp5 = new HostAndPort("localhost", Protocol.DEFAULT_PORT + 4);
redisHostAndPortList.add(defaulthnp5);
HostAndPort defaulthnp6 = new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT);
sentinelHostAndPortList.add(defaulthnp6);
HostAndPort defaulthnp6 = new HostAndPort("localhost", Protocol.DEFAULT_PORT + 5);
redisHostAndPortList.add(defaulthnp6);
HostAndPort defaulthnp7 = new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 1);
HostAndPort defaulthnp7 = new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT);
sentinelHostAndPortList.add(defaulthnp7);
HostAndPort defaulthnp8 = new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 2);
HostAndPort defaulthnp8 = new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 1);
sentinelHostAndPortList.add(defaulthnp8);
HostAndPort defaulthnp9 = new HostAndPort("localhost", Protocol.DEFAULT_SENTINEL_PORT + 2);
sentinelHostAndPortList.add(defaulthnp9);
String envRedisHosts = System.getProperty("redis-hosts");
String envSentinelHosts = System.getProperty("sentinel-hosts");

View File

@@ -17,8 +17,8 @@ public class JedisSentinelTest extends JedisTestBase {
protected static HostAndPort master = HostAndPortUtil.getRedisServers()
.get(0);
protected static HostAndPort slave = HostAndPortUtil.getRedisServers().get(
1);
protected static HostAndPort slave = HostAndPortUtil.getRedisServers()
.get(5);
protected static HostAndPort sentinel = HostAndPortUtil
.getSentinelServers().get(0);
@@ -44,14 +44,14 @@ public class JedisSentinelTest extends JedisTestBase {
@After
public void clear() throws InterruptedException {
Jedis j = new Jedis("localhost", 6380);
j.auth("foobared");
j.slaveofNoOne();
// New Sentinel (after 2.8.1)
// when slave promoted to master (slave of no one), New Sentinel force to restore it (demote)
// so, promote(slaveof) slave to master has no effect, not same to old Sentinel's behavior
}
@Test
public void sentinel() {
Jedis j = new Jedis("localhost", 26379);
Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
List<Map<String, String>> masters = j.sentinelMasters();
final String masterName = masters.get(0).get("name");
@@ -59,12 +59,13 @@ public class JedisSentinelTest extends JedisTestBase {
List<String> masterHostAndPort = j
.sentinelGetMasterAddrByName(masterName);
assertEquals("127.0.0.1", masterHostAndPort.get(0));
assertEquals("6379", masterHostAndPort.get(1));
HostAndPort masterFromSentinel = new HostAndPort(masterHostAndPort.get(0),
Integer.parseInt(masterHostAndPort.get(1)));
assertEquals(master, masterFromSentinel);
List<Map<String, String>> slaves = j.sentinelSlaves(masterName);
assertTrue(slaves.size() > 0);
assertEquals("6379", slaves.get(0).get("master-port"));
assertEquals(master.getPort(), Integer.parseInt(slaves.get(0).get("master-port")));
// DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET
assertEquals(Long.valueOf(1), j.sentinelReset(masterName));