[jboss-cvs] JBossCache/tests-50/functional/org/jboss/cache/pojo/jmx ...
Ben Wang
bwang at jboss.com
Mon Sep 25 01:50:05 EDT 2006
User: bwang
Date: 06/09/25 01:50:05
Added: tests-50/functional/org/jboss/cache/pojo/jmx MBeanTest.java
Log:
1. Modify useInterceptorMbeans to useMbean
2. Added PojoCache jmx framework
3. added test
Revision Changes Path
1.1 date: 2006/09/25 05:50:05; author: bwang; state: Exp;JBossCache/tests-50/functional/org/jboss/cache/pojo/jmx/MBeanTest.java
Index: MBeanTest.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 junit.framework.TestCase;
import org.jboss.cache.Cache;
import org.jboss.cache.Fqn;
import org.jboss.cache.pojo.jmx.JmxUtil;
import org.jboss.cache.pojo.PojoCacheFactory;
import org.jboss.cache.factories.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanServerFactory;
/**
* Tests the cache as an MBean
*
* @author <a href="mailto:ben.wang at jboss.org">Ben Wang</a>
*/
public class MBeanTest extends TestCase
{
private org.jboss.cache.pojo.PojoCache cache;
private MBeanServer mBeanServer;
private ObjectName mBeanName;
private String mBeanNameStr;
protected void setUp() throws MalformedObjectNameException
{
mBeanServer = MBeanServerFactory.createMBeanServer("CacheMBeanTest");
Configuration c = new Configuration();
c.setClusterName("PojoCacheMBeanTest");
c.setUseMbean(true);
c.setCacheMode(Configuration.CacheMode.LOCAL);
boolean toStart = false;
cache = PojoCacheFactory.createInstance(c, toStart);
cache.start();
mBeanNameStr = JmxUtil.getPojoCacheObjectName(cache);
mBeanName = new ObjectName(mBeanNameStr);
}
protected void tearDown()
{
if (cache != null)
{
cache.stop();
cache = null;
}
if (mBeanServer != null)
{
MBeanServerFactory.releaseMBeanServer(mBeanServer);
mBeanServer = null;
}
}
public void testCacheMBeanBinding() throws Exception
{
String tmpName = JmxUtil.getCacheObjectName((org.jboss.cache.CacheSPI)cache.getCache());
ObjectName tmpBeanName = new ObjectName(tmpName);
assertTrue("Cache Mbean should be registered ", mBeanServer.isRegistered(tmpBeanName));
assertTrue("PojoCache Mbean hould be registered ", mBeanServer.isRegistered(mBeanName));
}
public void testConfiguration() throws Exception
{
Configuration cfgFromJmx = (Configuration) mBeanServer.getAttribute(mBeanName, "Configuration");
assertEquals(cache.getCache().getConfiguration(), cfgFromJmx);
}
public void testCacheOperations() throws Exception
{
String cacheName = (String) mBeanServer.getAttribute(mBeanName, "UnderlyingCacheObjectName");
String tmpName = JmxUtil.getCacheObjectName((org.jboss.cache.CacheSPI)cache.getCache());
assertEquals("Cache object name ", tmpName, cacheName);
}
}
More information about the jboss-cvs-commits
mailing list