Search in sources :

Example 1 with NotificationService

use of com.sun.appserv.management.base.NotificationService in project Payara by payara.

the class NotificationServiceMgrTest method testCreateRemove.

public void testCreateRemove() throws Exception {
    final NotificationServiceMgr proxy = getNotificationServiceMgr();
    final NotificationService service = proxy.createNotificationService("test1", 512);
    final ObjectName objectName = Util.getObjectName(service);
    proxy.removeNotificationService(service.getName());
    assert (!getConnection().isRegistered(objectName));
}
Also used : NotificationServiceMgr(com.sun.appserv.management.base.NotificationServiceMgr) NotificationService(com.sun.appserv.management.base.NotificationService) ObjectName(javax.management.ObjectName)

Example 2 with NotificationService

use of com.sun.appserv.management.base.NotificationService 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)

Example 3 with NotificationService

use of com.sun.appserv.management.base.NotificationService in project Payara by payara.

the class MiscTest method testProxyDetectsMBeanRemoved.

/**
 *     Hangs were occuring in getPropertyNames().  Repeatedly invoke it to see if the hang
 *     can be reproduced.
 *     public void
 *     testGetPropertyNames()
 *     throws ClassNotFoundException
 *     {
 *     final Set	s	= getQueryMgr().queryInterfaceSet( PropertiesAccess.class.getName(), null );
 *
 *     for( int i = 0; i < 5000; ++i )
 *     {
 *     final Iterator iter	= s.iterator();
 *     while ( iter.hasNext() )
 *     {
 *     final PropertiesAccess	pa	= (PropertiesAccess)iter.next();
 *
 *     pa.getPropertyNames();
 *     }
 *     }
 *     }
 */
/**
 *     Verify that when an MBean is removed, the proxy
 *     throws an InstanceNotFoundException.  This test is included here because
 *     it otherwise causes problems when running other unit tests that want to operate
 *     on all MBeans--this test creates and removes one, which causes the other
 *     tests to fail.
 */
public void testProxyDetectsMBeanRemoved() throws InstanceNotFoundException {
    // use the NotificationServiceMgr as a convenient way of making
    // an MBean (a NotificationService) come and go.
    final NotificationServiceMgr mgr = getDomainRoot().getNotificationServiceMgr();
    final NotificationService ns = mgr.createNotificationService("UserData", 10);
    assert (ns.getUserData().equals("UserData"));
    final ObjectName nsObjectName = Util.getObjectName(ns);
    mgr.removeNotificationService(ns.getName());
    try {
        // all calls should fail
        Util.getObjectName(ns);
        ns.getName();
        ns.getUserData();
        failure("expecting exception due to missing MBean");
    } catch (Exception e) {
        // root cause should be an InstanceNotFoundException containing the ObjectName
        final Throwable t = ExceptionUtil.getRootCause(e);
        assert (t instanceof InstanceNotFoundException);
        final InstanceNotFoundException inf = (InstanceNotFoundException) t;
        final String msg = inf.getMessage();
        final int objectNameStart = msg.indexOf("amx:");
        final String objectNameString = msg.substring(objectNameStart, msg.length());
        final ObjectName on = Util.newObjectName(objectNameString);
        assert (on.equals(nsObjectName));
    }
}
Also used : NotificationServiceMgr(com.sun.appserv.management.base.NotificationServiceMgr) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotificationService(com.sun.appserv.management.base.NotificationService) IOException(java.io.IOException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectName(javax.management.ObjectName)

Example 4 with NotificationService

use of com.sun.appserv.management.base.NotificationService in project Payara by payara.

the class ProxyFactoryTest method testProxyFactoryDetectsMBeanRemoved.

/**
 *     Verify that when an MBean is removed, the ProxyFactory
 *     detects this, and removes any proxy from its cache.
 */
public void testProxyFactoryDetectsMBeanRemoved() throws InstanceNotFoundException {
    // use the NotificationServiceMgr as a convenient way of making
    // an MBean (a NotificationService) come and go.
    final NotificationServiceMgr mgr = getDomainRoot().getNotificationServiceMgr();
    final NotificationService ns = mgr.createNotificationService("UserData", 10);
    final ObjectName nsObjectName = Util.getObjectName(ns);
    assert (ns.getUserData().equals("UserData"));
    final ProxyFactory factory = getProxyFactory();
    final NotificationService proxy = factory.getProxy(nsObjectName, NotificationService.class, false);
    assert (proxy == ns) : "proxies differ: " + ns + "\n" + proxy;
    mgr.removeNotificationService(ns.getName());
    int iterations = 0;
    long sleepMillis = 10;
    while (factory.getProxy(nsObjectName, NotificationService.class, false) != null) {
        mySleep(sleepMillis);
        if (sleepMillis >= 400) {
            trace("testProxyFactoryDetectsMBeanRemoved: waiting for proxy to be removed");
        }
        sleepMillis *= 2;
    }
}
Also used : NotificationServiceMgr(com.sun.appserv.management.base.NotificationServiceMgr) ProxyFactory(com.sun.appserv.management.client.ProxyFactory) NotificationService(com.sun.appserv.management.base.NotificationService) ObjectName(javax.management.ObjectName)

Example 5 with NotificationService

use of com.sun.appserv.management.base.NotificationService in project Payara by payara.

the class NotificationServiceTest method testCreate.

public void testCreate() throws Exception {
    final NotificationService proxy = create();
    removeNotificationService(proxy);
}
Also used : NotificationService(com.sun.appserv.management.base.NotificationService)

Aggregations

NotificationService (com.sun.appserv.management.base.NotificationService)6 ObjectName (javax.management.ObjectName)4 NotificationServiceMgr (com.sun.appserv.management.base.NotificationServiceMgr)3 AttributeChangeNotification (javax.management.AttributeChangeNotification)2 Notification (javax.management.Notification)2 QueryMgr (com.sun.appserv.management.base.QueryMgr)1 ProxyFactory (com.sun.appserv.management.client.ProxyFactory)1 NotificationServiceHelper (com.sun.appserv.management.helper.NotificationServiceHelper)1 IOException (java.io.IOException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1