1 7 8 package org.jboss.cache.pojo.jmx; 9 10 import junit.framework.TestCase; 11 import org.jboss.cache.pojo.jmx.JmxUtil; 12 import org.jboss.cache.pojo.jmx.PojoCacheJmxWrapper; 13 import org.jboss.cache.pojo.PojoCacheFactory; 14 import org.jboss.cache.config.Configuration; 15 16 import javax.management.MBeanServer ; 17 import javax.management.ObjectName ; 18 import javax.management.MalformedObjectNameException ; 19 import javax.management.MBeanServerFactory ; 20 21 26 public class MBeanTest extends TestCase 27 { 28 private org.jboss.cache.pojo.PojoCache cache; 29 private MBeanServer mBeanServer; 30 private ObjectName mBeanName; 31 private String mBeanNameStr; 32 33 protected void setUp() throws Exception 34 { 35 mBeanServer = MBeanServerFactory.createMBeanServer("CacheMBeanTest"); 36 37 Configuration c = new Configuration(); 38 c.setClusterName("PojoCacheMBeanTest"); 39 c.setExposeManagementStatistics(true); 40 c.setCacheMode(Configuration.CacheMode.LOCAL); 41 boolean toStart = false; 42 cache = PojoCacheFactory.createCache(c, toStart); 43 cache.start(); 44 45 mBeanNameStr = JmxUtil.getPojoCacheObjectName(cache); 46 mBeanName = new ObjectName (mBeanNameStr); 47 PojoCacheJmxWrapper wrapper = new PojoCacheJmxWrapper(cache); 48 mBeanServer.registerMBean(wrapper, mBeanName); 49 wrapper.create(); 50 wrapper.start(); 51 } 52 53 protected void tearDown() 54 { 55 if (cache != null) 56 { 57 cache.stop(); 58 cache = null; 59 } 60 61 if (mBeanServer != null) 62 { 63 MBeanServerFactory.releaseMBeanServer(mBeanServer); 64 mBeanServer = null; 65 } 66 } 67 68 public void testDummy() 69 { 70 71 } 72 73 public void XtestCacheMBeanBinding() throws Exception 74 { 75 String tmpName = JmxUtil.getCacheObjectName((org.jboss.cache.CacheSPI)cache.getCache()); 76 ObjectName tmpBeanName = new ObjectName (tmpName); 77 assertTrue("Cache Mbean should be registered ", mBeanServer.isRegistered(tmpBeanName)); 78 assertTrue("PojoCache Mbean hould be registered ", mBeanServer.isRegistered(mBeanName)); 79 } 80 81 public void XtestConfiguration() throws Exception 82 { 83 String tmpName = JmxUtil.getCacheObjectName((org.jboss.cache.CacheSPI)cache.getCache()); 84 ObjectName tmpBeanName = new ObjectName (tmpName); 85 Configuration cfgFromJmx = (Configuration) mBeanServer.getAttribute(tmpBeanName, "Configuration"); 86 assertEquals(cache.getCache().getConfiguration(), cfgFromJmx); 87 } 88 89 public void XtestCacheOperations() throws Exception 90 { 91 String cacheName = (String ) mBeanServer.getAttribute(mBeanName, "UnderlyingCacheObjectName"); 92 String tmpName = JmxUtil.getCacheObjectName((org.jboss.cache.CacheSPI)cache.getCache()); 93 assertEquals("Cache object name ", tmpName, cacheName); 94 } 95 96 } 97 | Popular Tags |