[jbosscache-commits] JBoss Cache SVN: r7507 - in core/trunk/src: test/java/org/jboss/cache/jmx and 1 other directory.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Mon Jan 19 06:05:03 EST 2009
Author: galder.zamarreno at jboss.com
Date: 2009-01-19 06:05:03 -0500 (Mon, 19 Jan 2009)
New Revision: 7507
Modified:
core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java
Log:
[JBCACHE-1465] LOCAL MBean name now uses identity hash code and added new tests for problematic thread names.
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2009-01-19 10:49:16 UTC (rev 7506)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2009-01-19 11:05:03 UTC (rev 7507)
@@ -36,6 +36,7 @@
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
/**
* Registers all the <b>MBean</b>s from an <b>Cache</b> instance to a <b>MBeanServer</b>.
@@ -55,6 +56,7 @@
* </p>
*
* @author Mircea.Markus at jboss.com
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
* @since 3.0
*/
public class JmxRegistrationManager
@@ -97,6 +99,7 @@
this.mBeanServer = mBeanServer;
this.cacheSpi = (CacheSPI) cache;
processBaseName(objectNameBase);
+ log.debug("Base name is: " + this.objectNameBase);
}
/**
@@ -110,6 +113,7 @@
try
{
processBaseName(new ObjectName(objectNameBase));
+ log.debug("Base name is: " + this.objectNameBase);
}
catch (MalformedObjectNameException e)
{
@@ -216,7 +220,8 @@
// CurrentTimeMillis is not good enaugh as an unique id generator. I am constantly
// getting conflicts in several parallel tests on my box. Maybe some more sofisticated
// unique id generator should be provided?
- objectNameBase = LOCAL_CACHE_PREFIX + Thread.currentThread().getName() + "-" + System.currentTimeMillis();
+ // For example: use identity hashcode in hex format.
+ objectNameBase = LOCAL_CACHE_PREFIX + Integer.toHexString(System.identityHashCode(cacheSpi));
}
else //the cache is clustered
{
Modified: core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java 2009-01-19 10:49:16 UTC (rev 7506)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/JmxRegistrationManagerTest.java 2009-01-19 11:05:03 UTC (rev 7507)
@@ -21,6 +21,8 @@
*/
package org.jboss.cache.jmx;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
@@ -40,11 +42,13 @@
* Tester class for {@link JmxRegistrationManager}.
*
* @author Mircea.Markus at jboss.com
+ * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
* @since 3.0
*/
@Test (groups = "functional", testName = "jmx.JmxRegistrationManagerTest")
public class JmxRegistrationManagerTest
{
+ private static final Log log = LogFactory.getLog(JmxRegistrationManagerTest.class);
private UnitTestCacheFactory cacheFactory = new UnitTestCacheFactory();
private MBeanServer mBeanServer;
@@ -62,11 +66,33 @@
public void testRegisterLocalCache() throws Exception
{
- Configuration localConfig = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL);
+ registerLocalCache();
+ }
+
+ public void testRegisterLocalCacheWithDifferentThreadNames() throws Exception
+ {
+ String prevName = Thread.currentThread().getName();
+ try
+ {
+ Thread.currentThread().setName("onecolon:");
+ registerLocalCache();
+
+ Thread.currentThread().setName("twocolons::");
+ registerLocalCache();
+ }
+ finally
+ {
+ Thread.currentThread().setName(prevName);
+ }
+ }
+
+ public void testRegisterReplicatedCache() throws Exception
+ {
+ Configuration localConfig = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC);
localConfig.setExposeManagementStatistics(true);
Cache cache = cacheFactory.createCache(localConfig, getClass());
JmxRegistrationManager regManager = new JmxRegistrationManager(mBeanServer, cache, (ObjectName)null);
- assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.LOCAL_CACHE_PREFIX) == 0;
+ assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.REPLICATED_CACHE_PREFIX) == 0;
regManager.registerAllMBeans();
String name = regManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
assert mBeanServer.isRegistered(new ObjectName(name));
@@ -74,14 +100,14 @@
assert !mBeanServer.isRegistered(new ObjectName(name));
cache.stop();
}
-
- public void testRegisterReplicatedCache() throws Exception
+
+ protected void registerLocalCache() throws Exception
{
- Configuration localConfig = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC);
+ Configuration localConfig = UnitTestConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL);
localConfig.setExposeManagementStatistics(true);
Cache cache = cacheFactory.createCache(localConfig, getClass());
JmxRegistrationManager regManager = new JmxRegistrationManager(mBeanServer, cache, (ObjectName)null);
- assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.REPLICATED_CACHE_PREFIX) == 0;
+ assert regManager.getObjectNameBase().indexOf(JmxRegistrationManager.LOCAL_CACHE_PREFIX) == 0;
regManager.registerAllMBeans();
String name = regManager.getObjectName(CacheMgmtInterceptor.class.getSimpleName());
assert mBeanServer.isRegistered(new ObjectName(name));
More information about the jbosscache-commits
mailing list