it might happen that it is alredy saving, so make sure that test won't fail because of this
This commit is contained in:
@@ -12,114 +12,119 @@ import redis.clients.jedis.exceptions.JedisDataException;
|
|||||||
public class ControlCommandsTest extends JedisCommandTestBase {
|
public class ControlCommandsTest extends JedisCommandTestBase {
|
||||||
@Test
|
@Test
|
||||||
public void save() {
|
public void save() {
|
||||||
String status = jedis.save();
|
try {
|
||||||
assertEquals("OK", status);
|
String status = jedis.save();
|
||||||
|
assertEquals("OK", status);
|
||||||
|
} catch (JedisDataException e) {
|
||||||
|
assertTrue("ERR Background save already in progress"
|
||||||
|
.equalsIgnoreCase(e.getMessage()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bgsave() {
|
public void bgsave() {
|
||||||
try {
|
try {
|
||||||
String status = jedis.bgsave();
|
String status = jedis.bgsave();
|
||||||
assertEquals("Background saving started", status);
|
assertEquals("Background saving started", status);
|
||||||
} catch (JedisDataException e) {
|
} catch (JedisDataException e) {
|
||||||
assertTrue("ERR Background save already in progress"
|
assertTrue("ERR Background save already in progress"
|
||||||
.equalsIgnoreCase(e.getMessage()));
|
.equalsIgnoreCase(e.getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bgrewriteaof() {
|
public void bgrewriteaof() {
|
||||||
String scheduled = "Background append only file rewriting scheduled";
|
String scheduled = "Background append only file rewriting scheduled";
|
||||||
String started = "Background append only file rewriting started";
|
String started = "Background append only file rewriting started";
|
||||||
|
|
||||||
String status = jedis.bgrewriteaof();
|
String status = jedis.bgrewriteaof();
|
||||||
|
|
||||||
boolean ok = status.equals(scheduled) || status.equals(started);
|
boolean ok = status.equals(scheduled) || status.equals(started);
|
||||||
assertTrue(ok);
|
assertTrue(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void lastsave() throws InterruptedException {
|
public void lastsave() throws InterruptedException {
|
||||||
long before = jedis.lastsave();
|
long before = jedis.lastsave();
|
||||||
String st = "";
|
String st = "";
|
||||||
while (!st.equals("OK")) {
|
while (!st.equals("OK")) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
st = jedis.save();
|
st = jedis.save();
|
||||||
} catch (JedisDataException e) {
|
} catch (JedisDataException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
long after = jedis.lastsave();
|
long after = jedis.lastsave();
|
||||||
assertTrue((after - before) > 0);
|
assertTrue((after - before) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void info() {
|
public void info() {
|
||||||
String info = jedis.info();
|
String info = jedis.info();
|
||||||
assertNotNull(info);
|
assertNotNull(info);
|
||||||
info = jedis.info("server");
|
info = jedis.info("server");
|
||||||
assertNotNull(info);
|
assertNotNull(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void monitor() {
|
public void monitor() {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Jedis j = new Jedis("localhost");
|
Jedis j = new Jedis("localhost");
|
||||||
j.auth("foobared");
|
j.auth("foobared");
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
j.incr("foobared");
|
j.incr("foobared");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(2500);
|
Thread.sleep(2500);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
}
|
}
|
||||||
j.incr("foobared");
|
j.incr("foobared");
|
||||||
j.disconnect();
|
j.disconnect();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
jedis.monitor(new JedisMonitor() {
|
jedis.monitor(new JedisMonitor() {
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
public void onCommand(String command) {
|
public void onCommand(String command) {
|
||||||
if (command.contains("INCR")) {
|
if (command.contains("INCR")) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (count == 5) {
|
if (count == 5) {
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void configGet() {
|
public void configGet() {
|
||||||
List<String> info = jedis.configGet("m*");
|
List<String> info = jedis.configGet("m*");
|
||||||
assertNotNull(info);
|
assertNotNull(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void configSet() {
|
public void configSet() {
|
||||||
List<String> info = jedis.configGet("maxmemory");
|
List<String> info = jedis.configGet("maxmemory");
|
||||||
String memory = info.get(1);
|
String memory = info.get(1);
|
||||||
String status = jedis.configSet("maxmemory", "200");
|
String status = jedis.configSet("maxmemory", "200");
|
||||||
assertEquals("OK", status);
|
assertEquals("OK", status);
|
||||||
jedis.configSet("maxmemory", memory);
|
jedis.configSet("maxmemory", memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void sync() {
|
public void sync() {
|
||||||
jedis.sync();
|
jedis.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void debug() {
|
public void debug() {
|
||||||
jedis.set("foo", "bar");
|
jedis.set("foo", "bar");
|
||||||
String resp = jedis.debug(DebugParams.OBJECT("foo"));
|
String resp = jedis.debug(DebugParams.OBJECT("foo"));
|
||||||
assertNotNull(resp);
|
assertNotNull(resp);
|
||||||
resp = jedis.debug(DebugParams.RELOAD());
|
resp = jedis.debug(DebugParams.RELOAD());
|
||||||
assertNotNull(resp);
|
assertNotNull(resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user