[jbosscache-commits] JBoss Cache SVN: r6546 - in core/trunk/src: test/java/org/jboss/cache/jmx and 1 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Fri Aug 8 13:00:31 EDT 2008
Author: mircea.markus
Date: 2008-08-08 13:00:29 -0400 (Fri, 08 Aug 2008)
New Revision: 6546
Added:
core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTestBase.java
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/InterceptorRegistrationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LegacyConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LifecycleNotificationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/NotificationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/OptimisticNotificationTest.java
Removed:
core/trunk/src/main/java/org/jboss/cache/jmx/JmxUtil.java
core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTestBase.java
core/trunk/src/test/java/org/jboss/cache/jmx/InterceptorRegistrationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/LifecycleNotificationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java
core/trunk/src/test/java/org/jboss/cache/jmx/OptimisticNotificationTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapperMBean.java
core/trunk/src/main/java/org/jboss/cache/jmx/LegacyConfiguration.java
Log:
ongoing JMX stuff - deprecated old CacheJmxWrapper
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapper.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -24,13 +24,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.*;
-import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.config.*;
import org.jboss.cache.config.parsing.JGroupsStackParser;
import org.jboss.cache.config.parsing.element.BuddyElementParser;
import org.jboss.cache.config.parsing.element.EvictionElementParser;
import org.jboss.cache.config.parsing.element.LoadersElementParser;
-import org.jboss.cache.interceptors.base.CommandInterceptor;
import org.jboss.cache.util.CachePrinter;
import org.jgroups.Address;
import org.jgroups.Channel;
@@ -40,18 +38,19 @@
import javax.management.*;
import javax.transaction.TransactionManager;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
/**
- * Wrapper class that exposes a
- * {@link CacheJmxWrapperMBean JMX management interface}
+ * Wrapper class that exposes a {@link CacheJmxWrapperMBean JMX management interface}
*
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
* @version $Revision$
+ * @deprecated use {@link org.jboss.cache.jmx.JmxRegistrationManager}. This class will not be supported from 3.0 on.
*/
+ at Deprecated
public class CacheJmxWrapper<K, V>
extends NotificationBroadcasterSupport
implements CacheJmxWrapperMBean<K, V>, MBeanRegistration, CacheNotificationBroadcaster
@@ -708,27 +707,20 @@
throws Exception
{
this.server = server;
-
if (cacheObjectName == null)
{
- if (objName == null)
+ if (objName != null)
{
- // Calling this will create a value for cacheObjectName
+ cacheObjectName = objName.getCanonicalName();
+ } else
+ {
getCacheObjectName();
}
- else
- {
- cacheObjectName = objName.getCanonicalName();
- }
}
-
- ObjectName result = new ObjectName(cacheObjectName);
-
// Inform our CacheNotificationListener of the ObjectName it should transmit
- if (notificationServiceName == null)
- notificationServiceName = result.getCanonicalName();
+ if (notificationServiceName == null) notificationServiceName = cacheObjectName;
cacheNotificationListener.setServiceName(notificationServiceName);
- return result;
+ return new ObjectName(cacheObjectName);
}
/**
@@ -817,7 +809,14 @@
{
if (cacheObjectName == null)
{
- cacheObjectName = JmxUtil.getDefaultCacheObjectName(config, CacheSPI.class.getName());
+ if (config.getClusterName() == null)
+ {
+ cacheObjectName = JmxRegistrationManager.LOCAL_CACHE_PREFIX + "Cache" + System.currentTimeMillis();
+ }
+ else
+ {
+ cacheObjectName = JmxRegistrationManager.CLUSTERED_CACHE_PREFIX + config.getClusterName();
+ }
}
return cacheObjectName;
}
@@ -939,33 +938,10 @@
if (registerJmxResource && config.getExposeManagementStatistics() && !jmxResourceRegistered && server != null)
{
log.debug("Registering jmx resources");
- List<CommandInterceptor> interc = cache.getInterceptorChain();
- if (interc != null && interc.size() > 0)
- {
- try
- {
- for (ComponentRegistry.Component component : cache.getComponentRegistry().getRegiteredComponents())
- {
- ResourceDMBean resourceDMBean = new ResourceDMBean(component.getInstance());
- if (resourceDMBean.isManagedResource())
- {
- resourceDMBeans.add(resourceDMBean);
- }
- }
- for (ResourceDMBean resource: resourceDMBeans)
- {
- String resourceName = resource.getObject().getClass().getSimpleName();
- ObjectName objectName = new ObjectName(cacheObjectName + JmxUtil.JMX_RESOURCE_KEY + resourceName);
- if (!server.isRegistered(objectName)) server.registerMBean(resource, objectName);
- }
- jmxResourceRegistered = true;
- return true;
- }
- catch (JMException e)
- {
- throw new CacheException("Failed to register jmx resources", e);
- }
- }
+ JmxRegistrationManager registrationManager = new JmxRegistrationManager(server, cache, this.cacheObjectName);
+ registrationManager.registerAllMBeans();
+ jmxResourceRegistered = true;
+ return true;
}
return false;
}
@@ -974,21 +950,10 @@
{
if (registerJmxResource && jmxResourceRegistered && server != null)
{
- try
- {
- log.debug("Unregistering interceptors");
- for (ResourceDMBean resource : resourceDMBeans)
- {
- String resourceName = resource.getObject().getClass().getSimpleName();
- ObjectName objectName = new ObjectName(cacheObjectName + JmxUtil.JMX_RESOURCE_KEY + resourceName);
- if (server.isRegistered(objectName)) server.unregisterMBean(objectName);
- }
- jmxResourceRegistered = false;
- }
- catch (Exception e)
- {
- log.error("Exception unregistering interceptors from JMX", e);
- }
+ log.debug("Unregistering interceptors");
+ JmxRegistrationManager registrationManager = new JmxRegistrationManager(server, cache, this.cacheObjectName);
+ registrationManager.unregisterAllMBeans();
+ jmxResourceRegistered = false;
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapperMBean.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapperMBean.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/CacheJmxWrapperMBean.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -25,7 +25,9 @@
* <li> Cache information methods (numNodes, numAttributes, lockInfo, printDetails) which print as Strings or as formatted HTML (for web based JMX consoles)</li>
*
* @since 2.0.0
+ * @deprecated use {@link org.jboss.cache.jmx.JmxRegistrationManager}
*/
+ at Deprecated
public interface CacheJmxWrapperMBean<K, V> extends LegacyConfiguration
{
/**
Added: core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/JmxRegistrationManager.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.cache.jmx;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.ComponentRegistry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.management.*;
+import java.lang.management.ManagementFactory;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Mircea.Markus at jboss.com
+ * @since 3.0
+ */
+public class JmxRegistrationManager
+{
+
+ private static final Log log = LogFactory.getLog(JmxRegistrationManager.class);
+
+ /**
+ * default ObjectName for clusterd caches. Cluster name should pe appended.
+ */
+ public static final String CLUSTERED_CACHE_PREFIX = "jboss.cache:service=JBossCache,cluster=";
+
+ /**
+ * default ObjectName for non clustered caches. An unique identifier should be appended.
+ */
+ public static final String LOCAL_CACHE_PREFIX = "jboss.cache:service=JBossCache,uniqueId=";
+
+ /**
+ * Key for every Dynamic mbean added.
+ */
+ public static final String JMX_RESOURCE_KEY = ",jmx-resource=";
+
+ private MBeanServer mBeanServer;
+
+ private String objectNameBase;
+
+ private CacheSPI cacheSpi;
+
+ public JmxRegistrationManager(MBeanServer mBeanServer, Cache cache, ObjectName objectNameBase)
+ {
+ this.mBeanServer = mBeanServer;
+ this.cacheSpi = (CacheSPI) cache;
+ processBaseName(objectNameBase);
+ }
+
+ /**
+ * @param mBeanServer
+ * @param cache
+ * @param objectNameBase
+ * @throws IllegalArgumentException if the supplied objectNameBase name isn't valid
+ */
+ public JmxRegistrationManager(MBeanServer mBeanServer, Cache cache, String objectNameBase)
+ {
+ this.mBeanServer = mBeanServer;
+ this.cacheSpi = (CacheSPI) cache;
+ try
+ {
+ processBaseName(new ObjectName(objectNameBase));
+ } catch (MalformedObjectNameException e)
+ {
+ throw new IllegalArgumentException("Invalid Object Name : " + objectNameBase, e);
+ }
+ }
+
+ /**
+ * Defaults to platform to platform MBeanServer.
+ *
+ * @see java.lang.management.ManagementFactory#getPlatformMBeanServer()
+ * @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/management/mxbeans.html#mbean_server">platform MBeanServer</a>
+ */
+ public JmxRegistrationManager(Cache cache, ObjectName objectNameBase)
+ {
+ this(ManagementFactory.getPlatformMBeanServer(), cache, objectNameBase);
+ }
+
+ public JmxRegistrationManager(Cache cache)
+ {
+ this(cache, null);
+ }
+
+ public void registerAllMBeans() throws CacheException
+ {
+ try
+ {
+ List<ResourceDMBean> resourceDMBeans = getResourceDMBeans();
+ for (ResourceDMBean resource : resourceDMBeans)
+ {
+ String resourceName = resource.getObject().getClass().getSimpleName();
+ ObjectName objectName = new ObjectName(getObjectName(resourceName));
+ if (!mBeanServer.isRegistered(objectName))
+ {
+ mBeanServer.registerMBean(resource, objectName);
+ }
+ }
+ } catch (Exception e)
+ {
+ throw new CacheException("Failure while registering mbeans", e);
+ }
+ }
+
+ public void unregisterAllMBeans() throws CacheException
+ {
+ log.trace("Unregistering jmx resources..");
+ try
+ {
+ List<ResourceDMBean> resourceDMBeans = getResourceDMBeans();
+ for (ResourceDMBean resource : resourceDMBeans)
+ {
+ String resourceName = resource.getObject().getClass().getSimpleName();
+ ObjectName objectName = new ObjectName(getObjectName(resourceName));
+ if (mBeanServer.isRegistered(objectName))
+ {
+ mBeanServer.unregisterMBean(objectName);
+ }
+ }
+ } catch (Exception e)
+ {
+ throw new CacheException("Failure while unregistering mbeans", e);
+ }
+ }
+
+
+ private List<ResourceDMBean> getResourceDMBeans()
+ {
+ List<ResourceDMBean> resourceDMBeans = new ArrayList<ResourceDMBean>();
+ for (ComponentRegistry.Component component : cacheSpi.getComponentRegistry().getRegiteredComponents())
+ {
+ ResourceDMBean resourceDMBean = new ResourceDMBean(component.getInstance());
+ if (resourceDMBean.isManagedResource())
+ {
+ resourceDMBeans.add(resourceDMBean);
+ }
+ }
+ return resourceDMBeans;
+ }
+
+ private void processBaseName(ObjectName baseName)
+ {
+ if (baseName != null)
+ {
+ this.objectNameBase = baseName.getCanonicalName();
+ return;
+ }
+ if (cacheSpi.getConfiguration().getCacheMode().equals(Configuration.CacheMode.LOCAL))
+ {
+ objectNameBase = LOCAL_CACHE_PREFIX + System.currentTimeMillis();
+ }
+ else //the cache is clustered
+ {
+ objectNameBase = CLUSTERED_CACHE_PREFIX + cacheSpi.getConfiguration().getClusterName();
+ }
+ }
+
+ private String getObjectName(String resourceName)
+ {
+ return objectNameBase + JMX_RESOURCE_KEY + resourceName;
+ }
+
+ public String getObjectNameBase()
+ {
+ return objectNameBase;
+ }
+}
Deleted: core/trunk/src/main/java/org/jboss/cache/jmx/JmxUtil.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/JmxUtil.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/JmxUtil.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -1,93 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.jmx;
-
-import org.jboss.cache.config.Configuration;
-
-import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-/**
- * Various JMX related utilities
- *
- * @author Jerry Gauthier
- * @author Manik Surtani
- * @version $Id$
- */
-public class JmxUtil
-{
- public static final String JBOSS_SERVER_DOMAIN = "jboss";
- public static final String JBOSS_CACHE_DOMAIN = "jboss.cache";
- public static final String SERVICE_KEY_NAME = "service";
- public static final String BASE_PREFIX = JBOSS_CACHE_DOMAIN + ":" + SERVICE_KEY_NAME + "=JBossCache";
- public static final String CLUSTER_KEY = "cluster";
- public static final String PREFIX = BASE_PREFIX + "," + CLUSTER_KEY + "=";
- public static final String UNIQUE_ID_KEY = "uniqueId";
- public static final String NO_CLUSTER_PREFIX = BASE_PREFIX + "," + UNIQUE_ID_KEY + "=";
- public static final String CACHE_TYPE_KEY = "cacheType";
- public static final String PLAIN_CACHE_TYPE = "Cache";
- public static final String MBEAN_CLASS_SUFFIX = "MBean";
- public static final String JMX_RESOURCE_KEY = ",jmx-resource=";
-
- public static void registerCacheMBean(MBeanServer server, CacheJmxWrapperMBean cache, String cacheObjectName)
- throws JMException
- {
- ObjectName on = new ObjectName(cacheObjectName);
- if (!server.isRegistered(on))
- {
- server.registerMBean(cache, on);
- }
- }
-
- public static String getDefaultCacheObjectName(org.jboss.cache.Cache cache)
- {
- // get the cache's registration name
- return getDefaultCacheObjectName(cache.getConfiguration(), cache.getClass().getName());
- }
-
- public static String getDefaultCacheObjectName(Configuration config, String cacheImplClass)
- {
- // get the cache's registration name
- String tmpName;
- if (config.getClusterName() == null)
- {
- tmpName = NO_CLUSTER_PREFIX + getUniqueId(cacheImplClass);
- }
- else
- {
- tmpName = PREFIX + config.getClusterName();
- }
- return tmpName;
- }
-
- public static String getUniqueId(String cacheImplClass)
- {
- return cacheImplClass + System.currentTimeMillis();
- }
-
- public static void unregisterCacheMBean(MBeanServer server, String cacheObjectName)
- throws Exception
- {
- server.unregisterMBean(new ObjectName(cacheObjectName));
- }
-}
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/LegacyConfiguration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/LegacyConfiguration.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/LegacyConfiguration.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -33,7 +33,9 @@
*
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
* @version $Revision$
+ * @deprecated use {@link org.jboss.cache.jmx.JmxRegistrationManager}
*/
+ at Deprecated
public interface LegacyConfiguration
{
/**
Deleted: core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -1,453 +0,0 @@
-package org.jboss.cache.jmx;
-
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheException;
-import org.jboss.cache.CacheStatus;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.notifications.annotation.CacheListener;
-import org.jboss.cache.notifications.annotation.CacheStarted;
-import org.jboss.cache.notifications.annotation.CacheStopped;
-import org.jboss.cache.notifications.event.Event;
-import org.jboss.cache.transaction.DummyTransactionManagerLookup;
-import org.jboss.cache.util.CachePrinter;
-import org.jboss.cache.util.TestingUtil;
-import org.jgroups.Address;
-import org.jgroups.stack.IpAddress;
-import static org.testng.AssertJUnit.*;
-import org.testng.annotations.Test;
-
-import javax.management.ObjectName;
-import javax.transaction.TransactionManager;
-import java.util.List;
-
-/**
- * Tests the JMX wrapper class around the cache.
- *
- * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
- * @author Brian Stansberry
- */
- at Test(groups = "functional")
-public class CacheJmxWrapperTest extends CacheJmxWrapperTestBase
-{
- public void testCacheMBeanBinding() throws Exception
- {
- registerWrapper();
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
- }
-
- public void testSetCacheObjectName() throws Exception
- {
- ObjectName on = new ObjectName("jboss.cache:test=SetCacheObjectName");
- boolean registered = false;
- try
- {
- CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
- wrapper.setCacheObjectName(on.getCanonicalName());
-
- // Register under the standard name
- registerWrapper(wrapper);
- // Should be registered under 'on'
- registered = mBeanServer.isRegistered(on);
-
- assertTrue("Registered with configured name", registered);
- assertEquals("Configured name retained", on.getCanonicalName(), wrapper.getCacheObjectName());
-
- wrapper.create();
- wrapper.start();
-
- interceptorRegistrationTest(on.getCanonicalName(), true);
-
- wrapper.stop();
- wrapper.destroy();
-
- interceptorRegistrationTest(false);
- }
- finally
- {
- if (registered)
- mBeanServer.unregisterMBean(on);
- }
- }
-
- public void testGetCacheObjectName() throws Exception
- {
- ObjectName on = new ObjectName("jboss.cache:test=SetCacheObjectName");
- String str = on.getCanonicalName();
- CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
- wrapper.setCacheObjectName(str);
-
- assertEquals("Setter and getter match", str, wrapper.getCacheObjectName());
-
- // Go back to the default
- wrapper.setCacheObjectName(null);
- assertEquals("Got default ObjectName", JmxUtil.PREFIX + CLUSTER_NAME, wrapper.getCacheObjectName());
-
- registerWrapper(wrapper);
- assertEquals("Returns standard name", mBeanName, new ObjectName(wrapper.getCacheObjectName()));
- }
-
- public void testGetConfiguration1() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
- Configuration cfgFromJmx = wrapper.getConfiguration();
- assertNotNull("Got a configuration", cfgFromJmx);
- assertSame(cache.getConfiguration(), cfgFromJmx);
- }
-
- public void testGetConfiguration2() throws Exception
- {
- Configuration cfg = createConfiguration();
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(cfg);
- Configuration cfgFromJmx = wrapper.getConfiguration();
- assertNotNull("Got a configuration", cfgFromJmx);
- assertSame(cfg, cfgFromJmx);
- }
-
- /**
- * Note that this is a bit of a 'white box' test as it assumes that the
- * returned String equals Configuration.toString(). That could change and
- * break this test; if it does, and there's nothing wrong with the
- * change, just modify the test.
- *
- * @throws Exception
- */
- public void testPrintConfigurationAsString1() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
- String cfgFromJmx = wrapper.printConfigurationAsString();
- assertEquals(cache.getConfiguration().toString(), cfgFromJmx);
- }
-
- /**
- * Note that this is a bit of a 'white box' test as it assumes that the
- * returned String equals Configuration.toString(). That could change and
- * break this test; if it does, and there's nothing wrong with the
- * change, just modify the test.
- *
- * @throws Exception
- */
- public void testPrintConfigurationAsString2() throws Exception
- {
- Configuration cfg = createConfiguration();
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(cfg);
- wrapper.create();
- wrapper.start();
- String cfgFromJmx = wrapper.printConfigurationAsString();
- assertEquals(wrapper.getCache().getConfiguration().toString(), cfgFromJmx);
- }
-
- /**
- * Note that this is a bit of a 'white box' test as it checks
- * the currently coded HTML format and assumes that the HTML content is
- * derived from Configuration.toString(). That could change and break
- * this test; if it does, and there's nothing wrong with the
- * change, just modify the test.
- *
- * @throws Exception
- */
- public void testPrintConfigurationAsHtml1() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
- String cfgFromJmx = wrapper.printConfigurationAsHtmlString();
- assertEquals(CacheJmxWrapper.formatHtml(cache.getConfiguration().toString()), cfgFromJmx);
- checkHtml(cfgFromJmx, false);
- }
-
- /**
- * Note that this is a bit of a 'white box' test as it checks
- * the currently coded HTML format and assumes that the HTML content is
- * derived from Configuration.toString(). That could change and break
- * this test; if it does, and there's nothing wrong with the
- * change, just modify the test.
- *
- * @throws Exception
- */
- public void testPrintConfigurationAsHtml2() throws Exception
- {
- Configuration cfg = createConfiguration();
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(cfg);
- wrapper.create();
- wrapper.start();
- String cfgFromJmx = wrapper.printConfigurationAsHtmlString();
- assertEquals(CacheJmxWrapper.formatHtml(wrapper.getCache().getConfiguration().toString()), cfgFromJmx);
- checkHtml(cfgFromJmx, false);
- }
-
- @SuppressWarnings("unchecked")
- public void testGetCache() throws Exception
- {
- registerWrapper();
- // have to start the cache before we'll have a root
- cache.start();
-
- Cache<String, String> cacheJmx = (Cache<String, String>) mBeanServer.getAttribute(mBeanName, "Cache");
- cacheJmx.getRoot().put("key", "value");
-
- assertEquals("value", cache.getRoot().get("key"));
-
- Fqn fqn = Fqn.fromString("/testing/jmx");
- cache.put(fqn, "key", "value");
-
- assertEquals("value", cacheJmx.get(fqn, "key"));
- }
-
- public void testPrintCacheDetails() throws Exception
- {
- printCacheDetailsTest(false);
- }
-
- /**
- * Note that this is a bit of a 'white box' test as it checks
- * the currently coded HTML format. That could change and break
- * this test; if it does, and there's nothing wrong with the
- * change, just modify the test.
- *
- * @throws Exception
- */
- public void testPrintCacheDetailsAsHtml() throws Exception
- {
- String html = printCacheDetailsTest(true);
- checkHtml(html, true);
- }
-
- public void testPrintLockInfo() throws Exception
- {
- printLockInfoTest(false);
- }
-
- /**
- * Note that this is a bit of a 'white box' test as it checks
- * the currently coded HTML format. That could change and break
- * this test; if it does, and there's nothing wrong with the
- * change, just modify the test.
- *
- * @throws Exception
- */
- public void testPrintLockInfoAsHtml() throws Exception
- {
- printLockInfoTest(true);
- }
-
- public void testGetLocalAddress() throws Exception
- {
- Configuration c = createConfiguration();
- c.setCacheMode(CacheMode.REPL_ASYNC);
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(c);
- wrapper.start();
- assertTrue("Got an IpAddress", wrapper.getLocalAddress() instanceof IpAddress);
- }
-
- public void testGetMembers() throws Exception
- {
- Configuration c = createConfiguration();
- c.setCacheMode(CacheMode.REPL_ASYNC);
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(c);
- wrapper.start();
-
- c = createConfiguration();
- c.setCacheMode(CacheMode.REPL_ASYNC);
- Cache cache2 = null;
- try
- {
- cache2 = createCache(c);
- cache2.start();
- Cache[] caches = new Cache[]{wrapper.getCache(), cache2};
- TestingUtil.blockUntilViewsReceived(caches, 5000);
-
- Address addr = wrapper.getLocalAddress();
- assertNotNull("Got an Address", addr);
- List members = wrapper.getMembers();
- assertNotNull("Got members", addr);
- assertEquals("Got correct number of members", 2, members.size());
- assertTrue("I am a member", members.contains(addr));
- }
- finally
- {
- if (cache2 != null)
- {
- cache2.destroy();
- }
- }
- }
-
- public void testDuplicateInvocation() throws Exception
- {
- CacheJmxWrapperMBean<String, String> cache = registerWrapper();
- cache.create();
- cache.start();
- cache.create();
- cache.start();
-
- cache.getCache().put(Fqn.fromString("/a/b/c"), null);
- assertTrue(cache.getNumberOfNodes() > 0);
- assertEquals(0, cache.getNumberOfAttributes());
-
- System.out.println("cache locks before restart:\n" + cache.printLockInfo());
- cache.destroy();
- cache.start();
- System.out.println("cache locks after restart:\n" + cache.printLockInfo());
-
- assertEquals(0, cache.getNumberOfNodes());
- assertEquals(0, cache.getNumberOfAttributes());
-
- cache.stop();
- cache.destroy();
- cache.stop();
- cache.destroy();
- }
-
- public void testFailedStart() throws Exception
- {
- CacheJmxWrapper<String, String> wrapper = new CacheJmxWrapper<String, String>(createCache(createConfiguration()));
- registerWrapper(wrapper);
- assertEquals("Correct state", CacheStatus.INSTANTIATED, wrapper.getCacheStatus());
- wrapper.create();
-
- DisruptLifecycleListener listener = new DisruptLifecycleListener();
- listener.setDisrupt(true);
- wrapper.getCache().addCacheListener(listener);
-
- assertEquals("Correct state", CacheStatus.CREATED, wrapper.getCacheStatus());
- try
- {
- wrapper.start();
- fail("Listener did not prevent start");
- }
- catch (CacheException good)
- {
- }
-
- assertEquals("Correct state", CacheStatus.FAILED, wrapper.getCacheStatus());
-
- listener.setDisrupt(false);
-
- wrapper.start();
-
- assertEquals("Correct state", CacheStatus.STARTED, wrapper.getCacheStatus());
-
- wrapper.getCache().put(Fqn.fromString("/a/b/c"), null);
- assertTrue(wrapper.getNumberOfNodes() > 0);
- assertEquals(0, wrapper.getNumberOfAttributes());
-
- listener.setDisrupt(true);
- // need to re-add the listener since the failed start would have nullified the notifier.
- cache.addCacheListener(listener);
-
- try
- {
- wrapper.stop();
- fail("Listener did not prevent stop");
- }
- catch (CacheException good)
- {
- }
-
- assertEquals("Correct state", CacheStatus.FAILED, wrapper.getCacheStatus());
-
- listener.setDisrupt(false);
-
- wrapper.stop();
- assertEquals("Correct state", CacheStatus.STOPPED, wrapper.getCacheStatus());
- wrapper.destroy();
- assertEquals("Correct state", CacheStatus.DESTROYED, wrapper.getCacheStatus());
- }
-
- private String printCacheDetailsTest(boolean html) throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
-
- // have to start the cache before we'll have a root
- cache.start();
- Fqn fqn = Fqn.fromString("/testing/jmx");
- cache.put(fqn, "foobar", "barfoo");
-
- assertEquals("barfoo", cache.get(fqn, "foobar"));
-
- String details = html ? wrapper.printCacheDetailsAsHtml() : wrapper.printCacheDetails();
-
-
- System.out.println("Cache details: " + CachePrinter.printCacheDetails(cache));
- System.out.println("Details: " + details);
-
- assertTrue("Details include testing", details.contains("testing"));
- assertTrue("Details include jmx", details.contains("jmx"));
- assertTrue("Details include foobar", details.contains("foobar"));
- assertTrue("Details include barfoo", details.contains("barfoo"));
-
- return details;
- }
-
- private String printLockInfoTest(boolean html) throws Exception
- {
- Configuration config = createConfiguration();
- config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- Cache<String, String> c = createCache(config);
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(c);
-
-// wrapper.setManageCacheLifecycle(true);
- wrapper.create();
- wrapper.start();
-
- TransactionManager tm = config.getRuntimeConfig().getTransactionManager();
-
- tm.begin();
- try
- {
- Fqn fqn = Fqn.fromString("/testing/jmx");
- cache.put(fqn, "foobar", "barfoo");
-
- String locks = html ? wrapper.printLockInfoAsHtml() : wrapper.printLockInfo();
-
- assertTrue("Details include testing", locks.contains("testing"));
- assertTrue("Details include jmx", locks.contains("jmx"));
-
- return locks;
- }
- catch (Exception e)
- {
- tm.setRollbackOnly();
- throw e;
- }
- finally
- {
- tm.commit();
- }
-
- }
-
- private void checkHtml(String html, boolean checkBR)
- {
- if (checkBR)
- assertTrue("Has <br", html.contains("<br"));
-
- assertTrue("No tabs", html.indexOf('\t') == -1);
-
- assertTrue("No spaces", html.indexOf(' ') == -1);
-
- }
-
- @CacheListener
- public class DisruptLifecycleListener
- {
- private boolean disrupt;
-
- @CacheStarted
- public void cacheStarted(Event e)
- {
- if (disrupt) throw new IllegalStateException("I don't want to start");
- }
-
- @CacheStopped
- public void cacheStopped(Event e)
- {
- if (disrupt) throw new IllegalStateException("I don't want to stop");
- }
-
- public void setDisrupt(boolean disrupt)
- {
- this.disrupt = disrupt;
- }
- }
-}
Deleted: core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTestBase.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTestBase.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -1,171 +0,0 @@
-package org.jboss.cache.jmx;
-
-import org.jboss.cache.Cache;
-import org.jboss.cache.CacheFactory;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.config.Configuration;
-import static org.testng.AssertJUnit.assertFalse;
-import static org.testng.AssertJUnit.assertTrue;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.MBeanServerInvocationHandler;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-/**
- * Tests the JMX wrapper class around the cache.
- *
- * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
- * @author Brian Stansberry
- */
- at Test(groups = "functional")
-public abstract class CacheJmxWrapperTestBase
-{
- public static final String CLUSTER_NAME = "CacheMBeanTest";
-
- protected Cache<String, String> cache;
- protected CacheJmxWrapperMBean<String, String> jmxWrapper;
- protected MBeanServer mBeanServer;
- protected ObjectName mBeanName;
- protected String mBeanNameStr;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp() throws Exception
- {
- mBeanServer = MBeanServerFactory.createMBeanServer("CacheMBeanTest");
-
- mBeanNameStr = JmxUtil.PREFIX + CLUSTER_NAME;
- mBeanName = new ObjectName(mBeanNameStr);
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown() throws Exception
- {
- try
- {
- cleanup();
- }
- finally
- {
- if (mBeanServer != null)
- {
- MBeanServerFactory.releaseMBeanServer(mBeanServer);
- mBeanServer = null;
- }
- }
- }
-
- protected CacheJmxWrapperMBean<String, String> registerWrapper() throws Exception
- {
- if (cache == null)
- cache = createCache(createConfiguration());
- return registerWrapper(cache);
- }
-
- protected CacheJmxWrapperMBean<String, String> registerWrapper(Cache<String, String> toWrap) throws Exception
- {
- CacheJmxWrapper<String, String> wrapper = new CacheJmxWrapper<String, String>(toWrap);
- return registerWrapper(wrapper);
- }
-
- protected CacheJmxWrapperMBean<String, String> registerWrapper(Configuration config) throws Exception
- {
- CacheJmxWrapper<String, String> wrapper = new CacheJmxWrapper<String, String>();
- wrapper.setConfiguration(config);
- return registerWrapper(wrapper);
- }
-
- @SuppressWarnings("unchecked")
- protected CacheJmxWrapperMBean<String, String> registerWrapper(CacheJmxWrapperMBean<String, String> wrapper) throws Exception
- {
- JmxUtil.registerCacheMBean(mBeanServer, wrapper, mBeanNameStr);
- jmxWrapper = (CacheJmxWrapperMBean<String, String>) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
- return jmxWrapper;
- }
-
- protected void unregisterWrapper() throws Exception
- {
- mBeanServer.unregisterMBean(mBeanName);
- }
-
- protected CacheJmxWrapper<String, String> createWrapper(Configuration config)
- {
- CacheJmxWrapper<String, String> wrapper = new CacheJmxWrapper<String, String>();
- wrapper.setConfiguration(config);
- return wrapper;
- }
-
- protected Cache<String, String> createCache(Configuration config)
- {
- CacheFactory<String, String> factory = new DefaultCacheFactory<String, String>();
- cache = factory.createCache(config, false);
- return cache;
- }
-
- protected Configuration createConfiguration()
- {
- Configuration c = new Configuration();
- c.setClusterName(CLUSTER_NAME);
- c.setExposeManagementStatistics(true);
- c.setCacheMode(Configuration.CacheMode.LOCAL);
- return c;
- }
-
- private void cleanup() throws Exception
- {
- if (cache != null)
- {
- try
- {
- cache.stop();
- }
- catch (Exception ignored)
- {
- }
-
- cache = null;
- }
- if (jmxWrapper != null)
- {
- try
- {
- jmxWrapper.stop();
- jmxWrapper.destroy();
- }
- catch (Exception ignored)
- {
- }
-
- jmxWrapper = null;
- }
-
- if (mBeanServer != null && mBeanName != null && mBeanServer.isRegistered(mBeanName))
- mBeanServer.unregisterMBean(mBeanName);
- }
-
- protected void interceptorRegistrationTest(boolean expectMbeans) throws MalformedObjectNameException, NullPointerException
- {
- interceptorRegistrationTest(mBeanNameStr, expectMbeans);
- }
-
- protected void interceptorRegistrationTest(String baseName, boolean expectMbeans) throws MalformedObjectNameException, NullPointerException
- {
- // should be 3 interceptor MBeans loaded:
- ObjectName[] interceptorMBeanNames = {
- new ObjectName(baseName + JmxUtil.JMX_RESOURCE_KEY + "TxInterceptor"),
- new ObjectName(baseName + JmxUtil.JMX_RESOURCE_KEY + "CacheMgmtInterceptor"),
- };
-
- for (ObjectName n : interceptorMBeanNames)
- {
- if (expectMbeans)
- assertTrue(n + " should be registered", mBeanServer.isRegistered(n));
- else
- assertFalse(n + " should not be registered", mBeanServer.isRegistered(n));
- }
- }
-}
Deleted: core/trunk/src/test/java/org/jboss/cache/jmx/InterceptorRegistrationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/InterceptorRegistrationTest.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/InterceptorRegistrationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -1,384 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.cache.jmx;
-
-import org.jboss.cache.config.Configuration;
-import static org.testng.AssertJUnit.assertTrue;
-import org.testng.annotations.Test;
-
-/**
- * Tests the interceptor registration function of CacheJmxWrapper.
- *
- * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @version $Revision$
- */
- at Test(groups = "functional")
-public class InterceptorRegistrationTest extends CacheJmxWrapperTestBase
-{
-
- /**
- * Confirms interceptor mbeans are registered if the following events
- * occur:
- * <p/>
- * cache.start();
- * wrapper creation and registration.
- *
- * @throws Exception
- */
- public void testInterceptorMBeans1() throws Exception
- {
- // have to start the cache to have any interceptors
- createCache(createConfiguration());
- cache.start();
-
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(cache);
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- interceptorRegistrationTest(true);
-
- // These should be ignored because we
- // never did wrapper.create()/start()
- wrapper.stop();
- wrapper.destroy();
-
- // Should still be registered
- interceptorRegistrationTest(true);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- /**
- * Confirms interceptor mbeans are registered if the following events
- * occur:
- * <p/>
- * cache.start();
- * wrapper creation and and start
- * wrapper registration.
- *
- * @throws Exception
- */
- public void testInterceptorMBeans2() throws Exception
- {
- // have to start the cache to have any interceptors
- createCache(createConfiguration());
- cache.start();
-
- CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper<String, String>(cache);
- wrapper.start();
- wrapper = registerWrapper(wrapper);
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- interceptorRegistrationTest(true);
-
- wrapper.stop();
- wrapper.destroy();
-
- // Should still no longer be registered
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- /**
- * Confirms interceptor mbeans are registered if the following events
- * occur:
- * <p/>
- * Cache not injected
- * wrapper registered;
- * wrapper created and started.
- *
- * @throws Exception
- */
- public void testInterceptorMBeans3() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(createConfiguration());
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- // have to start the cache to have any interceptors
- wrapper.create();
- wrapper.start();
-
- interceptorRegistrationTest(true);
-
- wrapper.stop();
- wrapper.destroy();
-
- // Destroy should unregister if we are managing
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- /**
- * Confirms interceptor mbeans are registered if the following events
- * occur:
- * <p/>
- * Cache not injected
- * wrapper created and started.
- * wrapper registered
- *
- * @throws Exception
- */
- public void testInterceptorMBeans4() throws Exception
- {
- CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
-
- // have to start the cache to have any interceptors
- wrapper.create();
- wrapper.start();
-
- registerWrapper(wrapper);
-
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- interceptorRegistrationTest(true);
-
- wrapper.stop();
- wrapper.destroy();
-
- // Destroy should unregister if we are managing
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- /**
- * Confirms interceptor mbeans are registered if the following events
- * occur:
- * <p/>
- * cache constructed;
- * wrapper constructed and registered with manageCacheLifecycle=true
- * wrapper created and started
- *
- * @throws Exception
- */
- public void testInterceptorMBeans5() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
-// wrapper.setManageCacheLifecycle(true);
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- // have to start the cache to have any interceptors
- wrapper.create();
- wrapper.start();
-
- interceptorRegistrationTest(true);
-
- wrapper.stop();
- wrapper.destroy();
-
- // Destroy should unregister if we are managing
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- /**
- * Confirms interceptor mbeans are registered if the following events
- * occur:
- * <p/>
- * cache constructed;
- * wrapper constructed and registered
- * wrapper created and started
- *
- * @throws Exception
- */
- public void testInterceptorMBeans6() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- // have to start the cache to have any interceptors
- wrapper.create();
- wrapper.start();
-
- interceptorRegistrationTest(true);
-
- wrapper.stop();
- wrapper.destroy();
-
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- /**
- * Confirms interceptor mbeans are registered if the following events
- * occur:
- * <p/>
- * cache constructed;
- * wrapper created and started
- * wrapper registered
- *
- * @throws Exception
- */
- public void testInterceptorMBeans7() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper<String, String>(createCache(createConfiguration()));
-
- // have to start the cache to have any interceptors
- wrapper.create();
- wrapper.start();
-
- wrapper = registerWrapper(wrapper);
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- interceptorRegistrationTest(true);
-
- wrapper.stop();
- wrapper.destroy();
-
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- /**
- * Tests that setting registerInterceptors=false disables interceptor
- * registration when the wrapper is registered before create/start
- * are called.
- *
- * @throws Exception
- */
- public void testRegisterInterceptors1() throws Exception
- {
- CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
- wrapper.setRegisterJmxResource(false);
-
- registerWrapper(wrapper);
-
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- wrapper.create();
- wrapper.start();
-
- interceptorRegistrationTest(false);
-
- wrapper.stop();
- wrapper.destroy();
-
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- /**
- * Tests that setting registerInterceptors=false disables interceptor
- * registration when the wrapper is registered after create/start
- * are called.
- *
- * @throws Exception
- */
- public void testRegisterInterceptors2() throws Exception
- {
- CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
- wrapper.setRegisterJmxResource(false);
-
- wrapper.create();
- wrapper.start();
-
- registerWrapper(wrapper);
-
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- interceptorRegistrationTest(false);
-
- wrapper.stop();
- wrapper.destroy();
-
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- public void testExposeManagementStatistics1() throws Exception
- {
- Configuration cfg = createConfiguration();
- cfg.setExposeManagementStatistics(false);
-
- CacheJmxWrapper<String, String> wrapper = createWrapper(cfg);
- registerWrapper(cfg);
-
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- wrapper.create();
- wrapper.start();
-
- interceptorRegistrationTest(false);
-
- wrapper.stop();
- wrapper.destroy();
-
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
- }
-
- public void testExposeManagementStatistics2() throws Exception
- {
- Configuration cfg = createConfiguration();
- cfg.setExposeManagementStatistics(false);
-
- CacheJmxWrapper<String, String> wrapper = createWrapper(cfg);
-
- wrapper.create();
- wrapper.start();
-
- registerWrapper(wrapper);
-
- assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
-
- interceptorRegistrationTest(false);
-
- wrapper.stop();
- wrapper.destroy();
-
- interceptorRegistrationTest(false);
-
- unregisterWrapper();
-
- interceptorRegistrationTest(false);
-
- }
-
-}
Deleted: core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -1,413 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.cache.jmx;
-
-import org.jboss.cache.Version;
-import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.config.Configuration.NodeLockingScheme;
-import org.jboss.cache.config.EvictionConfig;
-import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.RuntimeConfig;
-import org.jboss.cache.config.parsing.XmlConfigHelper;
-import org.jboss.cache.eviction.FIFOConfiguration;
-import org.jboss.cache.eviction.FIFOPolicy;
-import org.jboss.cache.eviction.LRUConfiguration;
-import org.jboss.cache.eviction.LRUPolicy;
-import org.jboss.cache.eviction.MRUConfiguration;
-import org.jboss.cache.eviction.MRUPolicy;
-import org.jboss.cache.loader.FileCacheLoader;
-import org.jboss.cache.loader.SingletonStoreCacheLoader;
-import org.jboss.cache.loader.jdbm.JdbmCacheLoader;
-import org.jboss.cache.lock.IsolationLevel;
-import org.jboss.cache.multiplexer.MultiplexerTestHelper;
-import org.jboss.cache.transaction.BatchModeTransactionManagerLookup;
-import org.jgroups.ChannelFactory;
-import org.jgroups.JChannelFactory;
-import org.jgroups.jmx.JChannelFactoryMBean;
-import static org.testng.AssertJUnit.*;
-import org.testng.annotations.Test;
-import org.w3c.dom.Element;
-
-import javax.management.MBeanServerInvocationHandler;
-import javax.management.ObjectName;
-import javax.transaction.TransactionManager;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.List;
-import java.util.Properties;
-
-/**
- * Test of the CacheLegacyJmxWrapper.
- *
- * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @version $Revision$
- */
- at Test(groups = "functional")
-public class LegacyConfigurationTest extends CacheJmxWrapperTestBase
-{
- @SuppressWarnings({"deprecation", "unchecked"})
- public void testLocalCache() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper();
- registerWrapper(wrapper);
-
- wrapper = (CacheJmxWrapperMBean<String, String>) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
-
- wrapper.setBuddyReplicationConfig(getBuddyReplicationConfig());
- wrapper.setCacheLoaderConfig(getCacheLoaderConfig());
- wrapper.setCacheMode("REPL_SYNC");
- wrapper.setClusterName("LocalTest");
- wrapper.setClusterConfig(getClusterConfig());
- wrapper.setEvictionPolicyConfig(getEvictionPolicyConfig());
- wrapper.setFetchInMemoryState(false);
- wrapper.setInitialStateRetrievalTimeout(100);
- wrapper.setInactiveOnStartup(true);
- wrapper.setNodeLockingScheme("OPTIMISTIC");
- wrapper.setIsolationLevel("READ_UNCOMMITTED");
- wrapper.setLockAcquisitionTimeout(200);
- wrapper.setReplicationVersion("1.0.1");
- wrapper.setReplQueueInterval(15);
- wrapper.setReplQueueMaxElements(50);
- wrapper.setSyncReplTimeout(300);
- wrapper.setSyncCommitPhase(true);
- wrapper.setSyncRollbackPhase(true);
- wrapper.setTransactionManagerLookupClass(BatchModeTransactionManagerLookup.class.getName());
- wrapper.setExposeManagementStatistics(false);
- wrapper.setUseRegionBasedMarshalling(true);
- wrapper.setUseReplQueue(true);
-
- Configuration c = wrapper.getConfiguration();
-
- assertEquals("CacheMode", "REPL_SYNC", wrapper.getCacheMode());
- assertEquals("CacheMode", CacheMode.REPL_SYNC, c.getCacheMode());
- assertEquals("ClusterName", "LocalTest", wrapper.getClusterName());
- assertEquals("ClusterName", "LocalTest", c.getClusterName());
- assertEquals("FetchInMemoryState", false, wrapper.getFetchInMemoryState());
- assertEquals("FetchInMemoryState", false, c.isFetchInMemoryState());
- assertEquals("InitialStateRetrievalTimeout", 100, wrapper.getInitialStateRetrievalTimeout());
- assertEquals("InitialStateRetrievalTimeout", 100, c.getStateRetrievalTimeout());
- assertEquals("InactiveOnStartup", true, wrapper.isInactiveOnStartup());
- assertEquals("InactiveOnStartup", true, c.isInactiveOnStartup());
- assertEquals("NodeLockingScheme", "OPTIMISTIC", wrapper.getNodeLockingScheme());
- assertEquals("NodeLockingScheme", NodeLockingScheme.OPTIMISTIC, c.getNodeLockingScheme());
- assertEquals("IsolationLevel", "READ_UNCOMMITTED", wrapper.getIsolationLevel());
- assertEquals("IsolationLevel", IsolationLevel.READ_UNCOMMITTED, c.getIsolationLevel());
- assertEquals("LockAcquisitionTimeout", 200, wrapper.getLockAcquisitionTimeout());
- assertEquals("LockAcquisitionTimeout", 200, c.getLockAcquisitionTimeout());
- assertEquals("ReplicationVersion", "1.0.1", wrapper.getReplicationVersion());
- assertEquals("ReplicationVersion", Version.getVersionShort("1.0.1"), c.getReplicationVersion());
- assertEquals("ReplQueueInterval", 15, wrapper.getReplQueueInterval());
- assertEquals("ReplQueueInterval", 15, c.getReplQueueInterval());
- assertEquals("ReplQueueMaxElements", 50, wrapper.getReplQueueMaxElements());
- assertEquals("ReplQueueMaxElements", 50, c.getReplQueueMaxElements());
- assertEquals("SyncReplTimeout", 300, wrapper.getSyncReplTimeout());
- assertEquals("SyncReplTimeout", 300, c.getSyncReplTimeout());
- assertEquals("SyncCommitPhase", true, wrapper.getSyncCommitPhase());
- assertEquals("SyncCommitPhase", true, c.isSyncCommitPhase());
- assertEquals("SyncRollbackPhase", true, wrapper.getSyncRollbackPhase());
- assertEquals("SyncRollbackPhase", true, c.isSyncRollbackPhase());
- assertEquals("TransactionManagerLookupClass", BatchModeTransactionManagerLookup.class.getName(), wrapper.getTransactionManagerLookupClass());
- assertEquals("TransactionManagerLookupClass", BatchModeTransactionManagerLookup.class.getName(), c.getTransactionManagerLookupClass());
- assertEquals("ExposeManagementStatistics", false, wrapper.getExposeManagementStatistics());
- assertEquals("ExposeManagementStatistics", false, c.getExposeManagementStatistics());
- assertEquals("UseRegionBasedMarshalling", true, wrapper.getUseRegionBasedMarshalling());
- assertEquals("UseRegionBasedMarshalling", true, c.isUseRegionBasedMarshalling());
- assertEquals("UseReplQueue", true, wrapper.getUseReplQueue());
- assertEquals("UseReplQueue", true, c.isUseReplQueue());
-
- assertEquals("ClusterConfig", getClusterConfig().toString(), wrapper.getClusterConfig().toString());
-
- assertEquals("BuddyReplicationConfig", getBuddyReplicationConfig().toString(), wrapper.getBuddyReplicationConfig().toString());
- BuddyReplicationConfig brc = c.getBuddyReplicationConfig();
- assertEquals("BR enabled", true, brc.isEnabled());
- assertEquals("BR auto grav", false, brc.isAutoDataGravitation());
- assertEquals("BR remove find", false, brc.isDataGravitationRemoveOnFind());
- assertEquals("BR search backup", false, brc.isDataGravitationSearchBackupTrees());
- assertEquals("BR comm timeout", 600000, brc.getBuddyCommunicationTimeout());
- assertEquals("BR poolname", "testpool", brc.getBuddyPoolName());
- BuddyLocatorConfig blc = brc.getBuddyLocatorConfig();
- assertEquals("BR locator", "org.jboss.cache.buddyreplication.TestBuddyLocator", blc.getBuddyLocatorClass());
- Properties props = blc.getBuddyLocatorProperties();
- assertEquals("BR props", "2", props.get("numBuddies"));
-
- assertEquals("CacheLoaderConfig", getCacheLoaderConfig().toString(), wrapper.getCacheLoaderConfig().toString());
- CacheLoaderConfig clc = c.getCacheLoaderConfig();
- assertEquals("CL passivation", false, clc.isPassivation());
- assertEquals("CL passivation", true, clc.isShared());
- assertEquals("CL preload", "/foo", clc.getPreload());
- List<IndividualCacheLoaderConfig> iclcs = clc.getIndividualCacheLoaderConfigs();
- IndividualCacheLoaderConfig iclc = iclcs.get(0);
- assertEquals("CL0 class", FileCacheLoader.class.getName(), iclc.getClassName());
- assertEquals("CL0 async", false, iclc.isAsync());
- assertEquals("CL0 fetch", true, iclc.isFetchPersistentState());
- assertEquals("CL0 ignore", true, iclc.isIgnoreModifications());
- assertEquals("CL0 purge", true, iclc.isPurgeOnStartup());
- assertEquals("CL0 singleton", true, iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
- assertEquals("CL0 singleton class", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
- iclc = iclcs.get(1);
- assertEquals("CL1 class", JdbmCacheLoader.class.getName(), iclc.getClassName());
- assertEquals("CL1 async", true, iclc.isAsync());
- assertEquals("CL1 fetch", false, iclc.isFetchPersistentState());
- assertEquals("CL1 ignore", false, iclc.isIgnoreModifications());
- assertEquals("CL1 purge", false, iclc.isPurgeOnStartup());
- assertEquals("CL1 singleton", false, iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
- assertEquals("CL1 singleton class", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
-
- assertEquals("EvictionPolicyConfig", getEvictionPolicyConfig().toString(), wrapper.getEvictionPolicyConfig().toString());
- EvictionConfig ec = c.getEvictionConfig();
- assertEquals("EC queue size", 20000, ec.getDefaultEventQueueSize());
- assertEquals("EC wakeup", 5000, ec.getWakeupInterval());
- assertEquals("EC default pol", LRUPolicy.class.getName(), ec.getDefaultEvictionPolicyClass());
- List<EvictionRegionConfig> ercs = ec.getEvictionRegionConfigs();
- EvictionRegionConfig erc = ercs.get(0);
- assertEquals("ERC0 name", "/_default_", erc.getRegionName());
- assertEquals("ERC0 queue size", 1000, erc.getEventQueueSize());
- LRUConfiguration lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
- assertEquals("EPC0 pol", LRUPolicy.class.getName(), lru.getEvictionPolicyClass());
- assertEquals("EPC0 maxnodes", 5000, lru.getMaxNodes());
- assertEquals("EPC0 ttl", 1000000, lru.getTimeToLive());
- erc = ercs.get(1);
- assertEquals("ERC1 name", "/org/jboss/data", erc.getRegionName());
- assertEquals("ERC1 queue size", 20000, erc.getEventQueueSize());
- FIFOConfiguration fifo = (FIFOConfiguration) erc.getEvictionPolicyConfig();
- assertEquals("EPC1 pol", FIFOPolicy.class.getName(), fifo.getEvictionPolicyClass());
- assertEquals("EPC1 maxnodes", 5000, fifo.getMaxNodes());
- erc = ercs.get(2);
- assertEquals("ERC2 name", "/test", erc.getRegionName());
- assertEquals("ERC2 queue size", 20000, erc.getEventQueueSize());
- MRUConfiguration mru = (MRUConfiguration) erc.getEvictionPolicyConfig();
- assertEquals("EPC2 pol", MRUPolicy.class.getName(), mru.getEvictionPolicyClass());
- assertEquals("EPC2 maxnodes", 10000, mru.getMaxNodes());
- erc = ercs.get(3);
- assertEquals("ERC3 name", "/maxAgeTest", erc.getRegionName());
- assertEquals("ERC3 queue size", 20000, erc.getEventQueueSize());
- lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
- assertEquals("EPC3 pol", LRUPolicy.class.getName(), lru.getEvictionPolicyClass());
- assertEquals("EPC3 maxnodes", 10000, lru.getMaxNodes());
- assertEquals("EPC3 maxage", 10000, lru.getMaxAge());
- assertEquals("EPC3 ttl", 8000, lru.getTimeToLive());
-
- }
-
- @SuppressWarnings("unchecked")
- public void testRuntimeConfig() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper<String, String>();
- registerWrapper(wrapper);
-
- wrapper = (CacheJmxWrapperMBean<String, String>) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
-
- // Fake a TM by making a bogus proxy
- TransactionManager tm = (TransactionManager) Proxy.newProxyInstance(getClass().getClassLoader(),
- new Class[]{TransactionManager.class}, new MockInvocationHandler());
- wrapper.setTransactionManager(tm);
- ChannelFactory cf = new JChannelFactory();
- wrapper.setMuxChannelFactory(cf);
-
- RuntimeConfig rc = wrapper.getConfiguration().getRuntimeConfig();
-
- assertSame("Same TM", tm, wrapper.getTransactionManager());
- assertSame("Same TM", tm, rc.getTransactionManager());
- assertSame("Same ChannelFactory", cf, wrapper.getMuxChannelFactory());
- assertSame("Same ChannelFactory", cf, rc.getMuxChannelFactory());
- }
-
- @SuppressWarnings("unchecked")
- public void testLegacyMuxChannelCreation() throws Exception
- {
- CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper<String, String>();
- registerWrapper(wrapper);
-
- wrapper = (CacheJmxWrapperMBean<String, String>) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
- wrapper.setMultiplexerStack(MultiplexerTestHelper.MUX_STACK);
-
- JChannelFactory factory = new JChannelFactory();
- factory.setDomain("jbc.mux.test");
- factory.setExposeChannels(false);
- factory.setMultiplexerConfig(MultiplexerTestHelper.getClusterConfigElement(getDefaultProperties()));
-
- ObjectName on = new ObjectName("jgroups:service=Mux");
- mBeanServer.registerMBean(new org.jgroups.jmx.JChannelFactory(factory), on);
-
- wrapper.setMultiplexerService((JChannelFactoryMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, on, JChannelFactoryMBean.class, false));
-
- wrapper.start();
-
- RuntimeConfig rc = wrapper.getConfiguration().getRuntimeConfig();
- assertNotNull("Channel created", rc.getChannel());
- }
-
- protected static Element getBuddyReplicationConfig() throws Exception
- {
-
- String xmlStr =
- " <buddy enabled=\"true\" poolName=\"testpool\" communicationTimeout=\"600000\">\n" +
- " <dataGravitation auto=\"false\" removeOnFind=\"false\" searchBackupTrees=\"false\"/>\n" +
- " <locator class=\"org.jboss.cache.buddyreplication.TestBuddyLocator\">\n" +
- " <properties>\n" +
- " numBuddies = 2\n" +
- " </properties>\n" +
- " </locator>\n" +
- " </buddy>";
- return XmlConfigHelper.stringToElement(xmlStr);
- }
-
- protected static Element getCacheLoaderConfig() throws Exception
- {
- String xmlStr =
- " <loaders passivation=\"false\" shared=\"true\">\n" +
- " <preload>\n" +
- " <node fqn=\"/foo\"/>\n" +
- " </preload>\n" +
- " <loader class=\"org.jboss.cache.loader.FileCacheLoader\" async=\"false\" fetchPersistentState=\"true\"\n" +
- " ignoreModifications=\"true\" purgeOnStartup=\"true\">\n" +
- " <properties>\n" +
- " location=/tmp\n " +
- " </properties>\n" +
- " <singletonStore enabled=\"true\" /> \n" +
- " </loader>\n" +
- " <loader class=\"org.jboss.cache.loader.jdbm.JdbmCacheLoader\" async=\"true\" fetchPersistentState=\"false\"\n" +
- " ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
- " <properties>\n" +
- " location=/home/bstansberry\n" +
- " </properties>\n" +
- " <singletonStore enabled=\"false\" /> \n" +
- " </loader>\n" +
- " </loaders>";
- return XmlConfigHelper.stringToElement(xmlStr);
- }
-
- protected static Element getEvictionPolicyConfig() throws Exception
- {
-
- String xmlStr =
- " <eviction wakeUpInterval=\"5000\" defaultPolicyClass=\"org.jboss.cache.eviction.LRUPolicy\" defaultEventQueueSize=\"20000\">\n" +
- " <default eventQueueSize=\"1000\">\n" +
- " <attribute name=\"maxNodes\">5000</attribute>\n" +
- " <attribute name=\"timeToLive\">1000000</attribute>\n" +
- " </default>\n" +
- "<region name=\"/org/jboss/data\" policyClass=\"org.jboss.cache.eviction.FIFOPolicy\">\n" +
- " <attribute name=\"maxNodes\">5000</attribute>\n" +
- "</region>\n" +
- "<region name=\"/test/\" policyClass=\"org.jboss.cache.eviction.MRUPolicy\">\n" +
- " <attribute name=\"maxNodes\">10000</attribute>\n" +
- "</region>\n" +
- "<region name=\"/maxAgeTest/\">\n" +
- " <attribute name=\"maxNodes\">10000</attribute>\n" +
- " <attribute name=\"timeToLiveSeconds\">8</attribute>\n" +
- " <attribute name=\"maxAgeSeconds\">10</attribute>\n" +
- "</region>\n" +
- " </eviction>";
- return XmlConfigHelper.stringToElement(xmlStr);
- }
-
- protected static Element getClusterConfig() throws Exception
- {
- String xml =
- "<jgroupsConfig>\n" +
- "<UDP mcast_addr=\"228.10.10.10\"\n" +
- " mcast_port=\"45588\"\n" +
- " tos=\"8\"\n" +
- " ucast_recv_buf_size=\"20000000\"\n" +
- " ucast_send_buf_size=\"640000\"\n" +
- " mcast_recv_buf_size=\"25000000\"\n" +
- " mcast_send_buf_size=\"640000\"\n" +
- " loopback=\"false\"\n" +
- " discard_incompatible_packets=\"true\"\n" +
- " max_bundle_size=\"64000\"\n" +
- " max_bundle_timeout=\"30\"\n" +
- " use_incoming_packet_handler=\"true\"\n" +
- " ip_ttl=\"2\"\n" +
- " enable_bundling=\"false\"\n" +
- " enable_diagnostics=\"true\"\n" +
- " use_concurrent_stack=\"true\"\n" +
- " thread_naming_pattern=\"pl\"\n" +
- " thread_pool.enabled=\"true\"\n" +
- " thread_pool.min_threads=\"1\"\n" +
- " thread_pool.max_threads=\"25\"\n" +
- " thread_pool.keep_alive_time=\"30000\"\n" +
- " thread_pool.queue_enabled=\"true\"\n" +
- " thread_pool.queue_max_size=\"10\"\n" +
- " thread_pool.rejection_policy=\"Run\"\n" +
- " oob_thread_pool.enabled=\"true\"\n" +
- " oob_thread_pool.min_threads=\"1\"\n" +
- " oob_thread_pool.max_threads=\"4\"\n" +
- " oob_thread_pool.keep_alive_time=\"10000\"\n" +
- " oob_thread_pool.queue_enabled=\"true\"\n" +
- " oob_thread_pool.queue_max_size=\"10\"\n" +
- " oob_thread_pool.rejection_policy=\"Run\"/>\n" +
- " <PING timeout=\"2000\" num_initial_members=\"3\"/>\n" +
- " <MERGE2 max_interval=\"30000\" min_interval=\"10000\"/>\n" +
- " <FD_SOCK/>\n" +
- " <FD timeout=\"10000\" max_tries=\"5\" shun=\"true\"/>\n" +
- " <VERIFY_SUSPECT timeout=\"1500\"/>\n" +
- " <pbcast.NAKACK max_xmit_size=\"60000\"\n" +
- " use_mcast_xmit=\"false\" gc_lag=\"0\"\n" +
- " retransmit_timeout=\"300,600,1200,2400,4800\"\n" +
- " discard_delivered_msgs=\"true\"/>\n" +
- " <UNICAST timeout=\"300,600,1200,2400,3600\"/>\n" +
- " <pbcast.STABLE stability_delay=\"1000\" desired_avg_gossip=\"50000\"\n" +
- " max_bytes=\"400000\"/>\n" +
- " <pbcast.GMS print_local_addr=\"true\" join_timeout=\"5000\"\n" +
- " join_retry_timeout=\"2000\" shun=\"false\"\n" +
- " view_bundling=\"true\" view_ack_collection_timeout=\"5000\"/>\n" +
- " <FRAG2 frag_size=\"60000\"/>\n" +
- " <pbcast.STREAMING_STATE_TRANSFER use_reading_thread=\"true\"/>\n" +
- " <pbcast.FLUSH timeout=\"0\"/>\n" +
- "</jgroupsConfig>";
- return XmlConfigHelper.stringToElement(xml);
- }
-
- protected String getDefaultProperties()
- {
- return "UDP(mcast_addr=224.0.0.36;mcast_port=55566;ip_ttl=32;" +
- "mcast_send_buf_size=150000;mcast_recv_buf_size=80000):" +
- "PING(timeout=1000;num_initial_members=2):" +
- "MERGE2(min_interval=5000;max_interval=10000):" +
- "FD_SOCK:" +
- "VERIFY_SUSPECT(timeout=1500):" +
- "pbcast.NAKACK(gc_lag=50;max_xmit_size=8192;retransmit_timeout=600,1200,2400,4800):" +
- "UNICAST(timeout=600,1200,2400,4800):" +
- "pbcast.STABLE(desired_avg_gossip=20000):" +
- "FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
- "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
- "shun=false;print_local_addr=true):" +
- "pbcast.STATE_TRANSFER";
- }
-
- class MockInvocationHandler implements InvocationHandler
- {
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- return null;
- }
-
- }
-}
Deleted: core/trunk/src/test/java/org/jboss/cache/jmx/LifecycleNotificationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/LifecycleNotificationTest.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/LifecycleNotificationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -1,102 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.cache.jmx;
-
-import static org.testng.AssertJUnit.assertEquals;
-
-import javax.management.AttributeChangeNotification;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * A LifecycleNotificationTest.
- *
- * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
- * @version $Revision$
- */
-public class LifecycleNotificationTest extends CacheJmxWrapperTestBase
-{
- public void testGetStateAndStateNotification() throws Exception
- {
- CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
- StateNotificationListener listener = new StateNotificationListener();
- wrapper.addNotificationListener(listener, null, null);
-
- assertEquals("Correct state after instanitation",
- CacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
-
- registerWrapper(wrapper);
- assertEquals("Correct state after registration",
- CacheJmxWrapperMBean.REGISTERED, wrapper.getState());
-
- wrapper.create();
- assertEquals("Correct state after create",
- CacheJmxWrapperMBean.CREATED, wrapper.getState());
-
- wrapper.start();
- assertEquals("Correct state after start",
- CacheJmxWrapperMBean.STARTED, wrapper.getState());
-
- wrapper.stop();
- assertEquals("Correct state after stop",
- CacheJmxWrapperMBean.STOPPED, wrapper.getState());
-
- wrapper.destroy();
- assertEquals("Correct state after destroy",
- CacheJmxWrapperMBean.DESTROYED, wrapper.getState());
-
- unregisterWrapper();
- assertEquals("Correct state after unregistration",
- CacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
-
- System.out.println(listener.notifications);
- assertEquals("Correct number of notifications received", 4, listener.notifications.size());
- assertEquals("Correct first notification", new Integer(CacheJmxWrapperMBean.STARTING), listener.notifications.get(0));
- assertEquals("Correct second notification", new Integer(CacheJmxWrapperMBean.STARTED), listener.notifications.get(1));
- assertEquals("Correct third notification", new Integer(CacheJmxWrapperMBean.STOPPING), listener.notifications.get(2));
- assertEquals("Correct fourth notification", new Integer(CacheJmxWrapperMBean.STOPPED), listener.notifications.get(3));
- }
-
- private static class StateNotificationListener
- implements NotificationListener
- {
- private List<Integer> notifications = new LinkedList<Integer>();
-
- public void handleNotification(Notification msg, Object handback)
- {
- if (msg instanceof AttributeChangeNotification)
- {
- AttributeChangeNotification change = (AttributeChangeNotification) msg;
- String attrName = change.getAttributeName();
- Object newValue = change.getNewValue();
- if ("State".equals(attrName) && newValue != null && newValue instanceof Integer)
- {
- notifications.add((Integer) newValue);
- }
- }
- }
- }
-
-}
Deleted: core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -1,467 +0,0 @@
-package org.jboss.cache.jmx;
-
-import org.jboss.cache.CacheFactory;
-import org.jboss.cache.CacheSPI;
-import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.config.CacheLoaderConfig;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.Configuration.CacheMode;
-import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
-import org.jboss.cache.loader.CacheLoader;
-import static org.testng.AssertJUnit.*;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.ObjectName;
-import java.util.EnumSet;
-import java.util.HashMap;
-
-/**
- * Functional tests for CacheJmxWrapper broadcast of cache event notifications
- *
- * @author Jerry Gauthier
- * @version $Id$
- */
- at Test(groups = {"functional"})
-public class NotificationTest
-{
- protected static final String CLUSTER_NAME = "NotificationTestCluster";
-
- protected static final String CAPITAL = "capital";
- protected static final String CURRENCY = "currency";
- protected static final String POPULATION = "population";
- protected static final String EUROPE_NODE = "Europe";
-
- public enum Type
- {
- STARTED, STOPPED, PRECREATE, POSTCREATE, PREEVICT, POSTEVICT,
- PRELOAD, POSTLOAD, PREREMOVE, POSTREMOVE, PREVISIT, POSTVISIT,
- PREMODIFY, POSTMODIFY, PREACTIVATE, POSTACTIVATE, PREPASSIVATE,
- POSTPASSIVATE, VIEWCHANGE
- }
-
- protected MBeanServer m_server;
- protected EnumSet<Type> events = EnumSet.noneOf(Type.class);
-
- protected CacheSPI<Object, Object> cache = null;
- protected boolean optimistic = false;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp() throws Exception
- {
- m_server = MBeanServerFactory.createMBeanServer();
-
- Object cacheMBean = createCacheAndJmxWrapper();
-
- // bind manually for now.
- ObjectName mgmt = getWrapperObjectName();
-
- m_server.registerMBean(cacheMBean, mgmt);
- }
-
- protected Object createCacheAndJmxWrapper() throws Exception
- {
- cache = createCache(CLUSTER_NAME);
- return new CacheJmxWrapper<Object, Object>(cache);
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown() throws Exception
- {
- try
- {
- cleanup();
- }
- finally
- {
- // make sure we stop the mbean server
- if (m_server != null)
- MBeanServerFactory.releaseMBeanServer(m_server);
- }
- }
-
- protected void cleanup() throws Exception
- {
- events.clear();
-
- destroyCache();
-
- if (m_server != null)
- {
- ObjectName mgmt = getWrapperObjectName();
- if (m_server.isRegistered(mgmt))
- m_server.unregisterMBean(mgmt);
- }
- }
-
- protected void destroyCache()
- {
- if (cache != null)
- {
- // stop the cache before the listener is unregistered
- //cache1.stop();
- cache.destroy();
- cache = null;
- }
- }
-
- protected ObjectName getWrapperObjectName() throws Exception
- {
- return new ObjectName(JmxUtil.PREFIX + CLUSTER_NAME);
- }
-
- public void testNotifications() throws Exception
- {
- assertNotNull("MBeanServer is null.", m_server);
- assertNotNull("Cache is null.", cache);
-
- ObjectName mgmt = getWrapperObjectName();
- MyListener listener = new MyListener(mgmt);
-
-
- m_server.addNotificationListener(mgmt, listener, null, null);
-
- // start the cache after registering listener - this will trigger CacheStarted
- // since cache is defined with cluster, thiswill also trigger ViewChange
- cache.start();
-
- // add a node - this will trigger NodeCreated, NodeModify(pre/post) and NodeModified
- HashMap<Object, Object> albania = new HashMap<Object, Object>(4);
- albania.put(CAPITAL, "Tirana");
- albania.put(CURRENCY, "Lek");
- cache.put("Europe/Albania", albania);
-
- // modify a node - this will trigger NodeModified and NodeModify(pre/post)
- cache.put("Europe/Albania", POPULATION, 3563112);
-
- // retrieve an attribute - this will trigger NodeVisited
- Fqn key = Fqn.fromString("Europe/Albania");
- assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + key, cache.get(key, CURRENCY));
-
- // evict the node - this will trigger NodePassivate, NodeEvicted and NodeEvict(pre/post)
- cache.evict(key);
-
- // retrieve the attribute again - this will trigger NodeVisited and NodeActivate
- assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + key, cache.get(key, CURRENCY));
-
- // remove the node - this will trigger NodeRemoved and NodeRemove(pre/post)
- cache.removeNode(key);
-
- // clean up before stopping the cache
- CacheLoader cl = cache.getCacheLoaderManager().getCacheLoader();
- cl.remove(Fqn.fromString(EUROPE_NODE));
-
- // stop the cache
- cache.stop();
- m_server.removeNotificationListener(mgmt, listener);
-
- // run the tests
- assertTrue("Expected CacheStarted notification", events.contains(Type.STARTED));
- assertTrue("Expected CacheStopped notification", events.contains(Type.STOPPED));
- assertTrue("Expected NodeCreated notification", events.contains(Type.PRECREATE));
- assertTrue("Expected NodeCreated notification", events.contains(Type.POSTCREATE));
- assertTrue("Expected NodeEvicted notification", events.contains(Type.PREEVICT));
- assertTrue("Expected NodeEvicted notification", events.contains(Type.POSTEVICT));
- assertTrue("Expected NodeLoaded notification", events.contains(Type.PRELOAD));
- assertTrue("Expected NodeLoaded notification", events.contains(Type.POSTLOAD));
- assertTrue("Expected NodeVisited notification", events.contains(Type.PREVISIT));
- assertTrue("Expected NodeVisited notification", events.contains(Type.POSTVISIT));
- assertTrue("Expected NodeActivated notification", events.contains(Type.PREACTIVATE));
- assertTrue("Expected NodeActivated notification", events.contains(Type.POSTACTIVATE));
- assertTrue("Expected NodeModified notification", events.contains(Type.PREMODIFY));
- assertTrue("Expected NodeModified notification", events.contains(Type.POSTMODIFY));
- assertTrue("Expected NodePassivated notification", events.contains(Type.PREPASSIVATE));
- assertTrue("Expected NodePassivated notification", events.contains(Type.POSTPASSIVATE));
- assertTrue("Expected NodeRemoved notification", events.contains(Type.PREREMOVE));
- assertTrue("Expected NodeRemoved notification", events.contains(Type.POSTREMOVE));
- assertTrue("Expected ViewChange notification", events.contains(Type.VIEWCHANGE));
- validateHealthyListener(listener);
- }
-
- public void testEarlyRegistration() throws Exception
- {
- // undo setup
- cleanup();
-
- CacheJmxWrapper<Object, Object> wrapper = new CacheJmxWrapper<Object, Object>();
- ObjectName mgmt = getWrapperObjectName();
- m_server.registerMBean(wrapper, mgmt);
- MyListener listener = new MyListener(mgmt);
- m_server.addNotificationListener(mgmt, listener, null, null);
-
- cache = createCache(CLUSTER_NAME);
- wrapper.setCache(cache);
- cache.start();
- try
- {
- assertTrue("Expected CacheStarted notification", events.contains(Type.STARTED));
- validateHealthyListener(listener);
- }
- finally
- {
- cache.stop();
- }
- }
-
- public void testLateRegistration() throws Exception
- {
- assertNotNull("MBeanServer is null.", m_server);
- assertNotNull("Cache is null.", cache);
-
- // start the cache before registering listener
- cache.start();
-
- try
- {
- ObjectName mgmt = getWrapperObjectName();
- MyListener listener = new MyListener(mgmt);
-
- m_server.addNotificationListener(mgmt, listener, null, null);
-
- // add a node - this will trigger NodeCreated, NodeModify(pre/post) and NodeModified
- HashMap<Object, Object> albania = new HashMap<Object, Object>(4);
- albania.put(CAPITAL, "Tirana");
- albania.put(CURRENCY, "Lek");
- cache.put("Europe/Albania", albania);
-
- // run the tests
- assertTrue("Expected NodeModified notification", events.contains(Type.PREMODIFY));
- assertTrue("Expected NodeModified notification", events.contains(Type.POSTMODIFY));
- validateHealthyListener(listener);
- }
- finally
- {
- cache.stop();
- }
- }
-
- public void testListenerRemoval() throws Exception
- {
- assertNotNull("MBeanServer is null.", m_server);
- assertNotNull("Cache is null.", cache);
-
- ObjectName mgmt = getWrapperObjectName();
- MyListener listener = new MyListener(mgmt);
-
- m_server.addNotificationListener(mgmt, listener, null, null);
-
- // start the cache after registering listener - this will trigger CacheStarted
- // since cache is defined with cluster, thiswill also trigger ViewChange
- cache.start();
- boolean ok = false;
- try
- {
- assertTrue("Expected CacheStarted notification", events.contains(Type.STARTED));
-
- m_server.removeNotificationListener(mgmt, listener);
- ok = true;
- }
- finally
- {
- cache.stop();
- if (ok)
- {
- assertFalse("Expected no CacheStopped notification", events.contains(Type.STOPPED));
- validateHealthyListener(listener);
- }
- }
- }
-
- private CacheSPI<Object, Object> createCache(String clusterName) throws Exception
- {
- Configuration config = createConfiguration(clusterName);
- CacheFactory<Object, Object> factory = new DefaultCacheFactory<Object, Object>();
- CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) factory.createCache(config, false);
-
- cache.create();
- // start the cache after the listener has been registered
- //cache.start();
- return cache;
- }
-
- protected Configuration createConfiguration(String clusterName) throws Exception
- {
- Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
- config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
- config.setCacheLoaderConfig(getCacheLoaderConfig("location=" + getTempDir()));
- config.setExposeManagementStatistics(true);
- config.setClusterName(clusterName);
- if (optimistic)
- {
- config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- config.setNodeLockingScheme("OPTIMISTIC");
- }
-
- return config;
- }
-
- private static String getTempDir()
- {
- return System.getProperty("java.io.tempdir", "/tmp");
- }
-
- private static boolean getPre(Object data)
- {
- assertNotNull("User data is null, should be Object[]", data);
- assertTrue("User data is " + data.getClass().getName() + ", should be Object[]", data instanceof Object[]);
-
- Object[] parms = (Object[]) data;
- assertTrue("Parameter is " + parms[1].getClass().getName() + ", should be Boolean", parms[1] instanceof Boolean);
- return (Boolean) parms[1];
- }
-
- protected static CacheLoaderConfig getCacheLoaderConfig(String properties) throws Exception
- {
- return UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(true, "",
- "org.jboss.cache.loader.FileCacheLoader", properties, false, false, true, false, false);
- }
-
- private static void validateHealthyListener(MyListener listener)
- {
- if (listener.failure != null)
- throw listener.failure;
- if (listener.exception != null)
- throw listener.exception;
- }
-
- private class MyListener implements NotificationListener
- {
- private RuntimeException exception;
- private AssertionError failure;
- private final String emitterObjectName;
-
- MyListener(ObjectName emitter)
- {
- this.emitterObjectName = emitter.getCanonicalName();
- }
-
- public void handleNotification(Notification notification, Object handback)
- {
- try
- {
- String type = notification.getType();
- Object userData = notification.getUserData();
-
- if (type.equals(CacheNotificationBroadcaster.NOTIF_CACHE_STARTED))
- {
- events.add(Type.STARTED);
- assertEquals("Correct object name in start notification", emitterObjectName, userData);
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_CACHE_STOPPED))
- {
- events.add(Type.STOPPED);
- assertEquals("Correct object name in stop notification", emitterObjectName, userData);
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_CREATED))
- {
- if (getPre(userData))
- {
- events.add(Type.PRECREATE);
- }
- else
- {
- events.add(Type.POSTCREATE);
- }
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_EVICTED))
- {
- if (getPre(userData))
- {
- events.add(Type.PREEVICT);
- }
- else
- {
- events.add(Type.POSTEVICT);
- }
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_LOADED))
- {
- if (getPre(userData))
- {
- events.add(Type.PRELOAD);
- }
- else
- {
- events.add(Type.POSTLOAD);
- }
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_REMOVED))
- {
- if (getPre(userData))
- {
- events.add(Type.PREREMOVE);
- }
- else
- {
- events.add(Type.POSTREMOVE);
- }
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_VISITED))
- {
- if (getPre(userData))
- {
- events.add(Type.PREVISIT);
- }
- else
- {
- events.add(Type.POSTVISIT);
- }
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_VIEW_CHANGED))
- {
- events.add(Type.VIEWCHANGE);
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_ACTIVATED))
- {
- if (getPre(userData))
- {
- events.add(Type.PREACTIVATE);
- }
- else
- {
- events.add(Type.POSTACTIVATE);
- }
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_MODIFIED))
- {
- if (getPre(userData))
- {
- events.add(Type.PREMODIFY);
- }
- else
- {
- events.add(Type.POSTMODIFY);
- }
- }
- else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_PASSIVATED))
- {
- if (getPre(userData))
- {
- events.add(Type.PREPASSIVATE);
- }
- else
- {
- events.add(Type.POSTPASSIVATE);
- }
- }
- }
- catch (RuntimeException e)
- {
- // Store so the test can rethrow
- exception = e;
- }
- catch (AssertionError e)
- {
- // Store so the test can rethrow
- failure = e;
- }
- }
- }
-
-}
Deleted: core/trunk/src/test/java/org/jboss/cache/jmx/OptimisticNotificationTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/OptimisticNotificationTest.java 2008-08-08 15:15:14 UTC (rev 6545)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/OptimisticNotificationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -1,19 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache.jmx;
-
-
-/**
- * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
- */
-public class OptimisticNotificationTest extends NotificationTest
-{
- public OptimisticNotificationTest()
- {
- optimistic = true;
- }
-}
Copied: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTest.java (from rev 6541, core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -0,0 +1,456 @@
+package org.jboss.cache.jmx.deprecated;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.jmx.CacheJmxWrapper;
+import org.jboss.cache.jmx.JmxRegistrationManager;
+import org.jboss.cache.jmx.CacheJmxWrapperMBean;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.CacheStarted;
+import org.jboss.cache.notifications.annotation.CacheStopped;
+import org.jboss.cache.notifications.event.Event;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.jboss.cache.util.CachePrinter;
+import org.jboss.cache.util.TestingUtil;
+import org.jgroups.Address;
+import org.jgroups.stack.IpAddress;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
+
+import javax.management.ObjectName;
+import javax.transaction.TransactionManager;
+import java.util.List;
+
+/**
+ * Tests the JMX wrapper class around the cache.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ * @author Brian Stansberry
+ */
+ at Test(groups = "functional")
+public class CacheJmxWrapperTest extends CacheJmxWrapperTestBase
+{
+ public void testCacheMBeanBinding() throws Exception
+ {
+ registerWrapper();
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+ }
+
+ public void testSetCacheObjectName() throws Exception
+ {
+ ObjectName on = new ObjectName("jboss.cache:test=SetCacheObjectName");
+ boolean registered = false;
+ try
+ {
+ CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
+ wrapper.setCacheObjectName(on.getCanonicalName());
+
+ // Register under the standard name
+ registerWrapper(wrapper);
+ // Should be registered under 'on'
+ registered = mBeanServer.isRegistered(on);
+
+ assertTrue("Registered with configured name", registered);
+ assertEquals("Configured name retained", on.getCanonicalName(), wrapper.getCacheObjectName());
+
+ wrapper.create();
+ wrapper.start();
+
+ interceptorRegistrationTest(on.getCanonicalName(), true);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ interceptorRegistrationTest(false);
+ }
+ finally
+ {
+ if (registered)
+ mBeanServer.unregisterMBean(on);
+ }
+ }
+
+ public void testGetCacheObjectName() throws Exception
+ {
+ ObjectName on = new ObjectName("jboss.cache:test=SetCacheObjectName");
+ String str = on.getCanonicalName();
+ CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
+ wrapper.setCacheObjectName(str);
+
+ assertEquals("Setter and getter match", str, wrapper.getCacheObjectName());
+
+ // Go back to the default
+ wrapper.setCacheObjectName(null);
+ assertEquals("Got default ObjectName", JmxRegistrationManager.CLUSTERED_CACHE_PREFIX + CLUSTER_NAME, wrapper.getCacheObjectName());
+
+ registerWrapper(wrapper);
+ assertEquals("Returns standard name", mBeanName, new ObjectName(wrapper.getCacheObjectName()));
+ }
+
+ public void testGetConfiguration1() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
+ Configuration cfgFromJmx = wrapper.getConfiguration();
+ assertNotNull("Got a configuration", cfgFromJmx);
+ assertSame(cache.getConfiguration(), cfgFromJmx);
+ }
+
+ public void testGetConfiguration2() throws Exception
+ {
+ Configuration cfg = createConfiguration();
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(cfg);
+ Configuration cfgFromJmx = wrapper.getConfiguration();
+ assertNotNull("Got a configuration", cfgFromJmx);
+ assertSame(cfg, cfgFromJmx);
+ }
+
+ /**
+ * Note that this is a bit of a 'white box' test as it assumes that the
+ * returned String equals Configuration.toString(). That could change and
+ * break this test; if it does, and there's nothing wrong with the
+ * change, just modify the test.
+ *
+ * @throws Exception
+ */
+ public void testPrintConfigurationAsString1() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
+ String cfgFromJmx = wrapper.printConfigurationAsString();
+ assertEquals(cache.getConfiguration().toString(), cfgFromJmx);
+ }
+
+ /**
+ * Note that this is a bit of a 'white box' test as it assumes that the
+ * returned String equals Configuration.toString(). That could change and
+ * break this test; if it does, and there's nothing wrong with the
+ * change, just modify the test.
+ *
+ * @throws Exception
+ */
+ public void testPrintConfigurationAsString2() throws Exception
+ {
+ Configuration cfg = createConfiguration();
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(cfg);
+ wrapper.create();
+ wrapper.start();
+ String cfgFromJmx = wrapper.printConfigurationAsString();
+ assertEquals(wrapper.getCache().getConfiguration().toString(), cfgFromJmx);
+ }
+
+ /**
+ * Note that this is a bit of a 'white box' test as it checks
+ * the currently coded HTML format and assumes that the HTML content is
+ * derived from Configuration.toString(). That could change and break
+ * this test; if it does, and there's nothing wrong with the
+ * change, just modify the test.
+ *
+ * @throws Exception
+ */
+ public void testPrintConfigurationAsHtml1() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
+ String cfgFromJmx = wrapper.printConfigurationAsHtmlString();
+ assertEquals(CacheJmxWrapper.formatHtml(cache.getConfiguration().toString()), cfgFromJmx);
+ checkHtml(cfgFromJmx, false);
+ }
+
+ /**
+ * Note that this is a bit of a 'white box' test as it checks
+ * the currently coded HTML format and assumes that the HTML content is
+ * derived from Configuration.toString(). That could change and break
+ * this test; if it does, and there's nothing wrong with the
+ * change, just modify the test.
+ *
+ * @throws Exception
+ */
+ public void testPrintConfigurationAsHtml2() throws Exception
+ {
+ Configuration cfg = createConfiguration();
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(cfg);
+ wrapper.create();
+ wrapper.start();
+ String cfgFromJmx = wrapper.printConfigurationAsHtmlString();
+ assertEquals(CacheJmxWrapper.formatHtml(wrapper.getCache().getConfiguration().toString()), cfgFromJmx);
+ checkHtml(cfgFromJmx, false);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGetCache() throws Exception
+ {
+ registerWrapper();
+ // have to start the cache before we'll have a root
+ cache.start();
+
+ Cache<String, String> cacheJmx = (Cache<String, String>) mBeanServer.getAttribute(mBeanName, "Cache");
+ cacheJmx.getRoot().put("key", "value");
+
+ assertEquals("value", cache.getRoot().get("key"));
+
+ Fqn fqn = Fqn.fromString("/testing/jmx");
+ cache.put(fqn, "key", "value");
+
+ assertEquals("value", cacheJmx.get(fqn, "key"));
+ }
+
+ public void testPrintCacheDetails() throws Exception
+ {
+ printCacheDetailsTest(false);
+ }
+
+ /**
+ * Note that this is a bit of a 'white box' test as it checks
+ * the currently coded HTML format. That could change and break
+ * this test; if it does, and there's nothing wrong with the
+ * change, just modify the test.
+ *
+ * @throws Exception
+ */
+ public void testPrintCacheDetailsAsHtml() throws Exception
+ {
+ String html = printCacheDetailsTest(true);
+ checkHtml(html, true);
+ }
+
+ public void testPrintLockInfo() throws Exception
+ {
+ printLockInfoTest(false);
+ }
+
+ /**
+ * Note that this is a bit of a 'white box' test as it checks
+ * the currently coded HTML format. That could change and break
+ * this test; if it does, and there's nothing wrong with the
+ * change, just modify the test.
+ *
+ * @throws Exception
+ */
+ public void testPrintLockInfoAsHtml() throws Exception
+ {
+ printLockInfoTest(true);
+ }
+
+ public void testGetLocalAddress() throws Exception
+ {
+ Configuration c = createConfiguration();
+ c.setCacheMode(CacheMode.REPL_ASYNC);
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(c);
+ wrapper.start();
+ assertTrue("Got an IpAddress", wrapper.getLocalAddress() instanceof IpAddress);
+ }
+
+ public void testGetMembers() throws Exception
+ {
+ Configuration c = createConfiguration();
+ c.setCacheMode(CacheMode.REPL_ASYNC);
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(c);
+ wrapper.start();
+
+ c = createConfiguration();
+ c.setCacheMode(CacheMode.REPL_ASYNC);
+ Cache cache2 = null;
+ try
+ {
+ cache2 = createCache(c);
+ cache2.start();
+ Cache[] caches = new Cache[]{wrapper.getCache(), cache2};
+ TestingUtil.blockUntilViewsReceived(caches, 5000);
+
+ Address addr = wrapper.getLocalAddress();
+ assertNotNull("Got an Address", addr);
+ List members = wrapper.getMembers();
+ assertNotNull("Got members", addr);
+ assertEquals("Got correct number of members", 2, members.size());
+ assertTrue("I am a member", members.contains(addr));
+ }
+ finally
+ {
+ if (cache2 != null)
+ {
+ cache2.destroy();
+ }
+ }
+ }
+
+ public void testDuplicateInvocation() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> cache = registerWrapper();
+ cache.create();
+ cache.start();
+ cache.create();
+ cache.start();
+
+ cache.getCache().put(Fqn.fromString("/a/b/c"), null);
+ assertTrue(cache.getNumberOfNodes() > 0);
+ assertEquals(0, cache.getNumberOfAttributes());
+
+ System.out.println("cache locks before restart:\n" + cache.printLockInfo());
+ cache.destroy();
+ cache.start();
+ System.out.println("cache locks after restart:\n" + cache.printLockInfo());
+
+ assertEquals(0, cache.getNumberOfNodes());
+ assertEquals(0, cache.getNumberOfAttributes());
+
+ cache.stop();
+ cache.destroy();
+ cache.stop();
+ cache.destroy();
+ }
+
+ public void testFailedStart() throws Exception
+ {
+ CacheJmxWrapper<String, String> wrapper = new CacheJmxWrapper<String, String>(createCache(createConfiguration()));
+ registerWrapper(wrapper);
+ assertEquals("Correct state", CacheStatus.INSTANTIATED, wrapper.getCacheStatus());
+ wrapper.create();
+
+ DisruptLifecycleListener listener = new DisruptLifecycleListener();
+ listener.setDisrupt(true);
+ wrapper.getCache().addCacheListener(listener);
+
+ assertEquals("Correct state", CacheStatus.CREATED, wrapper.getCacheStatus());
+ try
+ {
+ wrapper.start();
+ fail("Listener did not prevent start");
+ }
+ catch (CacheException good)
+ {
+ }
+
+ assertEquals("Correct state", CacheStatus.FAILED, wrapper.getCacheStatus());
+
+ listener.setDisrupt(false);
+
+ wrapper.start();
+
+ assertEquals("Correct state", CacheStatus.STARTED, wrapper.getCacheStatus());
+
+ wrapper.getCache().put(Fqn.fromString("/a/b/c"), null);
+ assertTrue(wrapper.getNumberOfNodes() > 0);
+ assertEquals(0, wrapper.getNumberOfAttributes());
+
+ listener.setDisrupt(true);
+ // need to re-add the listener since the failed start would have nullified the notifier.
+ cache.addCacheListener(listener);
+
+ try
+ {
+ wrapper.stop();
+ fail("Listener did not prevent stop");
+ }
+ catch (CacheException good)
+ {
+ }
+
+ assertEquals("Correct state", CacheStatus.FAILED, wrapper.getCacheStatus());
+
+ listener.setDisrupt(false);
+
+ wrapper.stop();
+ assertEquals("Correct state", CacheStatus.STOPPED, wrapper.getCacheStatus());
+ wrapper.destroy();
+ assertEquals("Correct state", CacheStatus.DESTROYED, wrapper.getCacheStatus());
+ }
+
+ private String printCacheDetailsTest(boolean html) throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
+
+ // have to start the cache before we'll have a root
+ cache.start();
+ Fqn fqn = Fqn.fromString("/testing/jmx");
+ cache.put(fqn, "foobar", "barfoo");
+
+ assertEquals("barfoo", cache.get(fqn, "foobar"));
+
+ String details = html ? wrapper.printCacheDetailsAsHtml() : wrapper.printCacheDetails();
+
+
+ System.out.println("Cache details: " + CachePrinter.printCacheDetails(cache));
+ System.out.println("Details: " + details);
+
+ assertTrue("Details include testing", details.contains("testing"));
+ assertTrue("Details include jmx", details.contains("jmx"));
+ assertTrue("Details include foobar", details.contains("foobar"));
+ assertTrue("Details include barfoo", details.contains("barfoo"));
+
+ return details;
+ }
+
+ private String printLockInfoTest(boolean html) throws Exception
+ {
+ Configuration config = createConfiguration();
+ config.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ Cache<String, String> c = createCache(config);
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(c);
+
+// wrapper.setManageCacheLifecycle(true);
+ wrapper.create();
+ wrapper.start();
+
+ TransactionManager tm = config.getRuntimeConfig().getTransactionManager();
+
+ tm.begin();
+ try
+ {
+ Fqn fqn = Fqn.fromString("/testing/jmx");
+ cache.put(fqn, "foobar", "barfoo");
+
+ String locks = html ? wrapper.printLockInfoAsHtml() : wrapper.printLockInfo();
+
+ assertTrue("Details include testing", locks.contains("testing"));
+ assertTrue("Details include jmx", locks.contains("jmx"));
+
+ return locks;
+ }
+ catch (Exception e)
+ {
+ tm.setRollbackOnly();
+ throw e;
+ }
+ finally
+ {
+ tm.commit();
+ }
+
+ }
+
+ private void checkHtml(String html, boolean checkBR)
+ {
+ if (checkBR)
+ assertTrue("Has <br", html.contains("<br"));
+
+ assertTrue("No tabs", html.indexOf('\t') == -1);
+
+ assertTrue("No spaces", html.indexOf(' ') == -1);
+
+ }
+
+ @CacheListener
+ public class DisruptLifecycleListener
+ {
+ private boolean disrupt;
+
+ @CacheStarted
+ public void cacheStarted(Event e)
+ {
+ if (disrupt) throw new IllegalStateException("I don't want to start");
+ }
+
+ @CacheStopped
+ public void cacheStopped(Event e)
+ {
+ if (disrupt) throw new IllegalStateException("I don't want to stop");
+ }
+
+ public void setDisrupt(boolean disrupt)
+ {
+ this.disrupt = disrupt;
+ }
+ }
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTestBase.java (from rev 6541, core/trunk/src/test/java/org/jboss/cache/jmx/CacheJmxWrapperTestBase.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTestBase.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTestBase.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -0,0 +1,178 @@
+package org.jboss.cache.jmx.deprecated;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.jmx.CacheJmxWrapperMBean;
+import org.jboss.cache.jmx.JmxRegistrationManager;
+import org.jboss.cache.jmx.CacheJmxWrapper;
+import org.jboss.cache.config.Configuration;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+/**
+ * Tests the JMX wrapper class around the cache.
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ * @author Brian Stansberry
+ */
+ at Test(groups = "functional")
+public abstract class CacheJmxWrapperTestBase
+{
+ public static final String CLUSTER_NAME = "CacheMBeanTest";
+
+ protected Cache<String, String> cache;
+ protected CacheJmxWrapperMBean<String, String> jmxWrapper;
+ protected MBeanServer mBeanServer;
+ protected ObjectName mBeanName;
+ protected String mBeanNameStr;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+ mBeanServer = MBeanServerFactory.createMBeanServer("CacheMBeanTest");
+
+ mBeanNameStr = JmxRegistrationManager.CLUSTERED_CACHE_PREFIX + CLUSTER_NAME;
+ mBeanName = new ObjectName(mBeanNameStr);
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ cleanup();
+ }
+ finally
+ {
+ if (mBeanServer != null)
+ {
+ MBeanServerFactory.releaseMBeanServer(mBeanServer);
+ mBeanServer = null;
+ }
+ }
+ }
+
+ protected CacheJmxWrapperMBean<String, String> registerWrapper() throws Exception
+ {
+ if (cache == null)
+ cache = createCache(createConfiguration());
+ return registerWrapper(cache);
+ }
+
+ protected CacheJmxWrapperMBean<String, String> registerWrapper(Cache<String, String> toWrap) throws Exception
+ {
+ CacheJmxWrapper<String, String> wrapper = new CacheJmxWrapper<String, String>(toWrap);
+ return registerWrapper(wrapper);
+ }
+
+ protected CacheJmxWrapperMBean<String, String> registerWrapper(Configuration config) throws Exception
+ {
+ CacheJmxWrapper<String, String> wrapper = new CacheJmxWrapper<String, String>();
+ wrapper.setConfiguration(config);
+ return registerWrapper(wrapper);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected CacheJmxWrapperMBean<String, String> registerWrapper(CacheJmxWrapperMBean<String, String> wrapper) throws Exception
+ {
+ ObjectName on = new ObjectName(mBeanNameStr);
+ if (!mBeanServer.isRegistered(on))
+ {
+ mBeanServer.registerMBean(wrapper, on);
+ }
+ jmxWrapper = (CacheJmxWrapperMBean<String, String>) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
+ return jmxWrapper;
+ }
+
+ protected void unregisterWrapper() throws Exception
+ {
+ mBeanServer.unregisterMBean(mBeanName);
+ }
+
+ protected CacheJmxWrapper<String, String> createWrapper(Configuration config)
+ {
+ CacheJmxWrapper<String, String> wrapper = new CacheJmxWrapper<String, String>();
+ wrapper.setConfiguration(config);
+ return wrapper;
+ }
+
+ protected Cache<String, String> createCache(Configuration config)
+ {
+ CacheFactory<String, String> factory = new DefaultCacheFactory<String, String>();
+ cache = factory.createCache(config, false);
+ return cache;
+ }
+
+ protected Configuration createConfiguration()
+ {
+ Configuration c = new Configuration();
+ c.setClusterName(CLUSTER_NAME);
+ c.setExposeManagementStatistics(true);
+ c.setCacheMode(Configuration.CacheMode.LOCAL);
+ return c;
+ }
+
+ private void cleanup() throws Exception
+ {
+ if (cache != null)
+ {
+ try
+ {
+ cache.stop();
+ }
+ catch (Exception ignored)
+ {
+ }
+
+ cache = null;
+ }
+ if (jmxWrapper != null)
+ {
+ try
+ {
+ jmxWrapper.stop();
+ jmxWrapper.destroy();
+ }
+ catch (Exception ignored)
+ {
+ }
+
+ jmxWrapper = null;
+ }
+
+ if (mBeanServer != null && mBeanName != null && mBeanServer.isRegistered(mBeanName))
+ mBeanServer.unregisterMBean(mBeanName);
+ }
+
+ protected void interceptorRegistrationTest(boolean expectMbeans) throws MalformedObjectNameException, NullPointerException
+ {
+ interceptorRegistrationTest(mBeanNameStr, expectMbeans);
+ }
+
+ protected void interceptorRegistrationTest(String baseName, boolean expectMbeans) throws MalformedObjectNameException, NullPointerException
+ {
+ // should be 3 interceptor MBeans loaded:
+ ObjectName[] interceptorMBeanNames = {
+ new ObjectName(baseName + JmxRegistrationManager.JMX_RESOURCE_KEY + "TxInterceptor"),
+ new ObjectName(baseName + JmxRegistrationManager.JMX_RESOURCE_KEY + "CacheMgmtInterceptor"),
+ };
+
+ for (ObjectName n : interceptorMBeanNames)
+ {
+ if (expectMbeans)
+ assertTrue(n + " should be registered", mBeanServer.isRegistered(n));
+ else
+ assertFalse(n + " should not be registered", mBeanServer.isRegistered(n));
+ }
+ }
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/CacheJmxWrapperTestBase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/InterceptorRegistrationTest.java (from rev 6541, core/trunk/src/test/java/org/jboss/cache/jmx/InterceptorRegistrationTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/InterceptorRegistrationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/InterceptorRegistrationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -0,0 +1,386 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cache.jmx.deprecated;
+
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.jmx.CacheJmxWrapperMBean;
+import org.jboss.cache.jmx.CacheJmxWrapper;
+import static org.testng.AssertJUnit.assertTrue;
+import org.testng.annotations.Test;
+
+/**
+ * Tests the interceptor registration function of CacheJmxWrapper.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+ at Test(groups = "functional")
+public class InterceptorRegistrationTest extends CacheJmxWrapperTestBase
+{
+
+ /**
+ * Confirms interceptor mbeans are registered if the following events
+ * occur:
+ * <p/>
+ * cache.start();
+ * wrapper creation and registration.
+ *
+ * @throws Exception
+ */
+ public void testInterceptorMBeans1() throws Exception
+ {
+ // have to start the cache to have any interceptors
+ createCache(createConfiguration());
+ cache.start();
+
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(cache);
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ interceptorRegistrationTest(true);
+
+ // These should be ignored because we
+ // never did wrapper.create()/start()
+ wrapper.stop();
+ wrapper.destroy();
+
+ // Should still be registered
+ interceptorRegistrationTest(true);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ /**
+ * Confirms interceptor mbeans are registered if the following events
+ * occur:
+ * <p/>
+ * cache.start();
+ * wrapper creation and and start
+ * wrapper registration.
+ *
+ * @throws Exception
+ */
+ public void testInterceptorMBeans2() throws Exception
+ {
+ // have to start the cache to have any interceptors
+ createCache(createConfiguration());
+ cache.start();
+
+ CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper<String, String>(cache);
+ wrapper.start();
+ wrapper = registerWrapper(wrapper);
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ interceptorRegistrationTest(true);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ // Should still no longer be registered
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ /**
+ * Confirms interceptor mbeans are registered if the following events
+ * occur:
+ * <p/>
+ * Cache not injected
+ * wrapper registered;
+ * wrapper created and started.
+ *
+ * @throws Exception
+ */
+ public void testInterceptorMBeans3() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper(createConfiguration());
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ // have to start the cache to have any interceptors
+ wrapper.create();
+ wrapper.start();
+
+ interceptorRegistrationTest(true);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ // Destroy should unregister if we are managing
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ /**
+ * Confirms interceptor mbeans are registered if the following events
+ * occur:
+ * <p/>
+ * Cache not injected
+ * wrapper created and started.
+ * wrapper registered
+ *
+ * @throws Exception
+ */
+ public void testInterceptorMBeans4() throws Exception
+ {
+ CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
+
+ // have to start the cache to have any interceptors
+ wrapper.create();
+ wrapper.start();
+
+ registerWrapper(wrapper);
+
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ interceptorRegistrationTest(true);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ // Destroy should unregister if we are managing
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ /**
+ * Confirms interceptor mbeans are registered if the following events
+ * occur:
+ * <p/>
+ * cache constructed;
+ * wrapper constructed and registered with manageCacheLifecycle=true
+ * wrapper created and started
+ *
+ * @throws Exception
+ */
+ public void testInterceptorMBeans5() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
+// wrapper.setManageCacheLifecycle(true);
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ // have to start the cache to have any interceptors
+ wrapper.create();
+ wrapper.start();
+
+ interceptorRegistrationTest(true);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ // Destroy should unregister if we are managing
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ /**
+ * Confirms interceptor mbeans are registered if the following events
+ * occur:
+ * <p/>
+ * cache constructed;
+ * wrapper constructed and registered
+ * wrapper created and started
+ *
+ * @throws Exception
+ */
+ public void testInterceptorMBeans6() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = registerWrapper();
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ // have to start the cache to have any interceptors
+ wrapper.create();
+ wrapper.start();
+
+ interceptorRegistrationTest(true);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ /**
+ * Confirms interceptor mbeans are registered if the following events
+ * occur:
+ * <p/>
+ * cache constructed;
+ * wrapper created and started
+ * wrapper registered
+ *
+ * @throws Exception
+ */
+ public void testInterceptorMBeans7() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper<String, String>(createCache(createConfiguration()));
+
+ // have to start the cache to have any interceptors
+ wrapper.create();
+ wrapper.start();
+
+ wrapper = registerWrapper(wrapper);
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ interceptorRegistrationTest(true);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ /**
+ * Tests that setting registerInterceptors=false disables interceptor
+ * registration when the wrapper is registered before create/start
+ * are called.
+ *
+ * @throws Exception
+ */
+ public void testRegisterInterceptors1() throws Exception
+ {
+ CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
+ wrapper.setRegisterJmxResource(false);
+
+ registerWrapper(wrapper);
+
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ wrapper.create();
+ wrapper.start();
+
+ interceptorRegistrationTest(false);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ /**
+ * Tests that setting registerInterceptors=false disables interceptor
+ * registration when the wrapper is registered after create/start
+ * are called.
+ *
+ * @throws Exception
+ */
+ public void testRegisterInterceptors2() throws Exception
+ {
+ CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
+ wrapper.setRegisterJmxResource(false);
+
+ wrapper.create();
+ wrapper.start();
+
+ registerWrapper(wrapper);
+
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ interceptorRegistrationTest(false);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ public void testExposeManagementStatistics1() throws Exception
+ {
+ Configuration cfg = createConfiguration();
+ cfg.setExposeManagementStatistics(false);
+
+ CacheJmxWrapper<String, String> wrapper = createWrapper(cfg);
+ registerWrapper(cfg);
+
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ wrapper.create();
+ wrapper.start();
+
+ interceptorRegistrationTest(false);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+ }
+
+ public void testExposeManagementStatistics2() throws Exception
+ {
+ Configuration cfg = createConfiguration();
+ cfg.setExposeManagementStatistics(false);
+
+ CacheJmxWrapper<String, String> wrapper = createWrapper(cfg);
+
+ wrapper.create();
+ wrapper.start();
+
+ registerWrapper(wrapper);
+
+ assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
+
+ interceptorRegistrationTest(false);
+
+ wrapper.stop();
+ wrapper.destroy();
+
+ interceptorRegistrationTest(false);
+
+ unregisterWrapper();
+
+ interceptorRegistrationTest(false);
+
+ }
+
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/InterceptorRegistrationTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LegacyConfigurationTest.java (from rev 6541, core/trunk/src/test/java/org/jboss/cache/jmx/LegacyConfigurationTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LegacyConfigurationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LegacyConfigurationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -0,0 +1,415 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cache.jmx.deprecated;
+
+import org.jboss.cache.Version;
+import org.jboss.cache.jmx.CacheJmxWrapperMBean;
+import org.jboss.cache.jmx.CacheJmxWrapper;
+import org.jboss.cache.config.BuddyReplicationConfig;
+import org.jboss.cache.config.BuddyReplicationConfig.BuddyLocatorConfig;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.config.EvictionConfig;
+import org.jboss.cache.config.EvictionRegionConfig;
+import org.jboss.cache.config.RuntimeConfig;
+import org.jboss.cache.config.parsing.XmlConfigHelper;
+import org.jboss.cache.eviction.FIFOConfiguration;
+import org.jboss.cache.eviction.FIFOPolicy;
+import org.jboss.cache.eviction.LRUConfiguration;
+import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.eviction.MRUConfiguration;
+import org.jboss.cache.eviction.MRUPolicy;
+import org.jboss.cache.loader.FileCacheLoader;
+import org.jboss.cache.loader.SingletonStoreCacheLoader;
+import org.jboss.cache.loader.jdbm.JdbmCacheLoader;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.multiplexer.MultiplexerTestHelper;
+import org.jboss.cache.transaction.BatchModeTransactionManagerLookup;
+import org.jgroups.ChannelFactory;
+import org.jgroups.JChannelFactory;
+import org.jgroups.jmx.JChannelFactoryMBean;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.Test;
+import org.w3c.dom.Element;
+
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+import javax.transaction.TransactionManager;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Test of the CacheLegacyJmxWrapper.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+ at Test(groups = "functional")
+public class LegacyConfigurationTest extends CacheJmxWrapperTestBase
+{
+ @SuppressWarnings({"deprecation", "unchecked"})
+ public void testLocalCache() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper();
+ registerWrapper(wrapper);
+
+ wrapper = (CacheJmxWrapperMBean<String, String>) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
+
+ wrapper.setBuddyReplicationConfig(getBuddyReplicationConfig());
+ wrapper.setCacheLoaderConfig(getCacheLoaderConfig());
+ wrapper.setCacheMode("REPL_SYNC");
+ wrapper.setClusterName("LocalTest");
+ wrapper.setClusterConfig(getClusterConfig());
+ wrapper.setEvictionPolicyConfig(getEvictionPolicyConfig());
+ wrapper.setFetchInMemoryState(false);
+ wrapper.setInitialStateRetrievalTimeout(100);
+ wrapper.setInactiveOnStartup(true);
+ wrapper.setNodeLockingScheme("OPTIMISTIC");
+ wrapper.setIsolationLevel("READ_UNCOMMITTED");
+ wrapper.setLockAcquisitionTimeout(200);
+ wrapper.setReplicationVersion("1.0.1");
+ wrapper.setReplQueueInterval(15);
+ wrapper.setReplQueueMaxElements(50);
+ wrapper.setSyncReplTimeout(300);
+ wrapper.setSyncCommitPhase(true);
+ wrapper.setSyncRollbackPhase(true);
+ wrapper.setTransactionManagerLookupClass(BatchModeTransactionManagerLookup.class.getName());
+ wrapper.setExposeManagementStatistics(false);
+ wrapper.setUseRegionBasedMarshalling(true);
+ wrapper.setUseReplQueue(true);
+
+ Configuration c = wrapper.getConfiguration();
+
+ assertEquals("CacheMode", "REPL_SYNC", wrapper.getCacheMode());
+ assertEquals("CacheMode", CacheMode.REPL_SYNC, c.getCacheMode());
+ assertEquals("ClusterName", "LocalTest", wrapper.getClusterName());
+ assertEquals("ClusterName", "LocalTest", c.getClusterName());
+ assertEquals("FetchInMemoryState", false, wrapper.getFetchInMemoryState());
+ assertEquals("FetchInMemoryState", false, c.isFetchInMemoryState());
+ assertEquals("InitialStateRetrievalTimeout", 100, wrapper.getInitialStateRetrievalTimeout());
+ assertEquals("InitialStateRetrievalTimeout", 100, c.getStateRetrievalTimeout());
+ assertEquals("InactiveOnStartup", true, wrapper.isInactiveOnStartup());
+ assertEquals("InactiveOnStartup", true, c.isInactiveOnStartup());
+ assertEquals("NodeLockingScheme", "OPTIMISTIC", wrapper.getNodeLockingScheme());
+ assertEquals("NodeLockingScheme", NodeLockingScheme.OPTIMISTIC, c.getNodeLockingScheme());
+ assertEquals("IsolationLevel", "READ_UNCOMMITTED", wrapper.getIsolationLevel());
+ assertEquals("IsolationLevel", IsolationLevel.READ_UNCOMMITTED, c.getIsolationLevel());
+ assertEquals("LockAcquisitionTimeout", 200, wrapper.getLockAcquisitionTimeout());
+ assertEquals("LockAcquisitionTimeout", 200, c.getLockAcquisitionTimeout());
+ assertEquals("ReplicationVersion", "1.0.1", wrapper.getReplicationVersion());
+ assertEquals("ReplicationVersion", Version.getVersionShort("1.0.1"), c.getReplicationVersion());
+ assertEquals("ReplQueueInterval", 15, wrapper.getReplQueueInterval());
+ assertEquals("ReplQueueInterval", 15, c.getReplQueueInterval());
+ assertEquals("ReplQueueMaxElements", 50, wrapper.getReplQueueMaxElements());
+ assertEquals("ReplQueueMaxElements", 50, c.getReplQueueMaxElements());
+ assertEquals("SyncReplTimeout", 300, wrapper.getSyncReplTimeout());
+ assertEquals("SyncReplTimeout", 300, c.getSyncReplTimeout());
+ assertEquals("SyncCommitPhase", true, wrapper.getSyncCommitPhase());
+ assertEquals("SyncCommitPhase", true, c.isSyncCommitPhase());
+ assertEquals("SyncRollbackPhase", true, wrapper.getSyncRollbackPhase());
+ assertEquals("SyncRollbackPhase", true, c.isSyncRollbackPhase());
+ assertEquals("TransactionManagerLookupClass", BatchModeTransactionManagerLookup.class.getName(), wrapper.getTransactionManagerLookupClass());
+ assertEquals("TransactionManagerLookupClass", BatchModeTransactionManagerLookup.class.getName(), c.getTransactionManagerLookupClass());
+ assertEquals("ExposeManagementStatistics", false, wrapper.getExposeManagementStatistics());
+ assertEquals("ExposeManagementStatistics", false, c.getExposeManagementStatistics());
+ assertEquals("UseRegionBasedMarshalling", true, wrapper.getUseRegionBasedMarshalling());
+ assertEquals("UseRegionBasedMarshalling", true, c.isUseRegionBasedMarshalling());
+ assertEquals("UseReplQueue", true, wrapper.getUseReplQueue());
+ assertEquals("UseReplQueue", true, c.isUseReplQueue());
+
+ assertEquals("ClusterConfig", getClusterConfig().toString(), wrapper.getClusterConfig().toString());
+
+ assertEquals("BuddyReplicationConfig", getBuddyReplicationConfig().toString(), wrapper.getBuddyReplicationConfig().toString());
+ BuddyReplicationConfig brc = c.getBuddyReplicationConfig();
+ assertEquals("BR enabled", true, brc.isEnabled());
+ assertEquals("BR auto grav", false, brc.isAutoDataGravitation());
+ assertEquals("BR remove find", false, brc.isDataGravitationRemoveOnFind());
+ assertEquals("BR search backup", false, brc.isDataGravitationSearchBackupTrees());
+ assertEquals("BR comm timeout", 600000, brc.getBuddyCommunicationTimeout());
+ assertEquals("BR poolname", "testpool", brc.getBuddyPoolName());
+ BuddyLocatorConfig blc = brc.getBuddyLocatorConfig();
+ assertEquals("BR locator", "org.jboss.cache.buddyreplication.TestBuddyLocator", blc.getBuddyLocatorClass());
+ Properties props = blc.getBuddyLocatorProperties();
+ assertEquals("BR props", "2", props.get("numBuddies"));
+
+ assertEquals("CacheLoaderConfig", getCacheLoaderConfig().toString(), wrapper.getCacheLoaderConfig().toString());
+ CacheLoaderConfig clc = c.getCacheLoaderConfig();
+ assertEquals("CL passivation", false, clc.isPassivation());
+ assertEquals("CL passivation", true, clc.isShared());
+ assertEquals("CL preload", "/foo", clc.getPreload());
+ List<IndividualCacheLoaderConfig> iclcs = clc.getIndividualCacheLoaderConfigs();
+ IndividualCacheLoaderConfig iclc = iclcs.get(0);
+ assertEquals("CL0 class", FileCacheLoader.class.getName(), iclc.getClassName());
+ assertEquals("CL0 async", false, iclc.isAsync());
+ assertEquals("CL0 fetch", true, iclc.isFetchPersistentState());
+ assertEquals("CL0 ignore", true, iclc.isIgnoreModifications());
+ assertEquals("CL0 purge", true, iclc.isPurgeOnStartup());
+ assertEquals("CL0 singleton", true, iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
+ assertEquals("CL0 singleton class", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
+ iclc = iclcs.get(1);
+ assertEquals("CL1 class", JdbmCacheLoader.class.getName(), iclc.getClassName());
+ assertEquals("CL1 async", true, iclc.isAsync());
+ assertEquals("CL1 fetch", false, iclc.isFetchPersistentState());
+ assertEquals("CL1 ignore", false, iclc.isIgnoreModifications());
+ assertEquals("CL1 purge", false, iclc.isPurgeOnStartup());
+ assertEquals("CL1 singleton", false, iclc.getSingletonStoreConfig().isSingletonStoreEnabled());
+ assertEquals("CL1 singleton class", SingletonStoreCacheLoader.class.getName(), iclc.getSingletonStoreConfig().getSingletonStoreClass());
+
+ assertEquals("EvictionPolicyConfig", getEvictionPolicyConfig().toString(), wrapper.getEvictionPolicyConfig().toString());
+ EvictionConfig ec = c.getEvictionConfig();
+ assertEquals("EC queue size", 20000, ec.getDefaultEventQueueSize());
+ assertEquals("EC wakeup", 5000, ec.getWakeupInterval());
+ assertEquals("EC default pol", LRUPolicy.class.getName(), ec.getDefaultEvictionPolicyClass());
+ List<EvictionRegionConfig> ercs = ec.getEvictionRegionConfigs();
+ EvictionRegionConfig erc = ercs.get(0);
+ assertEquals("ERC0 name", "/_default_", erc.getRegionName());
+ assertEquals("ERC0 queue size", 1000, erc.getEventQueueSize());
+ LRUConfiguration lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
+ assertEquals("EPC0 pol", LRUPolicy.class.getName(), lru.getEvictionPolicyClass());
+ assertEquals("EPC0 maxnodes", 5000, lru.getMaxNodes());
+ assertEquals("EPC0 ttl", 1000000, lru.getTimeToLive());
+ erc = ercs.get(1);
+ assertEquals("ERC1 name", "/org/jboss/data", erc.getRegionName());
+ assertEquals("ERC1 queue size", 20000, erc.getEventQueueSize());
+ FIFOConfiguration fifo = (FIFOConfiguration) erc.getEvictionPolicyConfig();
+ assertEquals("EPC1 pol", FIFOPolicy.class.getName(), fifo.getEvictionPolicyClass());
+ assertEquals("EPC1 maxnodes", 5000, fifo.getMaxNodes());
+ erc = ercs.get(2);
+ assertEquals("ERC2 name", "/test", erc.getRegionName());
+ assertEquals("ERC2 queue size", 20000, erc.getEventQueueSize());
+ MRUConfiguration mru = (MRUConfiguration) erc.getEvictionPolicyConfig();
+ assertEquals("EPC2 pol", MRUPolicy.class.getName(), mru.getEvictionPolicyClass());
+ assertEquals("EPC2 maxnodes", 10000, mru.getMaxNodes());
+ erc = ercs.get(3);
+ assertEquals("ERC3 name", "/maxAgeTest", erc.getRegionName());
+ assertEquals("ERC3 queue size", 20000, erc.getEventQueueSize());
+ lru = (LRUConfiguration) erc.getEvictionPolicyConfig();
+ assertEquals("EPC3 pol", LRUPolicy.class.getName(), lru.getEvictionPolicyClass());
+ assertEquals("EPC3 maxnodes", 10000, lru.getMaxNodes());
+ assertEquals("EPC3 maxage", 10000, lru.getMaxAge());
+ assertEquals("EPC3 ttl", 8000, lru.getTimeToLive());
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testRuntimeConfig() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper<String, String>();
+ registerWrapper(wrapper);
+
+ wrapper = (CacheJmxWrapperMBean<String, String>) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
+
+ // Fake a TM by making a bogus proxy
+ TransactionManager tm = (TransactionManager) Proxy.newProxyInstance(getClass().getClassLoader(),
+ new Class[]{TransactionManager.class}, new MockInvocationHandler());
+ wrapper.setTransactionManager(tm);
+ ChannelFactory cf = new JChannelFactory();
+ wrapper.setMuxChannelFactory(cf);
+
+ RuntimeConfig rc = wrapper.getConfiguration().getRuntimeConfig();
+
+ assertSame("Same TM", tm, wrapper.getTransactionManager());
+ assertSame("Same TM", tm, rc.getTransactionManager());
+ assertSame("Same ChannelFactory", cf, wrapper.getMuxChannelFactory());
+ assertSame("Same ChannelFactory", cf, rc.getMuxChannelFactory());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testLegacyMuxChannelCreation() throws Exception
+ {
+ CacheJmxWrapperMBean<String, String> wrapper = new CacheJmxWrapper<String, String>();
+ registerWrapper(wrapper);
+
+ wrapper = (CacheJmxWrapperMBean<String, String>) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, CacheJmxWrapperMBean.class, false);
+ wrapper.setMultiplexerStack(MultiplexerTestHelper.MUX_STACK);
+
+ JChannelFactory factory = new JChannelFactory();
+ factory.setDomain("jbc.mux.test");
+ factory.setExposeChannels(false);
+ factory.setMultiplexerConfig(MultiplexerTestHelper.getClusterConfigElement(getDefaultProperties()));
+
+ ObjectName on = new ObjectName("jgroups:service=Mux");
+ mBeanServer.registerMBean(new org.jgroups.jmx.JChannelFactory(factory), on);
+
+ wrapper.setMultiplexerService((JChannelFactoryMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, on, JChannelFactoryMBean.class, false));
+
+ wrapper.start();
+
+ RuntimeConfig rc = wrapper.getConfiguration().getRuntimeConfig();
+ assertNotNull("Channel created", rc.getChannel());
+ }
+
+ protected static Element getBuddyReplicationConfig() throws Exception
+ {
+
+ String xmlStr =
+ " <buddy enabled=\"true\" poolName=\"testpool\" communicationTimeout=\"600000\">\n" +
+ " <dataGravitation auto=\"false\" removeOnFind=\"false\" searchBackupTrees=\"false\"/>\n" +
+ " <locator class=\"org.jboss.cache.buddyreplication.TestBuddyLocator\">\n" +
+ " <properties>\n" +
+ " numBuddies = 2\n" +
+ " </properties>\n" +
+ " </locator>\n" +
+ " </buddy>";
+ return XmlConfigHelper.stringToElement(xmlStr);
+ }
+
+ protected static Element getCacheLoaderConfig() throws Exception
+ {
+ String xmlStr =
+ " <loaders passivation=\"false\" shared=\"true\">\n" +
+ " <preload>\n" +
+ " <node fqn=\"/foo\"/>\n" +
+ " </preload>\n" +
+ " <loader class=\"org.jboss.cache.loader.FileCacheLoader\" async=\"false\" fetchPersistentState=\"true\"\n" +
+ " ignoreModifications=\"true\" purgeOnStartup=\"true\">\n" +
+ " <properties>\n" +
+ " location=/tmp\n " +
+ " </properties>\n" +
+ " <singletonStore enabled=\"true\" /> \n" +
+ " </loader>\n" +
+ " <loader class=\"org.jboss.cache.loader.jdbm.JdbmCacheLoader\" async=\"true\" fetchPersistentState=\"false\"\n" +
+ " ignoreModifications=\"false\" purgeOnStartup=\"false\">\n" +
+ " <properties>\n" +
+ " location=/home/bstansberry\n" +
+ " </properties>\n" +
+ " <singletonStore enabled=\"false\" /> \n" +
+ " </loader>\n" +
+ " </loaders>";
+ return XmlConfigHelper.stringToElement(xmlStr);
+ }
+
+ protected static Element getEvictionPolicyConfig() throws Exception
+ {
+
+ String xmlStr =
+ " <eviction wakeUpInterval=\"5000\" defaultPolicyClass=\"org.jboss.cache.eviction.LRUPolicy\" defaultEventQueueSize=\"20000\">\n" +
+ " <default eventQueueSize=\"1000\">\n" +
+ " <attribute name=\"maxNodes\">5000</attribute>\n" +
+ " <attribute name=\"timeToLive\">1000000</attribute>\n" +
+ " </default>\n" +
+ "<region name=\"/org/jboss/data\" policyClass=\"org.jboss.cache.eviction.FIFOPolicy\">\n" +
+ " <attribute name=\"maxNodes\">5000</attribute>\n" +
+ "</region>\n" +
+ "<region name=\"/test/\" policyClass=\"org.jboss.cache.eviction.MRUPolicy\">\n" +
+ " <attribute name=\"maxNodes\">10000</attribute>\n" +
+ "</region>\n" +
+ "<region name=\"/maxAgeTest/\">\n" +
+ " <attribute name=\"maxNodes\">10000</attribute>\n" +
+ " <attribute name=\"timeToLiveSeconds\">8</attribute>\n" +
+ " <attribute name=\"maxAgeSeconds\">10</attribute>\n" +
+ "</region>\n" +
+ " </eviction>";
+ return XmlConfigHelper.stringToElement(xmlStr);
+ }
+
+ protected static Element getClusterConfig() throws Exception
+ {
+ String xml =
+ "<jgroupsConfig>\n" +
+ "<UDP mcast_addr=\"228.10.10.10\"\n" +
+ " mcast_port=\"45588\"\n" +
+ " tos=\"8\"\n" +
+ " ucast_recv_buf_size=\"20000000\"\n" +
+ " ucast_send_buf_size=\"640000\"\n" +
+ " mcast_recv_buf_size=\"25000000\"\n" +
+ " mcast_send_buf_size=\"640000\"\n" +
+ " loopback=\"false\"\n" +
+ " discard_incompatible_packets=\"true\"\n" +
+ " max_bundle_size=\"64000\"\n" +
+ " max_bundle_timeout=\"30\"\n" +
+ " use_incoming_packet_handler=\"true\"\n" +
+ " ip_ttl=\"2\"\n" +
+ " enable_bundling=\"false\"\n" +
+ " enable_diagnostics=\"true\"\n" +
+ " use_concurrent_stack=\"true\"\n" +
+ " thread_naming_pattern=\"pl\"\n" +
+ " thread_pool.enabled=\"true\"\n" +
+ " thread_pool.min_threads=\"1\"\n" +
+ " thread_pool.max_threads=\"25\"\n" +
+ " thread_pool.keep_alive_time=\"30000\"\n" +
+ " thread_pool.queue_enabled=\"true\"\n" +
+ " thread_pool.queue_max_size=\"10\"\n" +
+ " thread_pool.rejection_policy=\"Run\"\n" +
+ " oob_thread_pool.enabled=\"true\"\n" +
+ " oob_thread_pool.min_threads=\"1\"\n" +
+ " oob_thread_pool.max_threads=\"4\"\n" +
+ " oob_thread_pool.keep_alive_time=\"10000\"\n" +
+ " oob_thread_pool.queue_enabled=\"true\"\n" +
+ " oob_thread_pool.queue_max_size=\"10\"\n" +
+ " oob_thread_pool.rejection_policy=\"Run\"/>\n" +
+ " <PING timeout=\"2000\" num_initial_members=\"3\"/>\n" +
+ " <MERGE2 max_interval=\"30000\" min_interval=\"10000\"/>\n" +
+ " <FD_SOCK/>\n" +
+ " <FD timeout=\"10000\" max_tries=\"5\" shun=\"true\"/>\n" +
+ " <VERIFY_SUSPECT timeout=\"1500\"/>\n" +
+ " <pbcast.NAKACK max_xmit_size=\"60000\"\n" +
+ " use_mcast_xmit=\"false\" gc_lag=\"0\"\n" +
+ " retransmit_timeout=\"300,600,1200,2400,4800\"\n" +
+ " discard_delivered_msgs=\"true\"/>\n" +
+ " <UNICAST timeout=\"300,600,1200,2400,3600\"/>\n" +
+ " <pbcast.STABLE stability_delay=\"1000\" desired_avg_gossip=\"50000\"\n" +
+ " max_bytes=\"400000\"/>\n" +
+ " <pbcast.GMS print_local_addr=\"true\" join_timeout=\"5000\"\n" +
+ " join_retry_timeout=\"2000\" shun=\"false\"\n" +
+ " view_bundling=\"true\" view_ack_collection_timeout=\"5000\"/>\n" +
+ " <FRAG2 frag_size=\"60000\"/>\n" +
+ " <pbcast.STREAMING_STATE_TRANSFER use_reading_thread=\"true\"/>\n" +
+ " <pbcast.FLUSH timeout=\"0\"/>\n" +
+ "</jgroupsConfig>";
+ return XmlConfigHelper.stringToElement(xml);
+ }
+
+ protected String getDefaultProperties()
+ {
+ return "UDP(mcast_addr=224.0.0.36;mcast_port=55566;ip_ttl=32;" +
+ "mcast_send_buf_size=150000;mcast_recv_buf_size=80000):" +
+ "PING(timeout=1000;num_initial_members=2):" +
+ "MERGE2(min_interval=5000;max_interval=10000):" +
+ "FD_SOCK:" +
+ "VERIFY_SUSPECT(timeout=1500):" +
+ "pbcast.NAKACK(gc_lag=50;max_xmit_size=8192;retransmit_timeout=600,1200,2400,4800):" +
+ "UNICAST(timeout=600,1200,2400,4800):" +
+ "pbcast.STABLE(desired_avg_gossip=20000):" +
+ "FRAG(frag_size=8192;down_thread=false;up_thread=false):" +
+ "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;" +
+ "shun=false;print_local_addr=true):" +
+ "pbcast.STATE_TRANSFER";
+ }
+
+ class MockInvocationHandler implements InvocationHandler
+ {
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ return null;
+ }
+
+ }
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LegacyConfigurationTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LifecycleNotificationTest.java (from rev 6541, core/trunk/src/test/java/org/jboss/cache/jmx/LifecycleNotificationTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LifecycleNotificationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LifecycleNotificationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.cache.jmx.deprecated;
+
+import static org.testng.AssertJUnit.assertEquals;
+import org.testng.AssertJUnit;
+import org.jboss.cache.jmx.CacheJmxWrapper;
+import org.jboss.cache.jmx.CacheJmxWrapperMBean;
+
+import javax.management.AttributeChangeNotification;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * A LifecycleNotificationTest.
+ *
+ * @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
+ * @version $Revision$
+ */
+public class LifecycleNotificationTest extends CacheJmxWrapperTestBase
+{
+ public void testGetStateAndStateNotification() throws Exception
+ {
+ CacheJmxWrapper<String, String> wrapper = createWrapper(createConfiguration());
+ StateNotificationListener listener = new StateNotificationListener();
+ wrapper.addNotificationListener(listener, null, null);
+
+ AssertJUnit.assertEquals("Correct state after instanitation",
+ CacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
+
+ registerWrapper(wrapper);
+ assertEquals("Correct state after registration",
+ CacheJmxWrapperMBean.REGISTERED, wrapper.getState());
+
+ wrapper.create();
+ assertEquals("Correct state after create",
+ CacheJmxWrapperMBean.CREATED, wrapper.getState());
+
+ wrapper.start();
+ assertEquals("Correct state after start",
+ CacheJmxWrapperMBean.STARTED, wrapper.getState());
+
+ wrapper.stop();
+ assertEquals("Correct state after stop",
+ CacheJmxWrapperMBean.STOPPED, wrapper.getState());
+
+ wrapper.destroy();
+ assertEquals("Correct state after destroy",
+ CacheJmxWrapperMBean.DESTROYED, wrapper.getState());
+
+ unregisterWrapper();
+ assertEquals("Correct state after unregistration",
+ CacheJmxWrapperMBean.UNREGISTERED, wrapper.getState());
+
+ System.out.println(listener.notifications);
+ assertEquals("Correct number of notifications received", 4, listener.notifications.size());
+ assertEquals("Correct first notification", new Integer(CacheJmxWrapperMBean.STARTING), listener.notifications.get(0));
+ assertEquals("Correct second notification", new Integer(CacheJmxWrapperMBean.STARTED), listener.notifications.get(1));
+ assertEquals("Correct third notification", new Integer(CacheJmxWrapperMBean.STOPPING), listener.notifications.get(2));
+ assertEquals("Correct fourth notification", new Integer(CacheJmxWrapperMBean.STOPPED), listener.notifications.get(3));
+ }
+
+ private static class StateNotificationListener
+ implements NotificationListener
+ {
+ private List<Integer> notifications = new LinkedList<Integer>();
+
+ public void handleNotification(Notification msg, Object handback)
+ {
+ if (msg instanceof AttributeChangeNotification)
+ {
+ AttributeChangeNotification change = (AttributeChangeNotification) msg;
+ String attrName = change.getAttributeName();
+ Object newValue = change.getNewValue();
+ if ("State".equals(attrName) && newValue != null && newValue instanceof Integer)
+ {
+ notifications.add((Integer) newValue);
+ }
+ }
+ }
+ }
+
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/LifecycleNotificationTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/NotificationTest.java (from rev 6541, core/trunk/src/test/java/org/jboss/cache/jmx/NotificationTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/NotificationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/NotificationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -0,0 +1,470 @@
+package org.jboss.cache.jmx.deprecated;
+
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.jmx.CacheJmxWrapper;
+import org.jboss.cache.jmx.JmxRegistrationManager;
+import org.jboss.cache.jmx.CacheNotificationBroadcaster;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.loader.CacheLoader;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import java.util.EnumSet;
+import java.util.HashMap;
+
+/**
+ * Functional tests for CacheJmxWrapper broadcast of cache event notifications
+ *
+ * @author Jerry Gauthier
+ * @version $Id$
+ */
+ at Test(groups = {"functional"})
+public class NotificationTest
+{
+ protected static final String CLUSTER_NAME = "NotificationTestCluster";
+
+ protected static final String CAPITAL = "capital";
+ protected static final String CURRENCY = "currency";
+ protected static final String POPULATION = "population";
+ protected static final String EUROPE_NODE = "Europe";
+
+ public enum Type
+ {
+ STARTED, STOPPED, PRECREATE, POSTCREATE, PREEVICT, POSTEVICT,
+ PRELOAD, POSTLOAD, PREREMOVE, POSTREMOVE, PREVISIT, POSTVISIT,
+ PREMODIFY, POSTMODIFY, PREACTIVATE, POSTACTIVATE, PREPASSIVATE,
+ POSTPASSIVATE, VIEWCHANGE
+ }
+
+ protected MBeanServer m_server;
+ protected EnumSet<Type> events = EnumSet.noneOf(Type.class);
+
+ protected CacheSPI<Object, Object> cache = null;
+ protected boolean optimistic = false;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() throws Exception
+ {
+ m_server = MBeanServerFactory.createMBeanServer();
+
+ Object cacheMBean = createCacheAndJmxWrapper();
+
+ // bind manually for now.
+ ObjectName mgmt = getWrapperObjectName();
+
+ m_server.registerMBean(cacheMBean, mgmt);
+ }
+
+ protected Object createCacheAndJmxWrapper() throws Exception
+ {
+ cache = createCache(CLUSTER_NAME);
+ return new CacheJmxWrapper<Object, Object>(cache);
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ cleanup();
+ }
+ finally
+ {
+ // make sure we stop the mbean server
+ if (m_server != null)
+ MBeanServerFactory.releaseMBeanServer(m_server);
+ }
+ }
+
+ protected void cleanup() throws Exception
+ {
+ events.clear();
+
+ destroyCache();
+
+ if (m_server != null)
+ {
+ ObjectName mgmt = getWrapperObjectName();
+ if (m_server.isRegistered(mgmt))
+ m_server.unregisterMBean(mgmt);
+ }
+ }
+
+ protected void destroyCache()
+ {
+ if (cache != null)
+ {
+ // stop the cache before the listener is unregistered
+ //cache1.stop();
+ cache.destroy();
+ cache = null;
+ }
+ }
+
+ protected ObjectName getWrapperObjectName() throws Exception
+ {
+ return new ObjectName(JmxRegistrationManager.CLUSTERED_CACHE_PREFIX + CLUSTER_NAME);
+ }
+
+ public void testNotifications() throws Exception
+ {
+ assertNotNull("MBeanServer is null.", m_server);
+ assertNotNull("Cache is null.", cache);
+
+ ObjectName mgmt = getWrapperObjectName();
+ MyListener listener = new MyListener(mgmt);
+
+
+ m_server.addNotificationListener(mgmt, listener, null, null);
+
+ // start the cache after registering listener - this will trigger CacheStarted
+ // since cache is defined with cluster, thiswill also trigger ViewChange
+ cache.start();
+
+ // add a node - this will trigger NodeCreated, NodeModify(pre/post) and NodeModified
+ HashMap<Object, Object> albania = new HashMap<Object, Object>(4);
+ albania.put(CAPITAL, "Tirana");
+ albania.put(CURRENCY, "Lek");
+ cache.put("Europe/Albania", albania);
+
+ // modify a node - this will trigger NodeModified and NodeModify(pre/post)
+ cache.put("Europe/Albania", POPULATION, 3563112);
+
+ // retrieve an attribute - this will trigger NodeVisited
+ Fqn key = Fqn.fromString("Europe/Albania");
+ assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + key, cache.get(key, CURRENCY));
+
+ // evict the node - this will trigger NodePassivate, NodeEvicted and NodeEvict(pre/post)
+ cache.evict(key);
+
+ // retrieve the attribute again - this will trigger NodeVisited and NodeActivate
+ assertNotNull("Retrieval error: expected to retrieve " + CURRENCY + " for " + key, cache.get(key, CURRENCY));
+
+ // remove the node - this will trigger NodeRemoved and NodeRemove(pre/post)
+ cache.removeNode(key);
+
+ // clean up before stopping the cache
+ CacheLoader cl = cache.getCacheLoaderManager().getCacheLoader();
+ cl.remove(Fqn.fromString(EUROPE_NODE));
+
+ // stop the cache
+ cache.stop();
+ m_server.removeNotificationListener(mgmt, listener);
+
+ // run the tests
+ assertTrue("Expected CacheStarted notification", events.contains(Type.STARTED));
+ assertTrue("Expected CacheStopped notification", events.contains(Type.STOPPED));
+ assertTrue("Expected NodeCreated notification", events.contains(Type.PRECREATE));
+ assertTrue("Expected NodeCreated notification", events.contains(Type.POSTCREATE));
+ assertTrue("Expected NodeEvicted notification", events.contains(Type.PREEVICT));
+ assertTrue("Expected NodeEvicted notification", events.contains(Type.POSTEVICT));
+ assertTrue("Expected NodeLoaded notification", events.contains(Type.PRELOAD));
+ assertTrue("Expected NodeLoaded notification", events.contains(Type.POSTLOAD));
+ assertTrue("Expected NodeVisited notification", events.contains(Type.PREVISIT));
+ assertTrue("Expected NodeVisited notification", events.contains(Type.POSTVISIT));
+ assertTrue("Expected NodeActivated notification", events.contains(Type.PREACTIVATE));
+ assertTrue("Expected NodeActivated notification", events.contains(Type.POSTACTIVATE));
+ assertTrue("Expected NodeModified notification", events.contains(Type.PREMODIFY));
+ assertTrue("Expected NodeModified notification", events.contains(Type.POSTMODIFY));
+ assertTrue("Expected NodePassivated notification", events.contains(Type.PREPASSIVATE));
+ assertTrue("Expected NodePassivated notification", events.contains(Type.POSTPASSIVATE));
+ assertTrue("Expected NodeRemoved notification", events.contains(Type.PREREMOVE));
+ assertTrue("Expected NodeRemoved notification", events.contains(Type.POSTREMOVE));
+ assertTrue("Expected ViewChange notification", events.contains(Type.VIEWCHANGE));
+ validateHealthyListener(listener);
+ }
+
+ public void testEarlyRegistration() throws Exception
+ {
+ // undo setup
+ cleanup();
+
+ CacheJmxWrapper<Object, Object> wrapper = new CacheJmxWrapper<Object, Object>();
+ ObjectName mgmt = getWrapperObjectName();
+ m_server.registerMBean(wrapper, mgmt);
+ MyListener listener = new MyListener(mgmt);
+ m_server.addNotificationListener(mgmt, listener, null, null);
+
+ cache = createCache(CLUSTER_NAME);
+ wrapper.setCache(cache);
+ cache.start();
+ try
+ {
+ assertTrue("Expected CacheStarted notification", events.contains(Type.STARTED));
+ validateHealthyListener(listener);
+ }
+ finally
+ {
+ cache.stop();
+ }
+ }
+
+ public void testLateRegistration() throws Exception
+ {
+ assertNotNull("MBeanServer is null.", m_server);
+ assertNotNull("Cache is null.", cache);
+
+ // start the cache before registering listener
+ cache.start();
+
+ try
+ {
+ ObjectName mgmt = getWrapperObjectName();
+ MyListener listener = new MyListener(mgmt);
+
+ m_server.addNotificationListener(mgmt, listener, null, null);
+
+ // add a node - this will trigger NodeCreated, NodeModify(pre/post) and NodeModified
+ HashMap<Object, Object> albania = new HashMap<Object, Object>(4);
+ albania.put(CAPITAL, "Tirana");
+ albania.put(CURRENCY, "Lek");
+ cache.put("Europe/Albania", albania);
+
+ // run the tests
+ assertTrue("Expected NodeModified notification", events.contains(Type.PREMODIFY));
+ assertTrue("Expected NodeModified notification", events.contains(Type.POSTMODIFY));
+ validateHealthyListener(listener);
+ }
+ finally
+ {
+ cache.stop();
+ }
+ }
+
+ public void testListenerRemoval() throws Exception
+ {
+ assertNotNull("MBeanServer is null.", m_server);
+ assertNotNull("Cache is null.", cache);
+
+ ObjectName mgmt = getWrapperObjectName();
+ MyListener listener = new MyListener(mgmt);
+
+ m_server.addNotificationListener(mgmt, listener, null, null);
+
+ // start the cache after registering listener - this will trigger CacheStarted
+ // since cache is defined with cluster, thiswill also trigger ViewChange
+ cache.start();
+ boolean ok = false;
+ try
+ {
+ assertTrue("Expected CacheStarted notification", events.contains(Type.STARTED));
+
+ m_server.removeNotificationListener(mgmt, listener);
+ ok = true;
+ }
+ finally
+ {
+ cache.stop();
+ if (ok)
+ {
+ assertFalse("Expected no CacheStopped notification", events.contains(Type.STOPPED));
+ validateHealthyListener(listener);
+ }
+ }
+ }
+
+ private CacheSPI<Object, Object> createCache(String clusterName) throws Exception
+ {
+ Configuration config = createConfiguration(clusterName);
+ CacheFactory<Object, Object> factory = new DefaultCacheFactory<Object, Object>();
+ CacheSPI<Object, Object> cache = (CacheSPI<Object, Object>) factory.createCache(config, false);
+
+ cache.create();
+ // start the cache after the listener has been registered
+ //cache.start();
+ return cache;
+ }
+
+ protected Configuration createConfiguration(String clusterName) throws Exception
+ {
+ Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.REPL_SYNC);
+ config.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+ config.setCacheLoaderConfig(getCacheLoaderConfig("location=" + getTempDir()));
+ config.setExposeManagementStatistics(true);
+ config.setClusterName(clusterName);
+ if (optimistic)
+ {
+ config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
+ config.setNodeLockingScheme("OPTIMISTIC");
+ }
+
+ return config;
+ }
+
+ private static String getTempDir()
+ {
+ return System.getProperty("java.io.tempdir", "/tmp");
+ }
+
+ private static boolean getPre(Object data)
+ {
+ assertNotNull("User data is null, should be Object[]", data);
+ assertTrue("User data is " + data.getClass().getName() + ", should be Object[]", data instanceof Object[]);
+
+ Object[] parms = (Object[]) data;
+ assertTrue("Parameter is " + parms[1].getClass().getName() + ", should be Boolean", parms[1] instanceof Boolean);
+ return (Boolean) parms[1];
+ }
+
+ protected static CacheLoaderConfig getCacheLoaderConfig(String properties) throws Exception
+ {
+ return UnitTestCacheConfigurationFactory.buildSingleCacheLoaderConfig(true, "",
+ "org.jboss.cache.loader.FileCacheLoader", properties, false, false, true, false, false);
+ }
+
+ private static void validateHealthyListener(MyListener listener)
+ {
+ if (listener.failure != null)
+ throw listener.failure;
+ if (listener.exception != null)
+ throw listener.exception;
+ }
+
+ private class MyListener implements NotificationListener
+ {
+ private RuntimeException exception;
+ private AssertionError failure;
+ private final String emitterObjectName;
+
+ MyListener(ObjectName emitter)
+ {
+ this.emitterObjectName = emitter.getCanonicalName();
+ }
+
+ public void handleNotification(Notification notification, Object handback)
+ {
+ try
+ {
+ String type = notification.getType();
+ Object userData = notification.getUserData();
+
+ if (type.equals(CacheNotificationBroadcaster.NOTIF_CACHE_STARTED))
+ {
+ events.add(Type.STARTED);
+ assertEquals("Correct object name in start notification", emitterObjectName, userData);
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_CACHE_STOPPED))
+ {
+ events.add(Type.STOPPED);
+ assertEquals("Correct object name in stop notification", emitterObjectName, userData);
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_CREATED))
+ {
+ if (getPre(userData))
+ {
+ events.add(Type.PRECREATE);
+ }
+ else
+ {
+ events.add(Type.POSTCREATE);
+ }
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_EVICTED))
+ {
+ if (getPre(userData))
+ {
+ events.add(Type.PREEVICT);
+ }
+ else
+ {
+ events.add(Type.POSTEVICT);
+ }
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_LOADED))
+ {
+ if (getPre(userData))
+ {
+ events.add(Type.PRELOAD);
+ }
+ else
+ {
+ events.add(Type.POSTLOAD);
+ }
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_REMOVED))
+ {
+ if (getPre(userData))
+ {
+ events.add(Type.PREREMOVE);
+ }
+ else
+ {
+ events.add(Type.POSTREMOVE);
+ }
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_VISITED))
+ {
+ if (getPre(userData))
+ {
+ events.add(Type.PREVISIT);
+ }
+ else
+ {
+ events.add(Type.POSTVISIT);
+ }
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_VIEW_CHANGED))
+ {
+ events.add(Type.VIEWCHANGE);
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_ACTIVATED))
+ {
+ if (getPre(userData))
+ {
+ events.add(Type.PREACTIVATE);
+ }
+ else
+ {
+ events.add(Type.POSTACTIVATE);
+ }
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_MODIFIED))
+ {
+ if (getPre(userData))
+ {
+ events.add(Type.PREMODIFY);
+ }
+ else
+ {
+ events.add(Type.POSTMODIFY);
+ }
+ }
+ else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_PASSIVATED))
+ {
+ if (getPre(userData))
+ {
+ events.add(Type.PREPASSIVATE);
+ }
+ else
+ {
+ events.add(Type.POSTPASSIVATE);
+ }
+ }
+ }
+ catch (RuntimeException e)
+ {
+ // Store so the test can rethrow
+ exception = e;
+ }
+ catch (AssertionError e)
+ {
+ // Store so the test can rethrow
+ failure = e;
+ }
+ }
+ }
+
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/NotificationTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Copied: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/OptimisticNotificationTest.java (from rev 6541, core/trunk/src/test/java/org/jboss/cache/jmx/OptimisticNotificationTest.java)
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/OptimisticNotificationTest.java (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/OptimisticNotificationTest.java 2008-08-08 17:00:29 UTC (rev 6546)
@@ -0,0 +1,19 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.cache.jmx.deprecated;
+
+
+/**
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ */
+public class OptimisticNotificationTest extends NotificationTest
+{
+ public OptimisticNotificationTest()
+ {
+ optimistic = true;
+ }
+}
Property changes on: core/trunk/src/test/java/org/jboss/cache/jmx/deprecated/OptimisticNotificationTest.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
More information about the jbosscache-commits
mailing list