Fix sentinel test not to be so sensitive to time

This commit is contained in:
Jonathan Leibiusky
2014-01-16 20:37:47 -05:00
parent 424ae75c7d
commit 23b54c2cef
3 changed files with 136 additions and 134 deletions

View File

@@ -188,6 +188,7 @@ stop:
test:
make start
sleep 2
mvn -Dtest=${TEST} clean compile test
make stop

View File

@@ -66,11 +66,9 @@ public class JedisClusterTest extends Assert {
pipeline2.sync();
pipeline3.sync();
waitForClusterReady();
}
@After
public void tearDown() {
// clear all slots
@@ -83,7 +81,7 @@ public class JedisClusterTest extends Assert {
node3.clusterDelSlots(slotsToDelete);
}
@Test(expected=JedisMovedDataException.class)
@Test(expected = JedisMovedDataException.class)
public void testThrowMovedException() {
node1.set("foo", "bar");
}
@@ -94,12 +92,14 @@ public class JedisClusterTest extends Assert {
node1.set("foo", "bar");
} catch (JedisMovedDataException jme) {
assertEquals(12182, jme.getSlot());
assertEquals(new HostAndPort("127.0.0.1", 7381), jme.getTargetNode());
assertEquals(new HostAndPort("127.0.0.1", 7381),
jme.getTargetNode());
return;
}
fail();
}
@Test(expected=JedisAskDataException.class)
@Test(expected = JedisAskDataException.class)
public void testThrowAskException() {
int keySlot = JedisClusterCRC16.getSlot("test");
String node3Id = getNodeId(node3.clusterNodes());
@@ -122,8 +122,8 @@ public class JedisClusterTest extends Assert {
JedisCluster jc = new JedisCluster(jedisClusterNode);
jc.set("foo", "bar");
jc.set("test", "test");
assertEquals("bar",node3.get("foo"));
assertEquals("test",node2.get("test"));
assertEquals("bar", node3.get("foo"));
assertEquals("test", node2.get("test"));
}
@Test
@@ -153,7 +153,7 @@ public class JedisClusterTest extends Assert {
assertEquals("foo", jc.get("51"));
}
@Test(expected=JedisClusterException.class)
@Test(expected = JedisClusterException.class)
public void testThrowExceptionWithoutKey() {
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
@@ -161,13 +161,13 @@ public class JedisClusterTest extends Assert {
jc.ping();
}
@Test(expected=JedisClusterMaxRedirectionsException.class)
@Test(expected = JedisClusterMaxRedirectionsException.class)
public void testRedisClusterMaxRedirections() {
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
JedisCluster jc = new JedisCluster(jedisClusterNode);
int slot51 = JedisClusterCRC16.getSlot("51");
//This will cause an infinite redirection loop
// This will cause an infinite redirection loop
node2.clusterSetSlotMigrating(slot51, getNodeId(node3.clusterNodes()));
jc.set("51", "foo");
}
@@ -184,9 +184,9 @@ public class JedisClusterTest extends Assert {
private void waitForClusterReady() throws InterruptedException {
boolean clusterOk = false;
while (!clusterOk) {
if (node1.clusterInfo().split("\n")[0].contains("ok") &&
node2.clusterInfo().split("\n")[0].contains("ok") &&
node3.clusterInfo().split("\n")[0].contains("ok") ) {
if (node1.clusterInfo().split("\n")[0].contains("ok")
&& node2.clusterInfo().split("\n")[0].contains("ok")
&& node3.clusterInfo().split("\n")[0].contains("ok")) {
clusterOk = true;
}
Thread.sleep(50);

View File

@@ -69,6 +69,7 @@ public class JedisSentinelPoolTest extends JedisTestBase {
}
waitForFailover(pool, oldMaster);
Thread.sleep(100);
jedis = pool.getResource();
assertEquals("PONG", jedis.ping());