Permalink
Browse files

Revert "add clientId for voldemort client" - change in interface for

StoreClientFactory might break things for now.

This reverts commit ddded7c.
  • Loading branch information...
1 parent a1873ab commit 75906be0869786d5af7905079fec48f43cf35337 Chinmay Soman committed Apr 12, 2012
View
77 src/java/voldemort/client/AbstractStoreClientFactory.java
@@ -16,17 +16,12 @@
package voldemort.client;
-import java.io.File;
-import java.io.IOException;
import java.io.StringReader;
-import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
-import java.net.UnknownHostException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -103,8 +98,6 @@
private final ClientConfig config;
private final RoutedStoreFactory routedStoreFactory;
private final int clientZoneId;
- private final String clientContextName;
- private final AtomicInteger sequencer;
public AbstractStoreClientFactory(ClientConfig config) {
this.config = config;
@@ -119,24 +112,18 @@ public AbstractStoreClientFactory(ClientConfig config) {
this.maxBootstrapRetries = config.getMaxBootstrapRetries();
this.stats = new StoreStats();
this.clientZoneId = config.getClientZoneId();
- this.clientContextName = (null == config.getClientContextName() ? ""
- : config.getClientContextName());
this.routedStoreFactory = new RoutedStoreFactory(config.isPipelineRoutedStoreEnabled(),
threadPool,
config.getRoutingTimeout(TimeUnit.MILLISECONDS));
- this.sequencer = new AtomicInteger(0);
if(this.isJmxEnabled) {
JmxUtils.registerMbean(threadPool,
JmxUtils.createObjectName(JmxUtils.getPackageName(threadPool.getClass()),
JmxUtils.getClassName(threadPool.getClass())
- + "."
- + clientContextName
+ jmxId()));
JmxUtils.registerMbean(new StoreStatsJmx(stats),
JmxUtils.createObjectName("voldemort.store.stats.aggregate",
- clientContextName + ".aggregate-perf"
- + jmxId()));
+ "aggregate-perf" + jmxId()));
}
}
@@ -146,18 +133,12 @@ public AbstractStoreClientFactory(ClientConfig config) {
public <K, V> StoreClient<K, V> getStoreClient(String storeName,
InconsistencyResolver<Versioned<V>> resolver) {
- return new DefaultStoreClient<K, V>(storeName,
- resolver,
- this,
- 3,
- clientContextName,
- sequencer.getAndIncrement());
+ return new DefaultStoreClient<K, V>(storeName, resolver, this, 3);
}
@SuppressWarnings("unchecked")
public <K, V, T> Store<K, V, T> getRawStore(String storeName,
- InconsistencyResolver<Versioned<V>> resolver,
- UUID clientId) {
+ InconsistencyResolver<Versioned<V>> resolver) {
logger.info("Client zone-id [" + clientZoneId
+ "] Attempting to obtain metadata for store [" + storeName + "] ");
@@ -242,13 +223,7 @@ public AbstractStoreClientFactory(ClientConfig config) {
store = statStore;
JmxUtils.registerMbean(new StoreStatsJmx(statStore.getStats()),
JmxUtils.createObjectName(JmxUtils.getPackageName(store.getClass()),
- clientContextName
- + "."
- + store.getName()
- + jmxId()
- + (null == clientId ? ""
- : "."
- + clientId.toString())));
+ store.getName() + jmxId()));
}
if(storeDef.getKeySerializer().hasCompression()
@@ -282,11 +257,6 @@ public AbstractStoreClientFactory(ClientConfig config) {
return serializedStore;
}
- public <K, V, T> Store<K, V, T> getRawStore(String storeName,
- InconsistencyResolver<Versioned<V>> resolver) {
- return getRawStore(storeName, resolver, null);
- }
-
protected ClientConfig getConfig() {
return config;
}
@@ -431,44 +401,7 @@ public void close() {
/* Give a unique id to avoid jmx clashes */
private String jmxId() {
- return jmxId == 0 ? "" : "." + Integer.toString(jmxId);
+ return jmxId == 0 ? "" : Integer.toString(jmxId);
}
- /**
- * Generate a unique client ID based on: 0. clientContext, if specified; 1.
- * storeName 2. run path 3. client sequence
- *
- * @param storeName the name of the store the client is created for
- * @param contextName the name of the client context
- * @param clientSequence the client sequence number
- * @return unique client ID
- */
- public static UUID generateClientId(String storeName, String contextName, int clientSequence) {
- String newLine = System.getProperty("line.separator");
- StringBuilder context = new StringBuilder(contextName == null ? "" : contextName);
- context.append(0 == clientSequence ? "" : ("." + clientSequence));
- context.append(".").append(storeName);
-
- try {
- InetAddress host = InetAddress.getLocalHost();
- context.append("@").append(host.getHostName()).append(":");
- } catch(UnknownHostException e) {
- logger.info("Unable to obtain client hostname.");
- logger.info(e.getMessage());
- }
-
- try {
- String currentPath = new File(".").getCanonicalPath();
- context.append(currentPath).append(newLine);
- } catch(IOException e) {
- logger.info("Unable to obtain client run path.");
- logger.info(e.getMessage());
- }
-
- if(logger.isDebugEnabled()) {
- logger.debug(context.toString());
- }
-
- return UUID.nameUUIDFromBytes(context.toString().getBytes());
- }
}
View
32 src/java/voldemort/client/CachingStoreClientFactory.java
@@ -1,12 +1,12 @@
/*
* Copyright 2008-2010 LinkedIn, Inc
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -16,13 +16,8 @@
package voldemort.client;
-import java.util.List;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
+import com.google.common.collect.ImmutableList;
import org.apache.log4j.Logger;
-
import voldemort.annotations.jmx.JmxManaged;
import voldemort.annotations.jmx.JmxOperation;
import voldemort.cluster.failuredetector.FailureDetector;
@@ -31,12 +26,14 @@
import voldemort.versioning.InconsistencyResolver;
import voldemort.versioning.Versioned;
-import com.google.common.collect.ImmutableList;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
/**
- * A wrapper for a store {@link StoreClientFactory} which caches requests to
- * <code>getStoreClient</code>
- *
+ * A wrapper for a store {@link StoreClientFactory} which caches requests
+ * to <code>getStoreClient</code>
+ *
*/
@JmxManaged(description = "A StoreClientFactory which caches clients")
public class CachingStoreClientFactory implements StoreClientFactory {
@@ -51,6 +48,7 @@ public CachingStoreClientFactory(StoreClientFactory inner) {
this.cache = new ConcurrentHashMap<Pair<String, Object>, StoreClient<?, ?>>();
}
+
@SuppressWarnings("unchecked")
public <K, V> StoreClient<K, V> getStoreClient(String storeName) {
Pair<String, Object> key = Pair.create(storeName, null);
@@ -76,13 +74,7 @@ public CachingStoreClientFactory(StoreClientFactory inner) {
public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver) {
- return getRawStore(storeName, resolver, null);
- }
-
- public <K, V, T> Store<K, V, T> getRawStore(String storeName,
- InconsistencyResolver<Versioned<V>> resolver,
- UUID clientId) {
- return inner.getRawStore(storeName, resolver, clientId);
+ return inner.getRawStore(storeName, resolver);
}
public void close() {
View
17 src/java/voldemort/client/ClientConfig.java
@@ -76,7 +76,6 @@
private long failureDetectorRequestLengthThreshold = socketTimeoutMs;
private volatile int maxBootstrapRetries = 2;
- private volatile String clientContextName = "default";
public ClientConfig() {}
@@ -111,7 +110,6 @@ public ClientConfig() {}
public static final String FAILUREDETECTOR_CATASTROPHIC_ERROR_TYPES_PROPERTY = "failuredetector_catastrophic_error_types";
public static final String FAILUREDETECTOR_REQUEST_LENGTH_THRESHOLD_PROPERTY = "failuredetector_request_length_threshold";
public static final String MAX_BOOTSTRAP_RETRIES = "max_bootstrap_retries";
- public static final String CLIENT_CONTEXT_NAME = "voldemort_client_context";
/**
* Instantiate the client config using a properties file
@@ -240,10 +238,6 @@ private void setProperties(Properties properties) {
if(props.containsKey(MAX_BOOTSTRAP_RETRIES))
this.setMaxBootstrapRetries(props.getInt(MAX_BOOTSTRAP_RETRIES));
-
- if(props.containsKey(CLIENT_CONTEXT_NAME)) {
- this.setClientContextName(props.getString(CLIENT_CONTEXT_NAME, null));
- }
}
public int getMaxConnectionsPerNode() {
@@ -523,7 +517,7 @@ public boolean isLazyEnabled() {
/**
* Enable lazy initialization of clients?
- *
+ *
* @param enableLazy If true clients will be lazily initialized
*/
public ClientConfig setEnableLazy(boolean enableLazy) {
@@ -640,13 +634,4 @@ public ClientConfig setMaxBootstrapRetries(int maxBootstrapRetries) {
return this;
}
- public String getClientContextName() {
- return clientContextName;
- }
-
- public ClientConfig setClientContextName(String clientContextName) {
- this.clientContextName = clientContextName;
- return this;
- }
-
}
View
29 src/java/voldemort/client/DefaultStoreClient.java
@@ -18,7 +18,6 @@
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import java.util.Map.Entry;
import org.apache.log4j.Logger;
@@ -64,45 +63,29 @@
private final String storeName;
private final InconsistencyResolver<Versioned<V>> resolver;
private volatile Store<K, V, Object> store;
- private final UUID clientId;
public DefaultStoreClient(String storeName,
InconsistencyResolver<Versioned<V>> resolver,
StoreClientFactory storeFactory,
int maxMetadataRefreshAttempts) {
- this(storeName, resolver, storeFactory, maxMetadataRefreshAttempts, null, 0);
- }
-
- public DefaultStoreClient(String storeName,
- InconsistencyResolver<Versioned<V>> resolver,
- StoreClientFactory storeFactory,
- int maxMetadataRefreshAttempts,
- String clientContext,
- int clientSequence) {
-
this.storeName = Utils.notNull(storeName);
this.resolver = resolver;
this.storeFactory = Utils.notNull(storeFactory);
this.metadataRefreshAttempts = maxMetadataRefreshAttempts;
- this.clientId = AbstractStoreClientFactory.generateClientId(storeName,
- clientContext,
- clientSequence);
+
// Registering self to be able to bootstrap client dynamically via JMX
JmxUtils.registerMbean(this,
JmxUtils.createObjectName(JmxUtils.getPackageName(this.getClass()),
JmxUtils.getClassName(this.getClass())
- + "." + clientContext + "."
- + storeName + "."
- + clientId.toString()));
+ + "." + storeName));
+
bootStrap();
- logger.info("Voldemort client created: clientContext=" + clientContext + " clientSequence="
- + clientSequence + " clientId=" + clientId.toString());
}
@JmxOperation(description = "bootstrap metadata from the cluster.")
public void bootStrap() {
logger.info("Bootstrapping metadata for store " + this.storeName);
- this.store = storeFactory.getRawStore(storeName, resolver, clientId);
+ this.store = storeFactory.getRawStore(storeName, resolver);
}
public boolean delete(K key) {
@@ -372,8 +355,4 @@ else if(versions.size() == 1)
return put(key, versioned, transforms);
}
-
- public UUID getClientId() {
- return clientId;
- }
}
View
9 src/java/voldemort/client/MockStoreClientFactory.java
@@ -18,7 +18,6 @@
import java.io.StringReader;
import java.util.List;
-import java.util.UUID;
import voldemort.cluster.failuredetector.FailureDetector;
import voldemort.cluster.failuredetector.NoopFailureDetector;
@@ -107,8 +106,7 @@ public MockStoreClientFactory(Serializer<?> keySerializer,
}
public <K1, V1, T1> Store<K1, V1, T1> getRawStore(String storeName,
- InconsistencyResolver<Versioned<V1>> resolver,
- UUID clientId) {
+ InconsistencyResolver<Versioned<V1>> resolver) {
if(this.storesXml != null)
return getRawStore(storeName);
@@ -133,11 +131,6 @@ public MockStoreClientFactory(Serializer<?> keySerializer,
return consistentStore;
}
- public <K, V, T> Store<K, V, T> getRawStore(String storeName,
- InconsistencyResolver<Versioned<V>> resolver) {
- return getRawStore(storeName, resolver, null);
- }
-
private <K1, V1, T1> Store<K1, V1, T1> getRawStore(String storeName) {
List<StoreDefinition> storeDefs = storeMapper.readStoreList(new StringReader(storesXml));
StoreDefinition storeDef = null;
View
17 src/java/voldemort/client/StoreClientFactory.java
@@ -16,8 +16,6 @@
package voldemort.client;
-import java.util.UUID;
-
import voldemort.cluster.failuredetector.FailureDetector;
import voldemort.store.Store;
import voldemort.versioning.InconsistencyResolver;
@@ -67,6 +65,9 @@
/**
* Get the underlying store, not the public StoreClient interface
*
+ * @param <K> The key type
+ * @param <V> The value type
+ * @param <T> The transform type
* @param storeName The name of the store
* @param resolver The inconsistency resolver
* @return The appropriate store
@@ -75,18 +76,6 @@
InconsistencyResolver<Versioned<V>> resolver);
/**
- * Get the underlying store, not the public StoreClient interface
- *
- * @param storeName The name of the store
- * @param resolver The inconsistency resolver
- * @param clientId The unique id of the client
- * @return The appropriate store
- */
- <K, V, T> Store<K, V, T> getRawStore(String storeName,
- InconsistencyResolver<Versioned<V>> resolver,
- UUID clientId);
-
- /**
* Close the store client
*/
public void close();
View
10 test/common/voldemort/StaticStoreClientFactory.java
@@ -2,7 +2,6 @@
import java.util.Arrays;
import java.util.List;
-import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import voldemort.client.DefaultStoreClient;
@@ -43,15 +42,8 @@ public StaticStoreClientFactory(Store<?, ?, ?>... stores) {
@SuppressWarnings("unchecked")
public <K, V, T> Store<K, V, T> getRawStore(String storeName,
- InconsistencyResolver<Versioned<V>> resolver,
- UUID clientId) {
- return (Store<K, V, T>) stores.get(Math.max(current.getAndIncrement(), stores.size() - 1));
- }
-
- @SuppressWarnings("unchecked")
- public <K, V, T> Store<K, V, T> getRawStore(String storeName,
InconsistencyResolver<Versioned<V>> resolver) {
- return getRawStore(storeName, resolver, null);
+ return (Store<K, V, T>) stores.get(Math.max(current.getAndIncrement(), stores.size() - 1));
}
@SuppressWarnings("unchecked")
View
341 test/unit/voldemort/client/ClientJmxTest.java
@@ -1,341 +0,0 @@
-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;
- }
-}

0 comments on commit 75906be

Please sign in to comment.