Clover coverage report -
Coverage timestamp: Wed Jan 31 2007 15:38:53 EST
file stats: LOC: 99   Methods: 6
NCLOC: 74   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CacheMBeanTest.java 50% 100% 100% 94.9%
coverage coverage
 1    package org.jboss.cache.jmx;
 2   
 3    import junit.framework.TestCase;
 4    import org.jboss.cache.Cache;
 5    import org.jboss.cache.CacheSPI;
 6    import org.jboss.cache.DefaultCacheFactory;
 7    import org.jboss.cache.Fqn;
 8    import org.jboss.cache.config.Configuration;
 9   
 10    import javax.management.MBeanServer;
 11    import javax.management.MBeanServerFactory;
 12    import javax.management.ObjectName;
 13   
 14    /**
 15    * Tests the cache as an MBean
 16    *
 17    * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
 18    */
 19    public class CacheMBeanTest extends TestCase
 20    {
 21    private Cache cache;
 22    private MBeanServer mBeanServer;
 23    private ObjectName mBeanName;
 24    private String mBeanNameStr;
 25   
 26  4 protected void setUp() throws Exception
 27    {
 28  4 mBeanServer = MBeanServerFactory.createMBeanServer("CacheMBeanTest");
 29   
 30  4 Configuration c = new Configuration();
 31  4 c.setClusterName("CacheMBeanTest");
 32  4 c.setExposeManagementStatistics(true);
 33  4 c.setCacheMode(Configuration.CacheMode.LOCAL);
 34  4 cache = DefaultCacheFactory.getInstance().createCache(c);
 35  4 mBeanNameStr = JmxUtil.PREFIX + cache.getConfiguration().getClusterName();
 36  4 mBeanName = new ObjectName(mBeanNameStr);
 37   
 38  4 JmxUtil.registerCacheMBean(mBeanServer, new CacheJmxWrapper(cache), mBeanNameStr);
 39  4 JmxUtil.registerInterceptors(mBeanServer, ((CacheSPI) cache).getInterceptorChain(), mBeanNameStr);
 40    }
 41   
 42  4 protected void tearDown()
 43    {
 44  4 if (cache != null)
 45    {
 46  4 cache.stop();
 47  4 cache = null;
 48    }
 49   
 50  4 if (mBeanServer != null)
 51    {
 52  4 MBeanServerFactory.releaseMBeanServer(mBeanServer);
 53  4 mBeanServer = null;
 54    }
 55    }
 56   
 57  1 public void testCacheMBeanBinding() throws Exception
 58    {
 59  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 60    }
 61   
 62  1 public void testInterceptorMBeans() throws Exception
 63    {
 64  1 assertTrue("Should be registered", mBeanServer.isRegistered(mBeanName));
 65   
 66    // should be 3 interceptor MBeans loaded:
 67  1 ObjectName[] interceptorMBeanNames = {
 68    new ObjectName(mBeanNameStr + JmxUtil.MBEAN_KEY + "TxInterceptor"),
 69    new ObjectName(mBeanNameStr + JmxUtil.MBEAN_KEY + "CacheMgmtInterceptor"),
 70    new ObjectName(mBeanNameStr + JmxUtil.MBEAN_KEY + "InvocationContextInterceptor")
 71    };
 72   
 73    // TestingUtil.sleepThread(600000);
 74   
 75  1 for (ObjectName n : interceptorMBeanNames)
 76    {
 77  3 assertTrue(n + " should be registered", mBeanServer.isRegistered(n));
 78    }
 79    }
 80   
 81  1 public void testConfiguration() throws Exception
 82    {
 83  1 Configuration cfgFromJmx = (Configuration) mBeanServer.getAttribute(mBeanName, "Configuration");
 84  1 assertEquals(cache.getConfiguration(), cfgFromJmx);
 85    }
 86   
 87  1 public void testCacheOperations() throws Exception
 88    {
 89  1 Cache cacheJmx = (Cache) mBeanServer.getAttribute(mBeanName, "Cache");
 90  1 cacheJmx.getRoot().put("key", "value");
 91   
 92  1 assertEquals("value", cache.getRoot().get("key"));
 93   
 94  1 Fqn fqn = Fqn.fromString("//testing/jmx");
 95  1 cache.put(fqn, "key", "value");
 96   
 97  1 assertEquals("value", cacheJmx.get(fqn, "key"));
 98    }
 99    }