forked from voldemort/voldemort
/
ClientJmxTest.java
341 lines (299 loc) · 17.2 KB
/
ClientJmxTest.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package voldemort.client;
import java.lang.management.ManagementFactory;
import java.net.URISyntaxException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import voldemort.ServerTestUtils;
import voldemort.serialization.SerializerFactory;
import voldemort.server.AbstractSocketService;
import voldemort.utils.JmxUtils;
public class ClientJmxTest extends AbstractStoreClientFactoryTest {
private static String STATS_DOMAIN = "voldemort.store.stats";
private static String AGGREGATE_STATS_DOMAIN = "voldemort.store.stats.aggregate";
private static String CLIENT_DOMAIN = "voldemort.client";
private static String CLUSTER_FAILUREDETECTOR_DOMAIN = "voldemort.cluster.failuredetector";
private static String CLIENT_REQUEST_DOMAIN = "voldemort.store.socket.clientrequest";
private AbstractSocketService socketService;
private MBeanServer mbServer = null;
private static int factoryJmxId = 0;
public ClientJmxTest() {
super();
}
private static String getAndIncrementJmxId() {
int current = factoryJmxId;
factoryJmxId++;
return (0 == current ? "" : "" + current);
}
@Override
@Before
public void setUp() throws Exception {
super.setUp();
socketService = ServerTestUtils.getSocketService(true,
getClusterXml(),
getStoreDefXml(),
getValidStoreName(),
getLocalNode().getSocketPort());
socketService.start();
mbServer = ManagementFactory.getPlatformMBeanServer();
}
@Override
@After
public void tearDown() throws Exception {
mbServer = null;
super.tearDown();
socketService.stop();
}
@Override
protected StoreClientFactory getFactory(String... bootstrapUrls) {
return new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrls)
.setEnableLazy(false)
.setEnableJmx(true));
}
protected StoreClientFactory getFactoryWithClientContext(String clientContext,
String... bootstrapUrls) {
return new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrls)
.setEnableLazy(false)
.setClientContextName(clientContext)
.setEnableJmx(true));
}
@Test
public void testTwoClientContextOnJmx() throws Exception {
String clientContext1 = "clientA";
String clientContext2 = "clientB";
String jmxId1 = getAndIncrementJmxId();
String jmxId2 = getAndIncrementJmxId();
StoreClient<Object, Object> c1 = getFactoryWithClientContext(clientContext1,
getValidBootstrapUrl()).getStoreClient(getValidStoreName());
StoreClient<Object, Object> c2 = getFactoryWithClientContext(clientContext2,
getValidBootstrapUrl()).getStoreClient(getValidStoreName());
// checking for aggregate stats
ObjectName c1Name = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContext1
+ ".aggregate-perf"
+ jmxId1);
ObjectName c2Name = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContext2
+ ".aggregate-perf"
+ jmxId2);
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
mbServer.unregisterMBean(c1Name);
mbServer.unregisterMBean(c2Name);
// checking for per store stats
String c1type = clientContext1 + ".test" + jmxId1;
String c2type = clientContext2 + ".test" + jmxId2;
c1Name = JmxUtils.createObjectName(STATS_DOMAIN,
c1type
+ "."
+ ((DefaultStoreClient<Object, Object>) c1).getClientId()
.toString());
c2Name = JmxUtils.createObjectName(STATS_DOMAIN,
c2type
+ "."
+ ((DefaultStoreClient<Object, Object>) c2).getClientId()
.toString());
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
mbServer.unregisterMBean(c1Name);
mbServer.unregisterMBean(c2Name);
}
@Test
public void testSameContextOnJmx() throws Exception {
String clientContext = "clientContext";
String jmxId1 = getAndIncrementJmxId();
String jmxId2 = getAndIncrementJmxId();
StoreClient<Object, Object>[] clients = new StoreClient[2];
for(int i = 0; i < 2; i++) {
clients[i] = getFactoryWithClientContext(clientContext, getValidBootstrapUrl()).getStoreClient(getValidStoreName());
}
// checking for aggregate stats
ObjectName c1Name = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContext
+ ".aggregate-perf"
+ jmxId1);
ObjectName c2Name = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContext
+ ".aggregate-perf"
+ jmxId2);
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
mbServer.unregisterMBean(c1Name);
mbServer.unregisterMBean(c2Name);
// checking for per store stats
String c1type = clientContext + ".test" + jmxId1;
String c2type = clientContext + ".test" + jmxId2;
c1Name = JmxUtils.createObjectName(STATS_DOMAIN,
c1type
+ "."
+ ((DefaultStoreClient<Object, Object>) clients[0]).getClientId()
.toString());
c2Name = JmxUtils.createObjectName(STATS_DOMAIN,
c2type
+ "."
+ ((DefaultStoreClient<Object, Object>) clients[1]).getClientId()
.toString());
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
mbServer.unregisterMBean(c1Name);
mbServer.unregisterMBean(c2Name);
}
@Test
public void testTwoClientNoContextOnJmx() throws Exception {
String clientContextCompare = "default";
String jmxId1 = getAndIncrementJmxId();
String jmxId2 = getAndIncrementJmxId();
StoreClient<Object, Object> c1 = getFactory(getValidBootstrapUrl()).getStoreClient(getValidStoreName());
StoreClient<Object, Object> c2 = getFactory(getValidBootstrapUrl()).getStoreClient(getValidStoreName());
// checking for aggregate stats
ObjectName c1Name = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContextCompare
+ ".aggregate-perf"
+ jmxId1);
ObjectName c2Name = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContextCompare
+ ".aggregate-perf"
+ jmxId2);
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
mbServer.unregisterMBean(c1Name);
mbServer.unregisterMBean(c2Name);
// checking for per store stats
String c1type = clientContextCompare + ".test" + jmxId1;
String c2type = clientContextCompare + ".test" + jmxId2;
c1Name = JmxUtils.createObjectName(STATS_DOMAIN,
c1type
+ "."
+ ((DefaultStoreClient<Object, Object>) c1).getClientId()
.toString());
c2Name = JmxUtils.createObjectName(STATS_DOMAIN,
c2type
+ "."
+ ((DefaultStoreClient<Object, Object>) c2).getClientId()
.toString());
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
mbServer.unregisterMBean(c1Name);
mbServer.unregisterMBean(c2Name);
}
@Test
public void testTwoClientNullContextOnJmx() throws Exception {
String clientContextCompare = "";
String jmxId1 = getAndIncrementJmxId();
String jmxId2 = getAndIncrementJmxId();
StoreClient<Object, Object> c1 = getFactoryWithClientContext(null, getValidBootstrapUrl()).getStoreClient(getValidStoreName());
StoreClient<Object, Object> c2 = getFactoryWithClientContext(null, getValidBootstrapUrl()).getStoreClient(getValidStoreName());
// checking for aggregate stats
ObjectName c1Name = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContextCompare
+ ".aggregate-perf"
+ jmxId1);
ObjectName c2Name = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContextCompare
+ ".aggregate-perf"
+ jmxId2);
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
mbServer.unregisterMBean(c1Name);
mbServer.unregisterMBean(c2Name);
// checking for per store stats
String c1type = clientContextCompare + ".test" + jmxId1;
String c2type = clientContextCompare + ".test" + jmxId2;
c1Name = JmxUtils.createObjectName(STATS_DOMAIN,
c1type
+ "."
+ ((DefaultStoreClient<Object, Object>) c1).getClientId()
.toString());
c2Name = JmxUtils.createObjectName(STATS_DOMAIN,
c2type
+ "."
+ ((DefaultStoreClient<Object, Object>) c2).getClientId()
.toString());
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
mbServer.unregisterMBean(c1Name);
mbServer.unregisterMBean(c2Name);
}
@Test
public void testSameContextAndFactory() throws Exception {
String clientContext = "clientContext";
String jmxId = getAndIncrementJmxId();
StoreClientFactory factory = getFactoryWithClientContext(clientContext,
getValidBootstrapUrl());
StoreClient<Object, Object>[] clients = new StoreClient[2];
for(int i = 0; i < 2; i++) {
clients[i] = factory.getStoreClient(getValidStoreName());
}
ObjectName cName = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContext
+ ".aggregate-perf"
+ jmxId);
checkForMbeanFound(cName);
mbServer.unregisterMBean(cName);
// checking for per store stats
String ctype = clientContext + ".test" + jmxId;
ObjectName c1Name = JmxUtils.createObjectName(STATS_DOMAIN,
ctype
+ "."
+ ((DefaultStoreClient<Object, Object>) clients[0]).getClientId()
.toString());
ObjectName c2Name = JmxUtils.createObjectName(STATS_DOMAIN,
ctype
+ "."
+ ((DefaultStoreClient<Object, Object>) clients[1]).getClientId()
.toString());
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
mbServer.unregisterMBean(c1Name);
}
@Test
public void testDifferentId() throws Exception {
String clientContext = "clientContext";
String jmxId = getAndIncrementJmxId();
StoreClientFactory factory = getFactoryWithClientContext(clientContext,
getValidBootstrapUrl());
StoreClient<Object, Object>[] clients = new StoreClient[2];
clients[0] = factory.getStoreClient(getValidStoreName());
clients[1] = factory.getStoreClient(getValidStoreName());
ObjectName cName = JmxUtils.createObjectName(AGGREGATE_STATS_DOMAIN, clientContext
+ ".aggregate-perf"
+ jmxId);
checkForMbeanFound(cName);
mbServer.unregisterMBean(cName);
// checking for per store stats
String ctype = clientContext + ".test" + jmxId;
ObjectName c1Name = JmxUtils.createObjectName(STATS_DOMAIN,
ctype
+ "."
+ ((DefaultStoreClient<Object, Object>) clients[0]).getClientId()
.toString());
ObjectName c2Name = JmxUtils.createObjectName(STATS_DOMAIN,
ctype
+ "."
+ ((DefaultStoreClient<Object, Object>) clients[1]).getClientId()
.toString());
checkForMbeanFound(c1Name);
checkForMbeanFound(c2Name);
assertTrue(!c1Name.equals(c2Name));
mbServer.unregisterMBean(c1Name);
mbServer.unregisterMBean(c2Name);
}
private void checkForMbeanFound(ObjectName name) {
try {
mbServer.getMBeanInfo(name);
} catch(InstanceNotFoundException e) {
fail("MBean not found on the JMX Server: " + name.toString());
} catch(Exception e) {
fail("Test failed: " + e.getMessage());
}
}
@Override
protected StoreClientFactory getFactoryWithSerializer(SerializerFactory factory,
String... bootstrapUrls) {
return new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrls)
.setEnableLazy(false)
.setSerializerFactory(factory));
}
@Override
protected String getValidBootstrapUrl() throws URISyntaxException {
return getLocalNode().getSocketUrl().toString();
}
@Override
protected String getValidScheme() {
return SocketStoreClientFactory.URL_SCHEME;
}
}