Apply "Java Convention" to met Jedis's preferred source code Convention
This commit is contained in:
@@ -22,13 +22,15 @@ public class JedisSentinelTest extends JedisTestBase {
|
|||||||
|
|
||||||
protected static HostAndPort master = HostAndPortUtil.getRedisServers()
|
protected static HostAndPort master = HostAndPortUtil.getRedisServers()
|
||||||
.get(0);
|
.get(0);
|
||||||
protected static HostAndPort slave = HostAndPortUtil.getRedisServers().get(5);
|
protected static HostAndPort slave = HostAndPortUtil.getRedisServers().get(
|
||||||
|
5);
|
||||||
protected static HostAndPort sentinel = HostAndPortUtil
|
protected static HostAndPort sentinel = HostAndPortUtil
|
||||||
.getSentinelServers().get(0);
|
.getSentinelServers().get(0);
|
||||||
|
|
||||||
protected static HostAndPort sentinelForFailover = HostAndPortUtil.getSentinelServers()
|
protected static HostAndPort sentinelForFailover = HostAndPortUtil
|
||||||
.get(3);
|
.getSentinelServers().get(3);
|
||||||
protected static HostAndPort masterForFailover = HostAndPortUtil.getRedisServers().get(6);
|
protected static HostAndPort masterForFailover = HostAndPortUtil
|
||||||
|
.getRedisServers().get(6);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws InterruptedException {
|
public void setup() throws InterruptedException {
|
||||||
@@ -57,7 +59,8 @@ public class JedisSentinelTest extends JedisTestBase {
|
|||||||
|
|
||||||
assertTrue(inMasters);
|
assertTrue(inMasters);
|
||||||
|
|
||||||
List<String> masterHostAndPort = j.sentinelGetMasterAddrByName(MASTER_NAME);
|
List<String> masterHostAndPort = j
|
||||||
|
.sentinelGetMasterAddrByName(MASTER_NAME);
|
||||||
HostAndPort masterFromSentinel = new HostAndPort(
|
HostAndPort masterFromSentinel = new HostAndPort(
|
||||||
masterHostAndPort.get(0), Integer.parseInt(masterHostAndPort
|
masterHostAndPort.get(0), Integer.parseInt(masterHostAndPort
|
||||||
.get(1)));
|
.get(1)));
|
||||||
@@ -65,7 +68,8 @@ public class JedisSentinelTest extends JedisTestBase {
|
|||||||
|
|
||||||
List<Map<String, String>> slaves = j.sentinelSlaves(MASTER_NAME);
|
List<Map<String, String>> slaves = j.sentinelSlaves(MASTER_NAME);
|
||||||
assertTrue(slaves.size() > 0);
|
assertTrue(slaves.size() > 0);
|
||||||
assertEquals(master.getPort(), Integer.parseInt(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
|
// DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET
|
||||||
assertEquals(Long.valueOf(1), j.sentinelReset(MASTER_NAME));
|
assertEquals(Long.valueOf(1), j.sentinelReset(MASTER_NAME));
|
||||||
@@ -74,15 +78,19 @@ public class JedisSentinelTest extends JedisTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sentinelFailover() throws InterruptedException {
|
public void sentinelFailover() throws InterruptedException {
|
||||||
Jedis j = new Jedis(sentinelForFailover.getHost(), sentinelForFailover.getPort());
|
Jedis j = new Jedis(sentinelForFailover.getHost(),
|
||||||
|
sentinelForFailover.getPort());
|
||||||
|
|
||||||
HostAndPort currentMaster = new HostAndPort(masterForFailover.getHost(), masterForFailover.getPort());
|
HostAndPort currentMaster = new HostAndPort(
|
||||||
|
masterForFailover.getHost(), masterForFailover.getPort());
|
||||||
|
|
||||||
List<String> masterHostAndPort = j.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
|
List<String> masterHostAndPort = j
|
||||||
|
.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
|
||||||
String result = j.sentinelFailover(FAILOVER_MASTER_NAME);
|
String result = j.sentinelFailover(FAILOVER_MASTER_NAME);
|
||||||
assertEquals("OK", result);
|
assertEquals("OK", result);
|
||||||
|
|
||||||
JedisSentinelTestUtil.waitForNewPromotedMaster(sentinelForFailover, FAILOVER_MASTER_NAME, currentMaster);
|
JedisSentinelTestUtil.waitForNewPromotedMaster(sentinelForFailover,
|
||||||
|
FAILOVER_MASTER_NAME, currentMaster);
|
||||||
|
|
||||||
masterHostAndPort = j.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
|
masterHostAndPort = j.sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
|
||||||
HostAndPort newMaster = new HostAndPort(masterHostAndPort.get(0),
|
HostAndPort newMaster = new HostAndPort(masterHostAndPort.get(0),
|
||||||
@@ -96,12 +104,14 @@ public class JedisSentinelTest extends JedisTestBase {
|
|||||||
Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
|
Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
|
||||||
|
|
||||||
// monitor new master
|
// monitor new master
|
||||||
String result = j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, master.getPort(), 1);
|
String result = j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP,
|
||||||
|
master.getPort(), 1);
|
||||||
assertEquals("OK", result);
|
assertEquals("OK", result);
|
||||||
|
|
||||||
// already monitored
|
// already monitored
|
||||||
try {
|
try {
|
||||||
j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, master.getPort(), 1);
|
j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP, master.getPort(),
|
||||||
|
1);
|
||||||
fail();
|
fail();
|
||||||
} catch (JedisDataException e) {
|
} catch (JedisDataException e) {
|
||||||
// pass
|
// pass
|
||||||
@@ -112,7 +122,8 @@ public class JedisSentinelTest extends JedisTestBase {
|
|||||||
public void sentinelRemove() {
|
public void sentinelRemove() {
|
||||||
Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
|
Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
|
||||||
|
|
||||||
ensureMonitored(sentinel, REMOVE_MASTER_NAME, MASTER_IP, master.getPort(), 1);
|
ensureMonitored(sentinel, REMOVE_MASTER_NAME, MASTER_IP,
|
||||||
|
master.getPort(), 1);
|
||||||
|
|
||||||
String result = j.sentinelRemove(REMOVE_MASTER_NAME);
|
String result = j.sentinelRemove(REMOVE_MASTER_NAME);
|
||||||
assertEquals("OK", result);
|
assertEquals("OK", result);
|
||||||
@@ -140,7 +151,8 @@ public class JedisSentinelTest extends JedisTestBase {
|
|||||||
List<Map<String, String>> masters = j.sentinelMasters();
|
List<Map<String, String>> masters = j.sentinelMasters();
|
||||||
for (Map<String, String> master : masters) {
|
for (Map<String, String> master : masters) {
|
||||||
if (master.get("name").equals(MASTER_NAME)) {
|
if (master.get("name").equals(MASTER_NAME)) {
|
||||||
assertEquals(1234, Integer.parseInt(master.get("down-after-milliseconds")));
|
assertEquals(1234,
|
||||||
|
Integer.parseInt(master.get("down-after-milliseconds")));
|
||||||
assertEquals(3, Integer.parseInt(master.get("parallel-syncs")));
|
assertEquals(3, Integer.parseInt(master.get("parallel-syncs")));
|
||||||
assertEquals(2, Integer.parseInt(master.get("quorum")));
|
assertEquals(2, Integer.parseInt(master.get("quorum")));
|
||||||
}
|
}
|
||||||
@@ -150,7 +162,8 @@ public class JedisSentinelTest extends JedisTestBase {
|
|||||||
j.sentinelSet(MASTER_NAME, parameterMap);
|
j.sentinelSet(MASTER_NAME, parameterMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureMonitored(HostAndPort sentinel, String masterName, String ip, int port, int quorum) {
|
private void ensureMonitored(HostAndPort sentinel, String masterName,
|
||||||
|
String ip, int port, int quorum) {
|
||||||
Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
|
Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
|
||||||
try {
|
try {
|
||||||
j.sentinelMonitor(masterName, ip, port, quorum);
|
j.sentinelMonitor(masterName, ip, port, quorum);
|
||||||
|
|||||||
Reference in New Issue
Block a user