Change the way we test sentinel commands so it is automatic
This commit is contained in:
16
Makefile
16
Makefile
@@ -12,15 +12,31 @@ requirepass foobared
|
|||||||
pidfile /tmp/redis2.pid
|
pidfile /tmp/redis2.pid
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
|
||||||
|
define REDIS_SENTINEL1
|
||||||
|
port 26379
|
||||||
|
daemonize yes
|
||||||
|
sentinel monitor mymaster 127.0.0.1 6379 2
|
||||||
|
sentinel auth-pass mymaster foobared
|
||||||
|
sentinel down-after-milliseconds mymaster 5000
|
||||||
|
sentinel failover-timeout mymaster 900000
|
||||||
|
sentinel can-failover mymaster yes
|
||||||
|
sentinel parallel-syncs mymaster 1
|
||||||
|
pidfile /tmp/sentinel1.pid
|
||||||
|
endef
|
||||||
|
|
||||||
export REDIS1_CONF
|
export REDIS1_CONF
|
||||||
export REDIS2_CONF
|
export REDIS2_CONF
|
||||||
|
export REDIS_SENTINEL1
|
||||||
test:
|
test:
|
||||||
echo "$$REDIS1_CONF" | redis-server -
|
echo "$$REDIS1_CONF" | redis-server -
|
||||||
echo "$$REDIS2_CONF" | redis-server -
|
echo "$$REDIS2_CONF" | redis-server -
|
||||||
|
echo "$$REDIS_SENTINEL1" | redis-sentinel -
|
||||||
|
|
||||||
mvn clean compile test
|
mvn clean compile test
|
||||||
|
|
||||||
kill `cat /tmp/redis1.pid`
|
kill `cat /tmp/redis1.pid`
|
||||||
kill `cat /tmp/redis2.pid`
|
kill `cat /tmp/redis2.pid`
|
||||||
|
kill `cat /tmp/sentinel1.pid`
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
|||||||
@@ -1,22 +1,40 @@
|
|||||||
package redis.clients.jedis.tests;
|
package redis.clients.jedis.tests;
|
||||||
|
|
||||||
import static junit.framework.Assert.*;
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
import static junit.framework.Assert.assertFalse;
|
||||||
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
public class JedisSentinelTest {
|
public class JedisSentinelTest {
|
||||||
|
|
||||||
private static final String MASTER_NAME = "mymaster";
|
private static final String MASTER_NAME = "mymaster";
|
||||||
|
|
||||||
/**
|
@Before
|
||||||
* Based on redis/master/slave/sentinel configs from
|
public void setup() throws InterruptedException {
|
||||||
* https://github.com/noise/redis-sentinel-tests.
|
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(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void clear() {
|
||||||
|
Jedis j = new Jedis("localhost", 6380);
|
||||||
|
j.auth("foobared");
|
||||||
|
j.slaveofNoOne();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sentinel() {
|
public void sentinel() {
|
||||||
Jedis j = new Jedis("localhost", 26379);
|
Jedis j = new Jedis("localhost", 26379);
|
||||||
@@ -45,5 +63,6 @@ public class JedisSentinelTest {
|
|||||||
// 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));
|
||||||
assertEquals(Long.valueOf(0), j.sentinelReset("woof" + masterName));
|
assertEquals(Long.valueOf(0), j.sentinelReset("woof" + masterName));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user