Merge branch 'speed-up-unit-test' of github.com:HeartSaVioR/jedis into upgrade_libs

Conflicts:
	src/test/java/redis/clients/jedis/tests/JedisPoolTest.java
	src/test/java/redis/clients/jedis/tests/JedisSentinelPoolTest.java
	src/test/java/redis/clients/jedis/tests/JedisSentinelTest.java
	src/test/java/redis/clients/jedis/tests/ShardedJedisPipelineTest.java
	src/test/java/redis/clients/jedis/tests/ShardedJedisPoolTest.java
	src/test/java/redis/clients/jedis/tests/benchmark/PoolBenchmark.java
	src/test/java/redis/clients/jedis/tests/commands/TransactionCommandsTest.java
This commit is contained in:
Jonathan Leibiusky
2013-11-29 12:12:30 -05:00
23 changed files with 400 additions and 246 deletions

View File

@@ -1,9 +1,6 @@
package redis.clients.jedis.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -11,25 +8,42 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.tests.utils.JedisSentinelTestUtil;
public class JedisSentinelTest {
public class JedisSentinelTest extends JedisTestBase {
private static final String MASTER_NAME = "mymaster";
protected static HostAndPort master = HostAndPortUtil.getRedisServers()
.get(0);
protected static HostAndPort slave = HostAndPortUtil.getRedisServers().get(
1);
protected static HostAndPort sentinel = HostAndPortUtil
.getSentinelServers().get(0);
protected static Jedis masterJedis;
protected static Jedis slaveJedis;
protected static Jedis sentinelJedis;
@Before
public void setup() throws InterruptedException {
Jedis j = new Jedis("localhost", 6380);
j.auth("foobared");
j.configSet("masterauth", "foobared");
j.slaveof("localhost", 6379);
// TODO: The sleep is to give time to the slave to synchronize with the
// master and also let know the sentinels about this new topology. We
// should find a better way to do this.
Thread.sleep(10000);
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
public void clear() {
public void clear() throws InterruptedException {
Jedis j = new Jedis("localhost", 6380);
j.auth("foobared");
j.slaveofNoOne();
@@ -52,18 +66,8 @@ public class JedisSentinelTest {
assertTrue(slaves.size() > 0);
assertEquals("6379", slaves.get(0).get("master-port"));
List<? extends Object> isMasterDownByAddr = j
.sentinelIsMasterDownByAddr("127.0.0.1", 6379);
assertEquals(Long.valueOf(0), (Long) isMasterDownByAddr.get(0));
assertFalse("?".equals(isMasterDownByAddr.get(1)));
isMasterDownByAddr = j.sentinelIsMasterDownByAddr("127.0.0.1", 1);
assertEquals(Long.valueOf(0), (Long) isMasterDownByAddr.get(0));
assertTrue("?".equals(isMasterDownByAddr.get(1)));
// DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET
assertEquals(Long.valueOf(1), j.sentinelReset(masterName));
assertEquals(Long.valueOf(0), j.sentinelReset("woof" + masterName));
}
}