jedis monitor should set client socket timeout to infinite
This commit is contained in:
@@ -5,6 +5,7 @@ public abstract class JedisMonitor {
|
|||||||
|
|
||||||
public void proceed(Client client) {
|
public void proceed(Client client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
this.client.setTimeoutInfinite();
|
||||||
do {
|
do {
|
||||||
String command = client.getBulkReply();
|
String command = client.getBulkReply();
|
||||||
onCommand(command);
|
onCommand(command);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import redis.clients.jedis.DebugParams;
|
import redis.clients.jedis.DebugParams;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisMonitor;
|
import redis.clients.jedis.JedisMonitor;
|
||||||
import redis.clients.jedis.exceptions.JedisDataException;
|
import redis.clients.jedis.exceptions.JedisDataException;
|
||||||
|
|
||||||
@@ -56,11 +57,32 @@ public class ControlCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void monitor() {
|
public void monitor() {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
Jedis j = new Jedis("localhost");
|
||||||
|
j.auth("foobared");
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
j.incr("foobared");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(2500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
}
|
||||||
|
j.incr("foobared");
|
||||||
|
j.disconnect();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
jedis.monitor(new JedisMonitor() {
|
jedis.monitor(new JedisMonitor() {
|
||||||
@Override
|
private int count = 0;
|
||||||
|
|
||||||
public void onCommand(String command) {
|
public void onCommand(String command) {
|
||||||
assertTrue(command.contains("OK"));
|
if (command.contains("INCR")) {
|
||||||
client.disconnect();
|
count++;
|
||||||
|
}
|
||||||
|
if (count == 5) {
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user