/
TapTest.java
108 lines (95 loc) · 2.84 KB
/
TapTest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package net.spy.memcached;
import java.net.URI;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import net.spy.memcached.tapmessage.ResponseMessage;
public class TapTest extends ClientBaseCase {
private static final long TAP_DUMP_TIMEOUT = 2000;
@Override
protected void initClient() throws Exception {
initClient(new BinaryConnectionFactory() {
@Override
public long getOperationTimeout() {
return 15000;
}
@Override
public FailureMode getFailureMode() {
return FailureMode.Retry;
}
});
}
public void testBackfill() throws Exception {
if (TestConfig.isMembase()) {
TapClient tc = new TapClient(AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11210"));
tc.tapBackfill(null, 5, TimeUnit.SECONDS);
HashMap<String, Boolean> items = new HashMap<String, Boolean>();
for (int i = 0; i < 25; i++) {
client.set("key" + i, 0, "value" + i);
items.put("key" + i + ",value" + i, new Boolean(false));
}
while(tc.hasMoreMessages()) {
ResponseMessage m;
if ((m = tc.getNextMessage()) != null) {
String key = m.getKey() + "," + new String(m.getValue());
if (items.containsKey(key)) {
items.put(key, new Boolean(true));
} else {
fail();
}
}
}
checkTapKeys(items);
assertTrue(client.flush().get().booleanValue());
}
}
public void testTapDump() throws Exception {
if (TestConfig.isMembase()) {
TapClient tc = new TapClient(AddrUtil.getAddresses(TestConfig.IPV4_ADDR + ":11210"));
HashMap<String, Boolean> items = new HashMap<String, Boolean>();
for (int i = 0; i < 25; i++) {
client.set("key" + i, 0, "value" + i).get();
items.put("key" + i + ",value" + i, new Boolean(false));
}
tc.tapDump(null);
long st = System.currentTimeMillis();
while(tc.hasMoreMessages()) {
if ((System.currentTimeMillis() - st) > TAP_DUMP_TIMEOUT) {
fail("Tap dump took too long");
}
ResponseMessage m;
if ((m = tc.getNextMessage()) != null) {
String key = m.getKey() + "," + new String(m.getValue());
if (items.containsKey(key)) {
items.put(key, new Boolean(true));
} else {
fail();
}
}
}
checkTapKeys(items);
assertTrue(client.flush().get().booleanValue());
}
}
public void testTapBucketDoesNotExist() throws Exception {
if (TestConfig.isMembase()) {
TapClient client = new TapClient(Arrays.asList(
new URI("http://" + TestConfig.IPV4_ADDR + ":8091/pools")),
"abucket", "abucket", "apassword");
try {
client.tapBackfill(null, 5, TimeUnit.SECONDS);
} catch (RuntimeException e) {
System.err.println(e.getMessage());
return;
}
}
}
private void checkTapKeys(HashMap<String, Boolean> items) {
for (Entry<String, Boolean> kv : items.entrySet()) {
if (!kv.getValue().booleanValue()) {
fail();
}
}
}
}