Search in sources :

Example 1 with NotificationServiceHelper

use of com.sun.appserv.management.helper.NotificationServiceHelper in project Payara by payara.

the class NotificationServiceTest method testListen.

public void testListen() throws Exception {
    // trace( "testListen: START" );
    final NotificationService proxy = create();
    final QueryMgr queryMgr = getQueryMgr();
    final ObjectName objectName = Util.getObjectName(queryMgr);
    final Object id = proxy.createBuffer(10, null);
    final NotificationServiceHelper helper = new NotificationServiceHelper(proxy, id);
    proxy.listenTo(objectName, null);
    assert (proxy.getListeneeSet().size() == 1);
    assert (Util.getObjectName((Util.asAMX(proxy.getListeneeSet().iterator().next()))).equals(objectName));
    // trace( "testListen: NEWING" );
    // we expect two changes, see below
    final MyListener myListener = new MyListener(2);
    proxy.addNotificationListener(myListener, null, null);
    final String saveLevel = queryMgr.getMBeanLogLevel();
    queryMgr.setMBeanLogLevel("" + Level.FINEST);
    queryMgr.setMBeanLogLevel(saveLevel);
    // delivery may be asynchronous; wait until done
    if (!myListener.await(5, TimeUnit.SECONDS)) {
        // trace( "testListen: FAILED TIMEOUT" );
        assert false : "NotificationServiceTest.testListen():  TIMED OUT waiting for Notifications";
    }
    // trace( "testListen: NOT FAILED" );
    assert (myListener.getCount() == 2);
    Notification[] notifs = helper.getNotifications();
    assertEquals(2, notifs.length);
    assert (notifs[0].getType().equals(AttributeChangeNotification.ATTRIBUTE_CHANGE));
    assert (notifs[1].getType().equals(AttributeChangeNotification.ATTRIBUTE_CHANGE));
    notifs = helper.getNotifications();
    assert (notifs.length == 0);
    proxy.dontListenTo(objectName);
    assert (proxy.getListeneeSet().size() == 0);
    removeNotificationService(proxy);
// trace( "testListen: EXIT" );
}
Also used : QueryMgr(com.sun.appserv.management.base.QueryMgr) NotificationServiceHelper(com.sun.appserv.management.helper.NotificationServiceHelper) NotificationService(com.sun.appserv.management.base.NotificationService) Notification(javax.management.Notification) AttributeChangeNotification(javax.management.AttributeChangeNotification) ObjectName(javax.management.ObjectName)

Aggregations

NotificationService (com.sun.appserv.management.base.NotificationService)1 QueryMgr (com.sun.appserv.management.base.QueryMgr)1 NotificationServiceHelper (com.sun.appserv.management.helper.NotificationServiceHelper)1 AttributeChangeNotification (javax.management.AttributeChangeNotification)1 Notification (javax.management.Notification)1 ObjectName (javax.management.ObjectName)1