Change Moved cluster test and add confirmation for jedis cluster tests

This commit is contained in:
Marcos Nils
2013-12-09 15:17:13 -03:00
parent 726c3151b6
commit 0ebbf02c94
2 changed files with 62 additions and 40 deletions

View File

@@ -0,0 +1,17 @@
package redis.clients.jedis.exceptions;
public class JedisAskDataException extends JedisDataException {
private static final long serialVersionUID = 3878126572474819403L;
public JedisAskDataException(String message) {
super(message);
}
public JedisAskDataException(Throwable cause) {
super(cause);
}
public JedisAskDataException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -1,7 +1,5 @@
package redis.clients.jedis.tests; package redis.clients.jedis.tests;
import java.util.HashSet;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@@ -11,6 +9,7 @@ import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.Pipeline; import redis.clients.jedis.Pipeline;
import redis.clients.jedis.exceptions.JedisAskDataException;
import redis.clients.jedis.exceptions.JedisMovedDataException; import redis.clients.jedis.exceptions.JedisMovedDataException;
import redis.clients.jedis.tests.utils.RedisSlot; import redis.clients.jedis.tests.utils.RedisSlot;
@@ -24,7 +23,7 @@ public class JedisClusterTest extends Assert {
private HostAndPort nodeInfo3 = HostAndPortUtil.getClusterServers().get(2); private HostAndPort nodeInfo3 = HostAndPortUtil.getClusterServers().get(2);
@Before @Before
public void setUp() { public void setUp() throws InterruptedException {
node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort()); node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
node1.connect(); node1.connect();
node1.flushAll(); node1.flushAll();
@@ -50,6 +49,14 @@ public class JedisClusterTest extends Assert {
pipelined.clusterAddSlots(i); pipelined.clusterAddSlots(i);
} }
pipelined.sync(); pipelined.sync();
boolean clusterOk = false;
while (!clusterOk) {
if (node1.clusterInfo().split("\n")[0].contains("ok")) {
clusterOk = true;
}
Thread.sleep(100);
}
} }
@After @After
@@ -64,15 +71,13 @@ public class JedisClusterTest extends Assert {
@Test(expected=JedisMovedDataException.class) @Test(expected=JedisMovedDataException.class)
public void throwMovedExceptionTest() { public void throwMovedExceptionTest() {
JedisCluster jc = new JedisCluster(new HashSet<HostAndPort>(HostAndPortUtil.getClusterServers())); node1.set("foo", "bar");
jc.set("foo", "bar"); node2.get("foo");
jc.get("foo");
} }
// @Test // @Test(expected=JedisAskDataException.class)
// public void ask() { // public void ask() {
// JedisCluster jc = new JedisCluster(new HashSet<HostAndPort>(HostAndPortUtil.getClusterServers())); // node1.set("foo", "bar");
// jc.set("foo", "bar");
// int keySlot = RedisSlot.getSlot("foo"); // int keySlot = RedisSlot.getSlot("foo");
// String node2Id = getNodeId(node2.clusterNodes()); // String node2Id = getNodeId(node2.clusterNodes());
// node1.clusterSetSlotMigrating(keySlot, node2Id); // node1.clusterSetSlotMigrating(keySlot, node2Id);