forked from noise/redis-sentinel-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.java
64 lines (57 loc) · 1.44 KB
/
Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import redis.clients.jedis.*;
import java.util.Date;
public class Test {
public static void main(String argv[]) {
String host = "localhost";
try {
host = argv[0];
}
catch (Exception e) {}
Long sleepMillis = 50L;
try {
sleepMillis = Long.parseLong(argv[1]);
}
catch (Exception e) {}
JedisPoolConfig conf = new JedisPoolConfig();
conf.setMaxWait(1000);
conf.setTestOnBorrow(true);
conf.setMaxActive(10);
System.out.println("starting pool for host " + host);
JedisPool pool = new JedisPool(conf, host, 6379, 1000, null);
Jedis jedis = null;
int i=0;
int fails = 0;
long downTime = 0;
while (true) {
try {
Thread.currentThread().sleep(sleepMillis);
jedis = pool.getResource();
jedis.set("foo", "bar");
String value = jedis.get("foo");
System.out.print(".");
if (i++ % 100 == 0) {
System.out.println("\n" + new Date());
}
if (fails != 0) {
long duration = System.currentTimeMillis() - downTime;
System.out.println("\n" + new Date() + ", SERVER UP, was down for " + duration + "ms, failed commands: " + fails);
fails = 0;
}
}
catch(Exception e) {
if (fails == 0) {
downTime = System.currentTimeMillis();
System.out.println("\n" + new Date() + ", SERVER DOWN");
}
fails++;
//System.out.println("\n" + new Date() + ", " + e.getMessage());
System.out.print("x");
}
finally {
if (jedis != null) {
pool.returnResource(jedis);
}
}
}
}
}