FileDocCategorySizeDatePackage
NotificationServiceTest.javaAPI DocGlassfish v2 API6224Fri May 04 22:23:54 BST 2007com.sun.enterprise.management.base

NotificationServiceTest

public final class NotificationServiceTest extends com.sun.enterprise.management.AMXTestBase

Fields Summary
Constructors Summary
public NotificationServiceTest()

	
Methods Summary
public com.sun.appserv.management.base.NotificationServicecreate()

		final NotificationServiceMgr	proxy	= getNotificationServiceMgr();
		
		return( proxy.createNotificationService( "test", 512 ) );
	
public static com.sun.enterprise.management.CapabilitiesgetCapabilities()

	    return getOfflineCapableCapabilities( true );
	
private voidremoveNotificationService(com.sun.appserv.management.base.NotificationService service)

		getNotificationServiceMgr().removeNotificationService( service.getName() );
	
private static voidsleep(int duration)

		try
		{
			Thread.sleep( duration );
		}
		catch( InterruptedException e )
		{
		}
	
public voidtestCreate()

		final NotificationService	proxy	= create();
		
		removeNotificationService( proxy );
	
public voidtestGetFromEmpty()

		final NotificationService	proxy	= create();
		
		assert( proxy.getListeneeSet().size() == 0 );
		final Object	id	= proxy.createBuffer( 10, null);
		final Map<String,Object>	result	= proxy.getBufferNotifications( id, 0 );
		final Notification[]	notifs	= (Notification[])result.get( proxy.NOTIFICATIONS_KEY );
		assertEquals( 0, notifs.length );
	
public voidtestListen()

		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 ) );
		
		final MyListener	myListener	= new MyListener();
		proxy.addNotificationListener( myListener, null, null );
		 
		final Level	saveLevel = queryMgr.getMBeanLogLevel();
		queryMgr.setMBeanLogLevel( Level.INFO );
		queryMgr.setMBeanLogLevel( saveLevel );
		
		// delivery may be asynchronous; wait until done
		while ( myListener.getCount() < 2 )
		{
			sleep( 20 );
		}
		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 );