speed up JedisSentinelTest

This commit is contained in:
Jonathan Leibiusky
2013-12-03 19:03:19 -05:00
parent 20d686ec94
commit 4a4768b1d2
3 changed files with 13 additions and 23 deletions

View File

@@ -60,6 +60,7 @@ pidfile /tmp/redis6.pid
logfile /tmp/redis6.log logfile /tmp/redis6.log
save "" save ""
appendonly no appendonly no
slaveof localhost 6379
endef endef
define REDIS_SENTINEL1 define REDIS_SENTINEL1

View File

@@ -1,6 +1,5 @@
package redis.clients.jedis.tests; package redis.clients.jedis.tests;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -10,15 +9,14 @@ import org.junit.Test;
import redis.clients.jedis.HostAndPort; import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.tests.utils.JedisSentinelTestUtil;
public class JedisSentinelTest extends JedisTestBase { public class JedisSentinelTest extends JedisTestBase {
private static final String MASTER_NAME = "mymaster"; private static final String MASTER_NAME = "mymaster";
protected static HostAndPort master = HostAndPortUtil.getRedisServers() protected static HostAndPort master = HostAndPortUtil.getRedisServers()
.get(0); .get(0);
protected static HostAndPort slave = HostAndPortUtil.getRedisServers() protected static HostAndPort slave = HostAndPortUtil.getRedisServers().get(
.get(5); 5);
protected static HostAndPort sentinel = HostAndPortUtil protected static HostAndPort sentinel = HostAndPortUtil
.getSentinelServers().get(0); .getSentinelServers().get(0);
@@ -28,25 +26,16 @@ public class JedisSentinelTest extends JedisTestBase {
@Before @Before
public void setup() throws InterruptedException { public void setup() throws InterruptedException {
masterJedis = new Jedis(master.getHost(), master.getPort());
slaveJedis = new Jedis(slave.getHost(), slave.getPort());
slaveJedis.auth("foobared");
slaveJedis.configSet("masterauth", "foobared");
slaveJedis.slaveof(master.getHost(), master.getPort());
List<HostAndPort> slaves = new ArrayList<HostAndPort>();
slaves.add(slave);
JedisSentinelTestUtil.waitForSentinelRecognizeRedisReplication(
sentinel, MASTER_NAME, master, slaves);
} }
@After @After
public void clear() throws InterruptedException { public void clear() throws InterruptedException {
// New Sentinel (after 2.8.1) // New Sentinel (after 2.8.1)
// when slave promoted to master (slave of no one), New Sentinel force to restore it (demote) // when slave promoted to master (slave of no one), New Sentinel force
// so, promote(slaveof) slave to master has no effect, not same to old Sentinel's behavior // to restore it (demote)
// so, promote(slaveof) slave to master has no effect, not same to old
// Sentinel's behavior
} }
@Test @Test
@@ -59,13 +48,15 @@ public class JedisSentinelTest extends JedisTestBase {
List<String> masterHostAndPort = j List<String> masterHostAndPort = j
.sentinelGetMasterAddrByName(masterName); .sentinelGetMasterAddrByName(masterName);
HostAndPort masterFromSentinel = new HostAndPort(masterHostAndPort.get(0), HostAndPort masterFromSentinel = new HostAndPort(
Integer.parseInt(masterHostAndPort.get(1))); masterHostAndPort.get(0), Integer.parseInt(masterHostAndPort
.get(1)));
assertEquals(master, masterFromSentinel); assertEquals(master, masterFromSentinel);
List<Map<String, String>> slaves = j.sentinelSlaves(masterName); List<Map<String, String>> slaves = j.sentinelSlaves(masterName);
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(masterName)); assertEquals(Long.valueOf(1), j.sentinelReset(masterName));

View File

@@ -423,7 +423,6 @@ public class ListCommandsTest extends JedisCommandTestBase {
jedis.lpush("foo", "bar"); jedis.lpush("foo", "bar");
result = jedis.blpop(1, "foo"); result = jedis.blpop(1, "foo");
System.out.println("lalalala");
assertNotNull(result); assertNotNull(result);
assertEquals(2, result.size()); assertEquals(2, result.size());
@@ -433,7 +432,6 @@ public class ListCommandsTest extends JedisCommandTestBase {
// Binary // Binary
jedis.lpush(bfoo, bbar); jedis.lpush(bfoo, bbar);
List<byte[]> bresult = jedis.blpop(1, bfoo); List<byte[]> bresult = jedis.blpop(1, bfoo);
System.out.println("lalalala");
assertNotNull(bresult); assertNotNull(bresult);
assertEquals(2, bresult.size()); assertEquals(2, bresult.size());