[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/jmx ...

Manik Surtani msurtani at jboss.com
Wed Sep 6 10:45:45 EDT 2006


  User: msurtani
  Date: 06/09/06 10:45:45

  Added:       tests/functional/org/jboss/cache/jmx  CacheMBeanTest.java
  Log:
  fixed JMX tests, added more JMX tests
  
  Revision  Changes    Path
  1.1      date: 2006/09/06 14:45:45;  author: msurtani;  state: Exp;JBossCache/tests/functional/org/jboss/cache/jmx/CacheMBeanTest.java
  
  Index: CacheMBeanTest.java
  ===================================================================
  package org.jboss.cache.jmx;
  
  import junit.framework.TestCase;
  import org.jboss.cache.Cache;
  import org.jboss.cache.Fqn;
  import org.jboss.cache.config.Configuration;
  import org.jboss.cache.factories.DefaultCacheFactory;
  import org.jboss.cache.util.MBeanConfigurator;
  
  import javax.management.MBeanServer;
  import javax.management.MBeanServerFactory;
  import javax.management.MalformedObjectNameException;
  import javax.management.ObjectName;
  
  /**
   * Tests the cache as an MBean
   *
   * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
   */
  public class CacheMBeanTest extends TestCase
  {
     private Cache 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("CacheMBeanTest");
        c.setUseInterceptorMbeans(true);
        c.setCacheMode(Configuration.CacheMode.LOCAL);
        cache = new DefaultCacheFactory().createCache(c);
        mBeanNameStr = MBeanConfigurator.PREFIX + cache.getConfiguration().getClusterName();
        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
     {
        assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
     }
  
     public void testInterceptorMBeans() throws Exception
     {
        assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
  
        // should be 3 interceptor MBeans loaded:
        ObjectName[] interceptorMBeanNames = {
                new ObjectName(mBeanNameStr + MBeanConfigurator.MBEAN_KEY + "TxInterceptor"),
                new ObjectName(mBeanNameStr + MBeanConfigurator.MBEAN_KEY + "CacheMgmtInterceptor"),
                new ObjectName(mBeanNameStr + MBeanConfigurator.MBEAN_KEY + "InvocationContextInterceptor")
        };
  
  //      TestingUtil.sleepThread(600000);
  
        for (ObjectName n : interceptorMBeanNames)
        {
           assertTrue(n + " should be registered", mBeanServer.isRegistered(n));
        }
     }
  
     public void testConfiguration() throws Exception
     {
        Configuration cfgFromJmx = (Configuration) mBeanServer.getAttribute(mBeanName, "Configuration");
        assertEquals(cache.getConfiguration(), cfgFromJmx);
     }
  
     public void testCacheOperations() throws Exception
     {
        Cache cacheJmx = (Cache) mBeanServer.getAttribute(mBeanName, "Cache");
        cacheJmx.put("key", "value");
  
        assertEquals("value", cache.get("key"));
  
        Fqn fqn = Fqn.fromString("//testing/jmx");
        cache.put(fqn, "key", "value");
  
        assertEquals("value", cacheJmx.get(fqn, "key"));
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list