1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
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 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
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 |
2
| protected void setUp() throws Exception
|
34 |
| { |
35 |
2
| mBeanServer = MBeanServerFactory.createMBeanServer("CacheMBeanTest");
|
36 |
| |
37 |
2
| Configuration c = new Configuration();
|
38 |
2
| c.setClusterName("PojoCacheMBeanTest");
|
39 |
2
| c.setExposeManagementStatistics(true);
|
40 |
2
| c.setCacheMode(Configuration.CacheMode.LOCAL);
|
41 |
2
| boolean toStart = false;
|
42 |
2
| cache = PojoCacheFactory.createCache(c, toStart);
|
43 |
2
| cache.start();
|
44 |
| |
45 |
2
| mBeanNameStr = JmxUtil.getPojoCacheObjectName(cache);
|
46 |
2
| mBeanName = new ObjectName(mBeanNameStr);
|
47 |
2
| PojoCacheJmxWrapper wrapper = new PojoCacheJmxWrapper(cache);
|
48 |
2
| mBeanServer.registerMBean(wrapper, mBeanName);
|
49 |
2
| wrapper.create();
|
50 |
2
| wrapper.start();
|
51 |
| } |
52 |
| |
53 |
2
| protected void tearDown()
|
54 |
| { |
55 |
2
| if (cache != null)
|
56 |
| { |
57 |
2
| cache.stop();
|
58 |
2
| cache = null;
|
59 |
| } |
60 |
| |
61 |
2
| if (mBeanServer != null)
|
62 |
| { |
63 |
2
| MBeanServerFactory.releaseMBeanServer(mBeanServer);
|
64 |
2
| mBeanServer = null;
|
65 |
| } |
66 |
| } |
67 |
| |
68 |
2
| public void testDummy()
|
69 |
| { |
70 |
| |
71 |
| } |
72 |
| |
73 |
0
| public void XtestCacheMBeanBinding() throws Exception
|
74 |
| { |
75 |
0
| String tmpName = JmxUtil.getCacheObjectName((org.jboss.cache.CacheSPI)cache.getCache());
|
76 |
0
| ObjectName tmpBeanName = new ObjectName(tmpName);
|
77 |
0
| assertTrue("Cache Mbean should be registered ", mBeanServer.isRegistered(tmpBeanName));
|
78 |
0
| assertTrue("PojoCache Mbean hould be registered ", mBeanServer.isRegistered(mBeanName));
|
79 |
| } |
80 |
| |
81 |
0
| public void XtestConfiguration() throws Exception
|
82 |
| { |
83 |
0
| String tmpName = JmxUtil.getCacheObjectName((org.jboss.cache.CacheSPI)cache.getCache());
|
84 |
0
| ObjectName tmpBeanName = new ObjectName(tmpName);
|
85 |
0
| Configuration cfgFromJmx = (Configuration) mBeanServer.getAttribute(tmpBeanName, "Configuration");
|
86 |
0
| assertEquals(cache.getCache().getConfiguration(), cfgFromJmx);
|
87 |
| } |
88 |
| |
89 |
0
| public void XtestCacheOperations() throws Exception
|
90 |
| { |
91 |
0
| String cacheName = (String) mBeanServer.getAttribute(mBeanName, "UnderlyingCacheObjectName");
|
92 |
0
| String tmpName = JmxUtil.getCacheObjectName((org.jboss.cache.CacheSPI)cache.getCache());
|
93 |
0
| assertEquals("Cache object name ", tmpName, cacheName);
|
94 |
| } |
95 |
| |
96 |
| } |