Search in sources :

Example 76 with MalformedObjectNameException

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]);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) Test(org.junit.Test)

Example 77 with MalformedObjectNameException

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]);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) Test(org.junit.Test)

Example 78 with MalformedObjectNameException

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();
    }
}
Also used : MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException) CompositeData(javax.management.openmbean.CompositeData) ListenerNotFoundException(javax.management.ListenerNotFoundException) MemoryUsage(java.lang.management.MemoryUsage) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test)

Example 79 with MalformedObjectNameException

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();
    }
}
Also used : MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) MemoryUsage(java.lang.management.MemoryUsage) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test)

Example 80 with MalformedObjectNameException

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());
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MemoryMXBeanImpl(com.ibm.java.lang.management.internal.MemoryMXBeanImpl) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) IOException(java.io.IOException) MemoryUsage(java.lang.management.MemoryUsage) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) MemoryMXBean(java.lang.management.MemoryMXBean) NotificationEmitter(javax.management.NotificationEmitter) Test(org.testng.annotations.Test)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)309 ObjectName (javax.management.ObjectName)285 InstanceNotFoundException (javax.management.InstanceNotFoundException)88 MBeanServer (javax.management.MBeanServer)80 MBeanRegistrationException (javax.management.MBeanRegistrationException)75 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)63 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)59 IOException (java.io.IOException)53 ArrayList (java.util.ArrayList)45 ReflectionException (javax.management.ReflectionException)30 MBeanException (javax.management.MBeanException)23 Test (org.testng.annotations.Test)23 CompositeData (javax.management.openmbean.CompositeData)18 Notification (javax.management.Notification)15 MBeanInfo (javax.management.MBeanInfo)14 AttributeNotFoundException (javax.management.AttributeNotFoundException)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 IntrospectionException (javax.management.IntrospectionException)11 MalformedURLException (java.net.MalformedURLException)10