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

NotificationEmitterServiceTest

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

Fields Summary
private static final String
TEST_SOURCE
private static final String
TEST_MESSAGE
private static final String
TEST_KEY
private static final String
TEST_VALUE
Constructors Summary
public NotificationEmitterServiceTest()

	
Methods Summary
public static com.sun.enterprise.management.CapabilitiesgetCapabilities()

	    return getOfflineCapableCapabilities( true );
	
public com.sun.appserv.management.base.NotificationEmitterServicegetNotificationEmitterService()

		return getDomainRoot().getDomainNotificationEmitterService();
	
public voidtestEmit()

	
		 
	
	
		final NotificationEmitterService	nes	= getNotificationEmitterService();
		
		final NotificationBuilder	builder	=
			new NotificationBuilder( testEmitListener.TEST_TYPE, TEST_SOURCE );
		
		final testEmitListener	listener	= new testEmitListener();
		nes.addNotificationListener( listener, null, null);
		final Notification	notif	= builder.buildNew( TEST_MESSAGE);
		builder.putMapData( notif, TEST_KEY, TEST_VALUE );
		
		// call emitNotification() and verify it was emitted
		nes.emitNotification( notif );
		while( listener.getLast() == null )
		{
			// wait...
			mySleep( 20 );
		}
		final Notification	retrieved	= listener.getLast();
		assert( retrieved.getType().equals( notif.getType() ) );
		assert( Util.getAMXNotificationValue( retrieved, TEST_KEY, String.class).equals( TEST_VALUE ) );
		assert( retrieved.getSource().equals( TEST_SOURCE ) );
		assert( retrieved.getMessage().equals( TEST_MESSAGE ) );
		
		// now emit many Notifications.
		listener.clear();
		long	start	= now();
		final int	ITER	= 200;
		for( int i = 0; i < ITER; ++i)
		{
			final Notification	temp	= builder.buildNew( TEST_MESSAGE);
		    builder.putMapData( notif, TEST_KEY, TEST_VALUE );
			nes.emitNotification( temp );
		}
		printElapsedIter( "Emitted Notifications", start, ITER );
		start	= now();
		while( listener.getNumHeard() < ITER )
		{
			mySleep( 10 );
		}
		printElapsedIter( "After sending, received emitted Notifications", start, ITER );
	
public voidtestGet()

		assert getNotificationEmitterService() != null;