< prev index next >
application/tests/org.openjdk.jmc.rjmx.test/src/test/java/org/openjdk/jmc/rjmx/test/synthetic/SyntheticNotificationTest.java
Print this page
*** 81,91 ****
@Override
@Before
public void setUp() throws Exception {
super.setUp();
! handle = getDefaultServer().connect("Test"); //$NON-NLS-1$
connection = handle.getServiceOrThrow(MBeanServerConnection.class);
gotNotification = false;
}
@Override
--- 81,91 ----
@Override
@Before
public void setUp() throws Exception {
super.setUp();
! handle = getDefaultServer().connect("Test");
connection = handle.getServiceOrThrow(MBeanServerConnection.class);
gotNotification = false;
}
@Override
*** 97,166 ****
* Tests that we can add synthetic notifications.
*/
@Test
public void testGetNotificationMetadata() throws InstanceNotFoundException, IntrospectionException,
MalformedObjectNameException, ReflectionException, NullPointerException, IOException {
! MBeanInfo info = connection.getMBeanInfo(new ObjectName("org.openjdk.jmc.test:type=Test")); //$NON-NLS-1$
assertTrue(info.getNotifications().length > 0);
}
/**
* Tests that we can have attributes AND notifications on the same synthetic.
*/
@Test
public void testCombinedMetadata() throws InstanceNotFoundException, IntrospectionException,
MalformedObjectNameException, ReflectionException, NullPointerException, IOException {
! MBeanInfo info = connection.getMBeanInfo(new ObjectName("org.openjdk.jmc.test:type=Test")); //$NON-NLS-1$
assertTrue(info.getNotifications().length > 0);
assertTrue(info.getAttributes().length > 0);
}
/**
* Tests that we can overload existing real MBean with notification and still get values.
*/
@Test
public void testOverloadMetadata() throws InstanceNotFoundException, IntrospectionException,
MalformedObjectNameException, ReflectionException, NullPointerException, IOException {
! MBeanInfo info = connection.getMBeanInfo(new ObjectName("java.lang:type=ClassLoading")); //$NON-NLS-1$
assertTrue(info.getNotifications().length > 0);
assertTrue(info.getAttributes().length > 0);
}
/**
* Tests that we can shadow an existing notification.
*/
@Test
public void testShadowMetadata() throws InstanceNotFoundException, IntrospectionException,
MalformedObjectNameException, ReflectionException, NullPointerException, IOException {
! Assume.assumeTrue("FIXME: Shadowing does not work yet!", false); //$NON-NLS-1$
! MBeanInfo info = connection.getMBeanInfo(new ObjectName("java.lang:type=Memory")); //$NON-NLS-1$
assertTrue(info.getNotifications().length > 0);
for (MBeanNotificationInfo notificationInfo : info.getNotifications()) {
! if (notificationInfo.getName().equals("java.management.memory.collection.threshold.exceeded")) { //$NON-NLS-1$
! assertTrue("Failed to shadow description", notificationInfo.getDescription().contains("shadow")); //$NON-NLS-1$ //$NON-NLS-2$
! assertTrue("Got the wrong type:" + notificationInfo.getNotifTypes()[0], "int".equals(notificationInfo //$NON-NLS-1$ //$NON-NLS-2$
.getNotifTypes()[0]));
} else {
! assertTrue("Should NOT contain shadow!", !notificationInfo.getDescription().contains("shadow")); //$NON-NLS-1$ //$NON-NLS-2$
! assertTrue("Should not be int!", !"int".equals(notificationInfo.getNotifTypes()[0])); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
@Test
public void testNotificationListener() throws InstanceNotFoundException, MalformedObjectNameException,
NullPointerException, IOException, InterruptedException, ListenerNotFoundException {
Notification notif = null;
SyntheticNotificationListener listener = new SyntheticNotificationListener();
! ObjectName testMBean = new ObjectName("org.openjdk.jmc.test:type=Test"); //$NON-NLS-1$
connection.addNotificationListener(testMBean, listener, null, null);
synchronized (this) {
this.wait(30000);
notif = listener.getLastNotification();
}
! assertTrue("Never got any notification!", gotNotification); //$NON-NLS-1$
assertNotNull(notif);
! assertTrue("Expected a user data > 0!", ((Integer) notif.getUserData()) > 0); //$NON-NLS-1$
! assertTrue("Expected Woho!", notif.getMessage().startsWith("Woho!")); //$NON-NLS-1$ //$NON-NLS-2$
connection.removeNotificationListener(testMBean, listener, null, null);
}
}
--- 97,166 ----
* Tests that we can add synthetic notifications.
*/
@Test
public void testGetNotificationMetadata() throws InstanceNotFoundException, IntrospectionException,
MalformedObjectNameException, ReflectionException, NullPointerException, IOException {
! MBeanInfo info = connection.getMBeanInfo(new ObjectName("org.openjdk.jmc.test:type=Test"));
assertTrue(info.getNotifications().length > 0);
}
/**
* Tests that we can have attributes AND notifications on the same synthetic.
*/
@Test
public void testCombinedMetadata() throws InstanceNotFoundException, IntrospectionException,
MalformedObjectNameException, ReflectionException, NullPointerException, IOException {
! MBeanInfo info = connection.getMBeanInfo(new ObjectName("org.openjdk.jmc.test:type=Test"));
assertTrue(info.getNotifications().length > 0);
assertTrue(info.getAttributes().length > 0);
}
/**
* Tests that we can overload existing real MBean with notification and still get values.
*/
@Test
public void testOverloadMetadata() throws InstanceNotFoundException, IntrospectionException,
MalformedObjectNameException, ReflectionException, NullPointerException, IOException {
! MBeanInfo info = connection.getMBeanInfo(new ObjectName("java.lang:type=ClassLoading"));
assertTrue(info.getNotifications().length > 0);
assertTrue(info.getAttributes().length > 0);
}
/**
* Tests that we can shadow an existing notification.
*/
@Test
public void testShadowMetadata() throws InstanceNotFoundException, IntrospectionException,
MalformedObjectNameException, ReflectionException, NullPointerException, IOException {
! Assume.assumeTrue("FIXME: Shadowing does not work yet!", false);
! MBeanInfo info = connection.getMBeanInfo(new ObjectName("java.lang:type=Memory"));
assertTrue(info.getNotifications().length > 0);
for (MBeanNotificationInfo notificationInfo : info.getNotifications()) {
! if (notificationInfo.getName().equals("java.management.memory.collection.threshold.exceeded")) {
! assertTrue("Failed to shadow description", notificationInfo.getDescription().contains("shadow"));
! assertTrue("Got the wrong type:" + notificationInfo.getNotifTypes()[0], "int".equals(notificationInfo
.getNotifTypes()[0]));
} else {
! assertTrue("Should NOT contain shadow!", !notificationInfo.getDescription().contains("shadow"));
! assertTrue("Should not be int!", !"int".equals(notificationInfo.getNotifTypes()[0]));
}
}
}
@Test
public void testNotificationListener() throws InstanceNotFoundException, MalformedObjectNameException,
NullPointerException, IOException, InterruptedException, ListenerNotFoundException {
Notification notif = null;
SyntheticNotificationListener listener = new SyntheticNotificationListener();
! ObjectName testMBean = new ObjectName("org.openjdk.jmc.test:type=Test");
connection.addNotificationListener(testMBean, listener, null, null);
synchronized (this) {
this.wait(30000);
notif = listener.getLastNotification();
}
! assertTrue("Never got any notification!", gotNotification);
assertNotNull(notif);
! assertTrue("Expected a user data > 0!", ((Integer) notif.getUserData()) > 0);
! assertTrue("Expected Woho!", notif.getMessage().startsWith("Woho!"));
connection.removeNotificationListener(testMBean, listener, null, null);
}
}
< prev index next >