[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/pojo/jmx ...
Brian Stansberry
brian.stansberry at jboss.com
Fri May 11 18:44:49 EDT 2007
User: bstansberry
Date: 07/05/11 18:44:49
Added: tests/functional/org/jboss/cache/pojo/jmx
InterceptorRegistrationTest.java
PojoCacheJmxWrapperTest.java
PojoCacheJmxWrapperTestBase.java
Removed: tests/functional/org/jboss/cache/pojo/jmx MBeanTest.java
Log:
PojoCache JMX testsuite additions and refactor
Revision Changes Path
1.1 date: 2007/05/11 22:44:49; author: bstansberry; state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/jmx/InterceptorRegistrationTest.java
Index: InterceptorRegistrationTest.java
===================================================================
/*
* 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.pojo.jmx;
import org.jboss.cache.config.Configuration;
/**
* Tests the interceptor registration function of CacheJmxWrapper.
*
* @author <a href="brian.stansberry at jboss.com">Brian Stansberry</a>
* @version $Revision: 1.1 $
*/
public class InterceptorRegistrationTest extends PojoCacheJmxWrapperTestBase
{
/**
* Confirms interceptor mbeans are registered if the following events
* occur:
*
* 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();
PojoCacheJmxWrapperMBean wrapper = registerWrapper(cache);
assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
interceptorRegistrationTest(true);
wrapper.stop();
wrapper.destroy();
// Should still be registered
interceptorRegistrationTest(true);
unregisterWrapper();
interceptorRegistrationTest(false);
}
/**
* Confirms interceptor mbeans are registered if the following events
* occur:
*
* 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();
PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(cache);
wrapper.start();
wrapper = registerWrapper(wrapper);
assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
interceptorRegistrationTest(true);
wrapper.stop();
wrapper.destroy();
// Should still be registered
interceptorRegistrationTest(true);
unregisterWrapper();
interceptorRegistrationTest(false);
}
/**
* Confirms interceptor mbeans are registered if the following events
* occur:
*
* Cache not injected
* wrapper registered;
* wrapper created and started.
*
* @throws Exception
*/
public void testInterceptorMBeans3() throws Exception
{
PojoCacheJmxWrapperMBean 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:
*
* Cache not injected
* wrapper created and started.
* wrapper registered
*
* @throws Exception
*/
public void testInterceptorMBeans4() throws Exception
{
PojoCacheJmxWrapper 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:
*
* cache constructed;
* wrapper constructed and registered with manageCacheLifecycle=true
* wrapper created and started
*
* @throws Exception
*/
public void testInterceptorMBeans5() throws Exception
{
PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(createCache(createConfiguration()));
wrapper.setManageCacheLifecycle(true);
wrapper = registerWrapper(wrapper);
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 NOT registered if the following events
* occur:
*
* cache constructed;
* wrapper constructed and registered
* wrapper created and started
*
* @throws Exception
*/
public void testInterceptorMBeans6() throws Exception
{
PojoCacheJmxWrapperMBean wrapper = registerWrapper();
assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
// have to start the cache to have any interceptors
wrapper.create();
wrapper.start();
interceptorRegistrationTest(false);
wrapper.stop();
wrapper.destroy();
interceptorRegistrationTest(false);
unregisterWrapper();
interceptorRegistrationTest(false);
}
/**
* Confirms interceptor mbeans are NOT registered if the following events
* occur:
*
* cache constructed;
* wrapper created and started
* wrapper registered
*
* @throws Exception
*/
public void testInterceptorMBeans7() throws Exception
{
PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(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(false);
wrapper.stop();
wrapper.destroy();
interceptorRegistrationTest(false);
unregisterWrapper();
interceptorRegistrationTest(false);
}
/**
* Confirms interceptor mbeans are NOT registered if the following events
* occur:
*
* wrapper created from config
* wrapper.managerCacheLifecycle=false
* wrapper created and started
* wrapper registered
*
* @throws Exception
*/
public void testInterceptorMBeans8() throws Exception
{
PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(createCache(createConfiguration()));
wrapper.setManageCacheLifecycle(false);
// have to start the cache to have any interceptors
wrapper.create();
wrapper.start();
wrapper = registerWrapper(wrapper);
assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
interceptorRegistrationTest(false);
wrapper.stop();
wrapper.destroy();
interceptorRegistrationTest(false);
unregisterWrapper();
interceptorRegistrationTest(false);
}
/**
* Confirms interceptor mbeans are NOT registered if the following events
* occur:
*
* wrapper created from config
* wrapper.managerCacheLifecycle=false
* wrapper registered
* wrapper created and started
*
* @throws Exception
*/
public void testInterceptorMBeans9() throws Exception
{
PojoCacheJmxWrapperMBean wrapper = new PojoCacheJmxWrapper(createCache(createConfiguration()));
wrapper.setManageCacheLifecycle(false);
wrapper = registerWrapper(wrapper);
assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
// have to start the cache to have any interceptors
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 before create/start
* are called.
*
* @throws Exception
*/
public void testRegisterInterceptors1() throws Exception
{
PojoCacheJmxWrapper wrapper = createWrapper(createConfiguration());
wrapper.setRegisterInterceptors(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
{
PojoCacheJmxWrapper wrapper = createWrapper(createConfiguration());
wrapper.setRegisterInterceptors(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);
PojoCacheJmxWrapper 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);
PojoCacheJmxWrapper 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);
}
}
1.1 date: 2007/05/11 22:44:49; author: bstansberry; state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapperTest.java
Index: PojoCacheJmxWrapperTest.java
===================================================================
/*
* JBoss, Home of Professional Open Source
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.cache.pojo.jmx;
import javax.management.ObjectName;
import org.jboss.cache.config.Configuration;
/**
* Tests the PojoCacheJmxWrapper class
*
* @author <a href="mailto:ben.wang at jboss.org">Ben Wang</a>
* @author Brian Stansberry
*/
public class PojoCacheJmxWrapperTest extends PojoCacheJmxWrapperTestBase
{
public void testCacheMBeanBinding() throws Exception
{
registerWrapper();
assertTrue("Cache Mbean should be registered ", mBeanServer.isRegistered(plainCacheMBeanName));
assertTrue("PojoCache Mbean hould be registered ", mBeanServer.isRegistered(mBeanName));
}
public void testConfiguration() throws Exception
{
registerWrapper();
Configuration cfgFromJmx = (Configuration) mBeanServer.getAttribute(plainCacheMBeanName, "Configuration");
assertEquals(cache.getCache().getConfiguration(), cfgFromJmx);
}
public void testGetUnderlyingCacheObjectName() throws Exception
{
registerWrapper();
String cacheName = (String) mBeanServer.getAttribute(mBeanName, "UnderlyingCacheObjectName");
ObjectName tmpName = JmxUtil.getPlainCacheObjectName(mBeanName);
assertEquals("Cache object name ", tmpName.getCanonicalName(), cacheName);
}
}
1.1 date: 2007/05/11 22:44:49; author: bstansberry; state: Exp;JBossCache/tests/functional/org/jboss/cache/pojo/jmx/PojoCacheJmxWrapperTestBase.java
Index: PojoCacheJmxWrapperTestBase.java
===================================================================
package org.jboss.cache.pojo.jmx;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MBeanServerInvocationHandler;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import junit.framework.TestCase;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.pojo.PojoCache;
import org.jboss.cache.pojo.PojoCacheFactory;
/**
* Tests the JMX wrapper class around a PojoCache.
*
* @author Brian Stansberry
*/
public class PojoCacheJmxWrapperTestBase extends TestCase
{
public static final String PC_PREFIX = JmxUtil.POJO_CACHE_DOMAIN + ":" +
JmxUtil.SERVICE_KEY_NAME + "=PojoCacheJmxWrapperTest," +
JmxUtil.CLUSTER_KEY + "=";
public static final String CLUSTER_NAME = "PojoCacheMBeanTest";
protected PojoCache cache;
protected PojoCacheJmxWrapperMBean jmxWrapper;
protected MBeanServer mBeanServer;
protected ObjectName mBeanName;
protected String mBeanNameStr;
protected ObjectName plainCacheMBeanName;
protected String plainCacheMBeanNameStr;
protected void setUp() throws Exception
{
mBeanServer = MBeanServerFactory.createMBeanServer("PojoCacheMBeanTest");
mBeanName = new ObjectName(PC_PREFIX + CLUSTER_NAME);
mBeanNameStr = mBeanName.getCanonicalName();
plainCacheMBeanName = JmxUtil.getPlainCacheObjectName(mBeanName);
plainCacheMBeanNameStr = plainCacheMBeanName.getCanonicalName();
}
protected void tearDown() throws Exception
{
try
{
cleanup();
}
finally
{
if (mBeanServer != null)
{
MBeanServerFactory.releaseMBeanServer(mBeanServer);
mBeanServer = null;
}
}
}
protected PojoCacheJmxWrapperMBean registerWrapper() throws Exception
{
if (cache == null)
cache = createCache(createConfiguration());
return registerWrapper(cache);
}
protected PojoCacheJmxWrapperMBean registerWrapper(PojoCache toWrap) throws Exception
{
PojoCacheJmxWrapper wrapper = new PojoCacheJmxWrapper(toWrap);
return registerWrapper(wrapper);
}
protected PojoCacheJmxWrapperMBean registerWrapper(Configuration config) throws Exception
{
PojoCacheJmxWrapper wrapper = new PojoCacheJmxWrapper();
wrapper.setConfiguration(config);
return registerWrapper(wrapper);
}
protected PojoCacheJmxWrapperMBean registerWrapper(PojoCacheJmxWrapperMBean wrapper) throws Exception
{
JmxUtil.registerPojoCache(mBeanServer, wrapper, mBeanNameStr);
jmxWrapper = (PojoCacheJmxWrapperMBean) MBeanServerInvocationHandler.newProxyInstance(mBeanServer, mBeanName, PojoCacheJmxWrapperMBean.class, false);
return jmxWrapper;
}
protected void unregisterWrapper() throws Exception
{
mBeanServer.unregisterMBean(mBeanName);
}
protected PojoCacheJmxWrapper createWrapper(Configuration config)
{
PojoCacheJmxWrapper wrapper = new PojoCacheJmxWrapper();
wrapper.setConfiguration(config);
return wrapper;
}
protected PojoCache createCache(Configuration config)
{
cache = PojoCacheFactory.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(plainCacheMBeanNameStr, expectMbeans);
}
protected void interceptorRegistrationTest(String baseName, boolean expectMbeans) throws MalformedObjectNameException, NullPointerException
{
// should be 3 interceptor MBeans loaded:
ObjectName[] interceptorMBeanNames = {
new ObjectName(baseName + JmxUtil.INTERCEPTOR_KEY + "TxInterceptor"),
new ObjectName(baseName + JmxUtil.INTERCEPTOR_KEY + "CacheMgmtInterceptor"),
new ObjectName(baseName + JmxUtil.INTERCEPTOR_KEY + "InvocationContextInterceptor")
};
for (ObjectName n : interceptorMBeanNames)
{
if (expectMbeans)
assertTrue(n + " should be registered", mBeanServer.isRegistered(n));
else
assertFalse(n + " should not be registered", mBeanServer.isRegistered(n));
}
}
}
More information about the jboss-cvs-commits
mailing list