use of javax.management.MalformedObjectNameException in project LogHub by fbacchella.
the class TestStats method test1.
@Test
public void test1() throws NotCompliantMBeanException, MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException {
loghub.Stats.reset();
StatsMBean stats = new StatsMBean.Implementation();
Exception e = new NullPointerException();
loghub.Stats.newException(e);
assertEquals(String.format("NullPointerException at loghub.jmx.TestStats.test1 line %d", e.getStackTrace()[0].getLineNumber()), stats.getExceptions()[0]);
}
use of javax.management.MalformedObjectNameException in project LogHub by fbacchella.
the class TestStats method test2.
@Test
public void test2() throws NotCompliantMBeanException, MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException {
loghub.Stats.reset();
StatsMBean stats = new StatsMBean.Implementation();
Exception e = new RuntimeException("some message");
loghub.Stats.newException(e);
assertEquals(String.format("some message at loghub.jmx.TestStats.test2 line %d", e.getStackTrace()[0].getLineNumber()), stats.getExceptions()[0]);
}
use of javax.management.MalformedObjectNameException in project openj9 by eclipse.
the class MyTestListener method testRemoveNotificationListenerNotificationListener.
/*
* Class under test for void
* removeNotificationListener(NotificationListener)
*/
@Test
public final void testRemoveNotificationListenerNotificationListener() {
// Add a listener without a filter object.
MyTestListener listener = new MyTestListener();
mb.addNotificationListener(listener, null, null);
// Fire off a notification and ensure that the listener receives it.
try {
MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
CompositeData cd = TestUtil.toCompositeData(info);
Notification notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
notification.setUserData(cd);
mb.sendNotification(notification);
AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
// Verify that the handback is as expected.
AssertJUnit.assertNull(listener.getHandback());
// Verify the user data of the notification.
Notification n = listener.getNotification();
AssertJUnit.assertNotNull(n);
verifyNotificationUserData(n.getUserData());
// Remove the listener
mb.removeNotificationListener(listener);
// Fire off a notification and ensure that the listener does
// *not* receive it.
listener.resetNotificationsReceivedCount();
notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
notification.setUserData(cd);
mb.sendNotification(notification);
AssertJUnit.assertEquals(0, listener.getNotificationsReceivedCount());
// ListenerNotFoundException being thrown.
try {
mb.removeNotificationListener(listener);
Assert.fail("Should have thrown a ListenerNotFoundException!");
} catch (ListenerNotFoundException e) {
}
} catch (MalformedObjectNameException e) {
Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
e.printStackTrace();
} catch (ListenerNotFoundException e) {
Assert.fail("Unexpected ListenerNotFoundException : " + e.getMessage());
e.printStackTrace();
}
}
use of javax.management.MalformedObjectNameException in project openj9 by eclipse.
the class MyTestListener method testAddNotificationListener.
@Test
public final void testAddNotificationListener() {
// Add a listener with a handback object.
MyTestListener listener = new MyTestListener();
ArrayList<String> arr = new ArrayList<String>();
arr.add("Hegemony or survival ?");
mb.addNotificationListener(listener, null, arr);
// Fire off a notification and ensure that the listener receives it.
try {
MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
CompositeData cd = TestUtil.toCompositeData(info);
Notification notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
notification.setUserData(cd);
mb.sendNotification(notification);
AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
// Verify that the handback is as expected.
AssertJUnit.assertNotNull(listener.getHandback());
AssertJUnit.assertSame(arr, listener.getHandback());
ArrayList arr2 = (ArrayList) listener.getHandback();
AssertJUnit.assertTrue(arr2.size() == 1);
AssertJUnit.assertEquals("Hegemony or survival ?", arr2.get(0));
} catch (MalformedObjectNameException e) {
Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
e.printStackTrace();
}
}
use of javax.management.MalformedObjectNameException in project openj9 by eclipse.
the class TestManagementFactory method testMemoryMXBeanProxyNotificationEmitter.
@Test
public void testMemoryMXBeanProxyNotificationEmitter() {
try {
MemoryMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "java.lang:type=Memory", MemoryMXBean.class);
AssertJUnit.assertNotNull(proxy);
// Verify that the proxy is acting as a NotificationEmitter
AssertJUnit.assertTrue(proxy instanceof NotificationEmitter);
NotificationEmitter proxyEmitter = (NotificationEmitter) proxy;
// Add a listener with a handback object.
MyTestListener listener = new MyTestListener();
ArrayList<String> arr = new ArrayList<String>();
arr.add("Rock on Tommy !!!");
proxyEmitter.addNotificationListener(listener, null, arr);
// Fire off a notification and ensure that the listener receives it.
try {
MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
CompositeData cd = TestUtil.toCompositeData(info);
Notification notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
notification.setUserData(cd);
((MemoryMXBeanImpl) ManagementFactory.getMemoryMXBean()).sendNotification(notification);
AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
// Verify that the handback is as expected.
AssertJUnit.assertNotNull(listener.getHandback());
AssertJUnit.assertSame(arr, listener.getHandback());
ArrayList<?> arr2 = (ArrayList<?>) listener.getHandback();
AssertJUnit.assertEquals(1, arr2.size());
AssertJUnit.assertEquals("Rock on Tommy !!!", arr2.get(0));
} catch (MalformedObjectNameException e) {
Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
e.printStackTrace();
}
} catch (IllegalArgumentException e) {
Assert.fail("Unexpected IllegalArgumentException : " + e.getMessage());
} catch (NullPointerException e) {
Assert.fail("Unexpected NullPointerException : " + e.getMessage());
} catch (IOException e) {
Assert.fail("Unexpected IOException : " + e.getMessage());
}
}
Aggregations