@Test public void testMBeansDifferentPrefixAreIndependent() throws Exception { P6MBeansRegistry reg1 = constructMBean(null, JMX_PREFIX1, true); P6MBeansRegistry reg2 = constructMBean(null, JMX_PREFIX2, false); { // make sure, that jmx with prefix1 as well as the one with prefix2 are exposed checkMBeanAppendProperty(JMX_PREFIX1, true); checkMBeanAppendProperty(JMX_PREFIX2, false); } destroyMBean(reg1, JMX_PREFIX1); { // make sure, that jmx with prefix1 is no more exposed, but the one with prefix2 is still // exposed checkMBeanNotExposed(JMX_PREFIX1); checkMBeanAppendProperty(JMX_PREFIX2, false); } destroyMBean(reg2, JMX_PREFIX1); { // make sure, that jmx with prefix2 is not exposed either checkMBeanNotExposed(JMX_PREFIX2); } }
@Test public void testUnregisterMBeansWorks() throws Exception { P6MBeansRegistry mBeansRegistry = constructMBean(null, JMX_PREFIX_NONE, true); destroyMBean(mBeansRegistry, JMX_PREFIX_NONE); }
@Test public void testReRegisterMBeansSameRegistryWorks() throws Exception { P6MBeansRegistry mBeansRegistry = constructMBean(null, JMX_PREFIX_NONE, true); constructMBean(mBeansRegistry, JMX_PREFIX_NONE, false); }
private void destroyMBean(P6MBeansRegistry mBeansRegistry, final String jmxPrefix) throws Exception { // none to be reused registry if (null == mBeansRegistry) { mBeansRegistry = new P6MBeansRegistry(); } // unreg mBeansRegistry.unregisterAllMBeans(null); checkMBeanNotExposed(jmxPrefix); }
private P6MBeansRegistry constructMBean(P6MBeansRegistry mBeansRegistry, final String jmxPrefix, final boolean appendProperty) throws Exception { // none to be reused registry if (null == mBeansRegistry) { mBeansRegistry = new P6MBeansRegistry(); } final P6OptionsRepository repo = new P6OptionsRepository(); final P6SpyOptions opts = new P6SpyOptions(repo); opts.load(opts.getDefaults()); opts.setAppend(appendProperty); opts.setJmxPrefix(jmxPrefix); repo.initCompleted(); mBeansRegistry.registerMBeans(new ArrayList<P6LoadableOptions>(Arrays.asList(opts))); checkMBeanAppendProperty(jmxPrefix, appendProperty); return mBeansRegistry; }
@Test public void testReRegisterMBeansDifferentRegistryWorks() throws Exception { constructMBean(null, JMX_PREFIX_NONE, true); constructMBean(null, JMX_PREFIX_NONE, false); }