@Test(expected = InstanceNotFoundException.class) public void testCanUnregister() throws Exception { TestBean testBean = new TestBean("1"); ManagementRegistrar.register(objectName, testBean); ManagementRegistrar.unregister(objectName); ManagementRegistrar.normalizeAndRunQueuedCommands(); mBeanServer.getAttribute(new ObjectName(objectName), "Name"); }
@Test public void testCanRegister() throws Exception { final int iterations = 100000; final List<TestBean> beans = new ArrayList<TestBean>(iterations); for (int i = 0; i < iterations; i++) { if (i > 0) ManagementRegistrar.unregister(objectName); TestBean testBean = new TestBean("#" + i); beans.add(testBean); // holding a hard reference to ensure the instances are not GCed. ManagementRegistrar.register(objectName, testBean); } ManagementRegistrar.normalizeAndRunQueuedCommands(); assertEquals( beans.get(beans.size() - 1).getName(), mBeanServer.getAttribute(new ObjectName(objectName), "Name")); }
@After public void tearDown() throws Exception { ManagementRegistrar.unregister(objectName); ManagementRegistrar.normalizeAndRunQueuedCommands(); }