1 package voldemort
.client
;
3 import static org
.junit
.Assert
.assertFalse
;
4 import static org
.junit
.Assert
.fail
;
6 import java
.lang
.management
.ManagementFactory
;
7 import java
.util
.ArrayList
;
8 import java
.util
.Arrays
;
9 import java
.util
.Collection
;
10 import java
.util
.List
;
13 import javax
.management
.MBeanServer
;
14 import javax
.management
.ObjectName
;
16 import org
.junit
.After
;
17 import org
.junit
.Before
;
18 import org
.junit
.Test
;
19 import org
.junit
.runners
.Parameterized
.Parameters
;
21 import voldemort
.utils
.JmxUtils
;
25 * Smoke test to see how many Mbeans we create in each monitoring domain
28 public class SocketStoreClientFactoryMbeanTest
extends SocketStoreClientFactoryTest
{
30 // there should one of these per store (that has a store client), per
32 private static String STATS_DOMAIN
= "voldemort.store.stats";
33 private static String AGGREGATE_STATS_DOMAIN
= "voldemort.store.stats.aggregate";
34 private static String PIPELINE_ROUTED_STATS_DOMAIN
= "voldemort.store.routed";
36 // there should one of these per factory
37 private static String CLIENT_DOMAIN
= "voldemort.client";
38 private static String CLUSTER_FAILUREDETECTOR_DOMAIN
= "voldemort.cluster.failuredetector";
40 // there should be one of these per factory per host in the cluster the
41 // factory talks to (plus one aggregate)
42 private static String CLIENT_REQUEST_DOMAIN
= "voldemort.store.socket.clientrequest";
44 private MBeanServer mbServer
= null;
45 // list of factory objects to be closed at the end.
46 private List
<StoreClientFactory
> factories
;
48 public SocketStoreClientFactoryMbeanTest(boolean useNio
, boolean useLazy
) {
49 super(useNio
, useLazy
);
54 public void setUp() throws Exception
{
56 mbServer
= ManagementFactory
.getPlatformMBeanServer();
57 factories
= new ArrayList
<StoreClientFactory
>();
62 public void tearDown() throws Exception
{
64 for(StoreClientFactory factory
: factories
)
71 public static Collection
<Object
[]> configs() {
72 return Arrays
.asList(new Object
[][] { { true, false } });
75 private void checkMbeanIdCount(String domain
, String type
, int maxMbeans
, boolean unregister
) {
76 ObjectName oName
= JmxUtils
.createObjectName(domain
, type
);
77 Set
<ObjectName
> objects
= mbServer
.queryNames(oName
, null);
78 String messagePrefix
= "Domain " + domain
+ " expected Size " + maxMbeans
+ " actual size "
80 assertFalse(messagePrefix
+ ". Extra mbeans found", objects
.size() > maxMbeans
);
81 assertFalse(messagePrefix
+ ". Fewer than expected mbeans found",
82 objects
.size() < maxMbeans
);
86 for(ObjectName objName
: objects
)
87 mbServer
.unregisterMBean(objName
);
88 } catch(Exception e
) {
89 fail("Problem unregistering mbeans " + e
.getMessage());
94 private void bootStrap(List
<DefaultStoreClient
<Object
, Object
>> clients
, int n
) {
95 for(int i
= 0; i
< n
; i
++) {
96 for(DefaultStoreClient
<Object
, Object
> client
: clients
)
102 public void testMultipleDistinctClientsOnSingleFactory() {
104 StoreClientFactory factory
= getFactory(getValidBootstrapUrl());
105 List
<DefaultStoreClient
<Object
, Object
>> clients
= new ArrayList
<DefaultStoreClient
<Object
, Object
>>();
107 clients
.add((DefaultStoreClient
<Object
, Object
>) factory
.getStoreClient("test"));
108 clients
.add((DefaultStoreClient
<Object
, Object
>) factory
.getStoreClient("best"));
109 factories
.add(factory
);
111 // bootstrap a number of times
112 bootStrap(clients
, 10);
114 checkMbeanIdCount(CLIENT_DOMAIN
, "ClientThreadPool*", 1, true);
115 checkMbeanIdCount(CLIENT_DOMAIN
, "*StoreClient*", 2, true);
116 checkMbeanIdCount(CLUSTER_FAILUREDETECTOR_DOMAIN
, "ThresholdFailureDetector*", 1, true);
117 checkMbeanIdCount(PIPELINE_ROUTED_STATS_DOMAIN
, "*", 2, true);
118 checkMbeanIdCount(CLIENT_REQUEST_DOMAIN
, "aggregated*", 1, true);
119 checkMbeanIdCount(CLIENT_REQUEST_DOMAIN
, "stats_localhost*", 1, true);
120 checkMbeanIdCount(AGGREGATE_STATS_DOMAIN
, "aggregate-perf*", 1, true);
121 checkMbeanIdCount(STATS_DOMAIN
, "*", 2, true);
123 } catch(Exception e
) {
124 fail("Unexpected error " + e
.getMessage());
129 public void testMultipleIndistinctClientsOnSingleFactory() {
131 StoreClientFactory factory
= getFactory(getValidBootstrapUrl());
132 List
<DefaultStoreClient
<Object
, Object
>> clients
= new ArrayList
<DefaultStoreClient
<Object
, Object
>>();
134 clients
.add((DefaultStoreClient
<Object
, Object
>) factory
.getStoreClient("test"));
135 clients
.add((DefaultStoreClient
<Object
, Object
>) factory
.getStoreClient("best"));
136 clients
.add((DefaultStoreClient
<Object
, Object
>) factory
.getStoreClient("test"));
137 clients
.add((DefaultStoreClient
<Object
, Object
>) factory
.getStoreClient("best"));
138 factories
.add(factory
);
140 // bootstrap a number of times
141 bootStrap(clients
, 10);
143 checkMbeanIdCount(CLIENT_DOMAIN
, "ClientThreadPool*", 1, true);
144 checkMbeanIdCount(CLIENT_DOMAIN
, "*StoreClient*", 2, true);
145 checkMbeanIdCount(CLUSTER_FAILUREDETECTOR_DOMAIN
, "ThresholdFailureDetector*", 1, true);
146 checkMbeanIdCount(PIPELINE_ROUTED_STATS_DOMAIN
, "*", 2, true);
147 checkMbeanIdCount(CLIENT_REQUEST_DOMAIN
, "aggregated*", 1, true);
148 checkMbeanIdCount(CLIENT_REQUEST_DOMAIN
, "stats_localhost*", 1, true);
149 checkMbeanIdCount(AGGREGATE_STATS_DOMAIN
, "aggregate-perf*", 1, true);
150 checkMbeanIdCount(STATS_DOMAIN
, "*", 2, true);
152 } catch(Exception e
) {
153 fail("Unexpected error " + e
.getMessage());
158 public void testMultipleDistinctClientsOnMultipleFactories() {
160 StoreClientFactory testfactory
= getFactory(getValidBootstrapUrl());
161 List
<DefaultStoreClient
<Object
, Object
>> clients
= new ArrayList
<DefaultStoreClient
<Object
, Object
>>();
162 clients
.add((DefaultStoreClient
<Object
, Object
>) testfactory
.getStoreClient("test"));
163 StoreClientFactory bestfactory
= getFactory(getValidBootstrapUrl());
164 clients
.add((DefaultStoreClient
<Object
, Object
>) bestfactory
.getStoreClient("best"));
165 factories
.add(testfactory
);
166 factories
.add(bestfactory
);
168 // bootstrap a number of times
169 bootStrap(clients
, 10);
171 checkMbeanIdCount(CLIENT_DOMAIN
, "ClientThreadPool*", 2, true);
172 checkMbeanIdCount(CLIENT_DOMAIN
, "*StoreClient*", 2, true);
173 checkMbeanIdCount(CLUSTER_FAILUREDETECTOR_DOMAIN
, "ThresholdFailureDetector*", 2, true);
174 checkMbeanIdCount(PIPELINE_ROUTED_STATS_DOMAIN
, "*", 2, true);
175 checkMbeanIdCount(CLIENT_REQUEST_DOMAIN
, "aggregated*", 2, true);
176 checkMbeanIdCount(CLIENT_REQUEST_DOMAIN
, "stats_localhost*", 2, true);
177 checkMbeanIdCount(AGGREGATE_STATS_DOMAIN
, "aggregate-perf*", 2, true);
178 checkMbeanIdCount(STATS_DOMAIN
, "*", 2, true);
180 } catch(Exception e
) {
181 fail("Unexpected error " + e
.getMessage());
186 public void testMultipleInDistinctClientsOnMultipleFactories() {
188 StoreClientFactory factory1
= getFactory(getValidBootstrapUrl());
189 List
<DefaultStoreClient
<Object
, Object
>> clients
= new ArrayList
<DefaultStoreClient
<Object
, Object
>>();
190 clients
.add((DefaultStoreClient
<Object
, Object
>) factory1
.getStoreClient("test"));
191 clients
.add((DefaultStoreClient
<Object
, Object
>) factory1
.getStoreClient("test"));
192 clients
.add((DefaultStoreClient
<Object
, Object
>) factory1
.getStoreClient("best"));
193 clients
.add((DefaultStoreClient
<Object
, Object
>) factory1
.getStoreClient("best"));
194 factories
.add(factory1
);
196 StoreClientFactory factory2
= getFactory(getValidBootstrapUrl());
197 clients
.add((DefaultStoreClient
<Object
, Object
>) factory2
.getStoreClient("test"));
198 clients
.add((DefaultStoreClient
<Object
, Object
>) factory2
.getStoreClient("test"));
199 clients
.add((DefaultStoreClient
<Object
, Object
>) factory2
.getStoreClient("best"));
200 clients
.add((DefaultStoreClient
<Object
, Object
>) factory2
.getStoreClient("best"));
201 factories
.add(factory2
);
203 // bootstrap a number of times
204 bootStrap(clients
, 10);
206 checkMbeanIdCount(CLIENT_DOMAIN
, "ClientThreadPool*", 2, true);
207 checkMbeanIdCount(CLIENT_DOMAIN
, "*StoreClient*", 2, true);
208 checkMbeanIdCount(CLUSTER_FAILUREDETECTOR_DOMAIN
, "ThresholdFailureDetector*", 2, true);
209 checkMbeanIdCount(PIPELINE_ROUTED_STATS_DOMAIN
, "*", 4, true);
210 checkMbeanIdCount(CLIENT_REQUEST_DOMAIN
, "aggregated*", 2, true);
211 checkMbeanIdCount(CLIENT_REQUEST_DOMAIN
, "stats_localhost*", 2, true);
212 checkMbeanIdCount(AGGREGATE_STATS_DOMAIN
, "aggregate-perf*", 2, true);
213 checkMbeanIdCount(STATS_DOMAIN
, "*", 4, true);
215 } catch(Exception e
) {
216 fail("Unexpected error " + e
.getMessage());