Update of /cvsroot/mx4j/mx4j/src/test/test/mx4j/remote
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2203/test/test/mx4j/remote
Modified Files:
RemoteNotificationClientHandlerTest.java
Log Message:
Removed a test no useful anymore, and added start() - finally - stop() to the handlers created in the test methods
Index: RemoteNotificationClientHandlerTest.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/test/test/mx4j/remote/RemoteNotificationClientHandlerTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** RemoteNotificationClientHandlerTest.java 15 Feb 2004 21:51:59 -0000 1.5
--- RemoteNotificationClientHandlerTest.java 1 Mar 2004 18:24:16 -0000 1.6
***************
*** 10,26 ****
import java.io.IOException;
!
import javax.management.remote.NotificationResult;
import javax.management.remote.TargetedNotification;
- import javax.management.ObjectName;
- import javax.management.NotificationListener;
- import javax.management.Notification;
- import test.MX4JTestCase;
- import test.MutableObject;
- import test.MutableLong;
import mx4j.remote.AbstractRemoteNotificationClientHandler;
import mx4j.remote.NotificationTuple;
import mx4j.remote.RemoteNotificationClientHandler;
/**
--- 10,25 ----
import java.io.IOException;
! import javax.management.Notification;
! import javax.management.NotificationListener;
! import javax.management.ObjectName;
import javax.management.remote.NotificationResult;
import javax.management.remote.TargetedNotification;
import mx4j.remote.AbstractRemoteNotificationClientHandler;
import mx4j.remote.NotificationTuple;
import mx4j.remote.RemoteNotificationClientHandler;
+ import test.MX4JTestCase;
+ import test.MutableLong;
+ import test.MutableObject;
/**
***************
*** 35,38 ****
--- 34,42 ----
}
+ protected void tearDown() throws Exception
+ {
+ sleep(2000);
+ }
+
public void testListenerEquality() throws Exception
{
***************
*** 60,83 ****
};
! NotificationListener listener = new NotificationListener()
{
! public void handleNotification(Notification notification, Object handback)
{
! }
! };
! ObjectName name = ObjectName.getInstance(":name=emitter");
! handler.addNotificationListener(new Integer(1), new NotificationTuple(name, listener, null, null));
! handler.addNotificationListener(new Integer(2), new NotificationTuple(name, listener, null, new Object()));
! assertTrue(handler.isActive());
! Integer[] ids = handler.getNotificationListeners(new NotificationTuple(name, listener));
! assertEquals(ids.length, 2);
! handler.removeNotificationListeners(new Integer[] {new Integer(1), new Integer(2)});
! assertTrue(!handler.isActive());
! sleep(2000);
}
--- 64,97 ----
};
! try
{
! handler.start();
!
! NotificationListener listener = new NotificationListener()
{
! public void handleNotification(Notification notification, Object handback)
! {
! }
! };
! ObjectName name = ObjectName.getInstance(":name=emitter");
! handler.addNotificationListener(new Integer(1), new NotificationTuple(name, listener, null, null));
! handler.addNotificationListener(new Integer(2), new NotificationTuple(name, listener, null, new Object()));
! assertTrue(handler.isActive());
! Integer[] ids = handler.getNotificationListeners(new NotificationTuple(name, listener));
! assertEquals(ids.length, 2);
! handler.removeNotificationListeners(new Integer[]{new Integer(1), new Integer(2)});
! assertTrue(handler.isActive());
! handler.stop();
! assertTrue(!handler.isActive());
! }
! finally
! {
! handler.stop();
! }
}
***************
*** 114,131 ****
};
! ObjectName name = ObjectName.getInstance(":name=emitter");
! handler.addNotificationListener(new Integer(1), new NotificationTuple(name, listener, null, null));
! Object handback = new Object();
! handler.addNotificationListener(new Integer(2), new NotificationTuple(name, listener, null, handback));
! handler.removeNotificationListeners(new Integer[] {new Integer(2)});
! if (handler.contains(new NotificationTuple(name, listener, null, handback))) fail();
! if (!handler.contains(new NotificationTuple(name, listener, null, null))) fail();
! Integer id = handler.getNotificationListener(new NotificationTuple(name, listener, null, null));
! assertEquals(id.intValue(), 1);
! handler.removeNotificationListeners(new Integer[] {new Integer(1)});
! sleep(2000);
}
--- 128,154 ----
};
! try
! {
! handler.start();
! ObjectName name = ObjectName.getInstance(":name=emitter");
! handler.addNotificationListener(new Integer(1), new NotificationTuple(name, listener, null, null));
! Object handback = new Object();
! handler.addNotificationListener(new Integer(2), new NotificationTuple(name, listener, null, handback));
! handler.removeNotificationListeners(new Integer[]{new Integer(2)});
! assertFalse(handler.contains(new NotificationTuple(name, listener, null, handback)));
! assertTrue(handler.contains(new NotificationTuple(name, listener, null, null)));
! Integer id = handler.getNotificationListener(new NotificationTuple(name, listener, null, null));
! assertEquals(id.intValue(), 1);
!
! handler.removeNotificationListeners(new Integer[]{new Integer(1)});
! assertFalse(handler.contains(new NotificationTuple(name, listener, null, null)));
! }
! finally
! {
! handler.stop();
! }
}
***************
*** 144,148 ****
TargetedNotification targeted = new TargetedNotification(notification, new Integer(1));
// Return nextSequence as next sequence number: next call must have this sequence number
! NotificationResult result1 = new NotificationResult(1, nextSequence, new TargetedNotification[] {targeted});
if (sequenceNumber < 0)
{
--- 167,171 ----
TargetedNotification targeted = new TargetedNotification(notification, new Integer(1));
// Return nextSequence as next sequence number: next call must have this sequence number
! NotificationResult result1 = new NotificationResult(1, nextSequence, new TargetedNotification[]{targeted});
if (sequenceNumber < 0)
{
***************
*** 153,157 ****
if (sequenceNumber == nextSequence)
{
! NotificationResult result2 = new NotificationResult(1, nextSequence + 1, new TargetedNotification[] {targeted});
holder.set(result2);
return result2;
--- 176,180 ----
if (sequenceNumber == nextSequence)
{
! NotificationResult result2 = new NotificationResult(1, nextSequence + 1, new TargetedNotification[]{targeted});
holder.set(result2);
return result2;
***************
*** 195,221 ****
};
! handler.addNotificationListener(new Integer(1), new NotificationTuple(name, listener, null, null));
!
! synchronized (holder)
{
! // This wait time is much less than the sleep time for the fetcher thread
! while (holder.get() == null) holder.wait(10);
! NotificationResult result = (NotificationResult)holder.get();
! assertEquals(result.getNextSequenceNumber(), nextSequence);
! holder.set(null);
! // Wait for the notification to arrive
! while (notifHolder.get() == null) holder.wait(10);
! Notification notif = (Notification)notifHolder.get();
! assertEquals(notif.getSource(), name);
! // Wait for the second fetchNotification call
! while (holder.get() == null) holder.wait(10);
! result = (NotificationResult)holder.get();
! assertEquals(result.getNextSequenceNumber(), nextSequence + 1);
! }
! handler.removeNotificationListeners(new Integer[] {new Integer(1)});
! sleep(2000);
}
--- 218,253 ----
};
! try
{
! handler.start();
! handler.addNotificationListener(new Integer(1), new NotificationTuple(name, listener, null, null));
! synchronized (holder)
! {
! // This wait time is much less than the sleep time for the fetcher thread
! while (holder.get() == null) holder.wait(10);
! NotificationResult result = (NotificationResult)holder.get();
! assertEquals(result.getNextSequenceNumber(), nextSequence);
! holder.set(null);
! // Wait for the notification to arrive
! while (notifHolder.get() == null) holder.wait(10);
! Notification notif = (Notification)notifHolder.get();
! assertEquals(notif.getSource(), name);
!
! // Wait for the second fetchNotification call
! while (holder.get() == null) holder.wait(10);
! result = (NotificationResult)holder.get();
! assertEquals(result.getNextSequenceNumber(), nextSequence + 1);
! }
!
! handler.removeNotificationListeners(new Integer[]{new Integer(1)});
! sleep(2000);
! }
! finally
! {
! handler.stop();
! }
}
***************
*** 234,237 ****
--- 266,272 ----
if (sequenceNumber < 0) return new NotificationResult(0, 0, new TargetedNotification[0]);
+ // Avoid to spin loop the fetcher thread
+ sleep(1000);
+
// Return a earliest sequence greater than the requested, to test notification lost behavior
return new NotificationResult(losts, losts, new TargetedNotification[0]);
***************
*** 265,342 ****
}
};
- handler.addNotificationListener(id, new NotificationTuple(name, listener, null, null));
-
- synchronized (holder)
- {
- while (lost.get() == 0) holder.wait(10);
- assertEquals(lost.get(), losts);
- }
-
- handler.removeNotificationListeners(new Integer[] {id});
- sleep(2000);
- }
! public void testAddRemoveAdd() throws Exception
! {
! final MutableLong holder = new MutableLong(0);
! RemoteNotificationClientHandler handler = new AbstractRemoteNotificationClientHandler(null, null, null)
{
! public NotificationResult fetchNotifications(long sequenceNumber, int maxNumber, long timeout) throws IOException
! {
! synchronized (holder)
! {
! if (sequenceNumber < 0) holder.set(sequenceNumber);
! }
!
! sleep(timeout);
!
! return new NotificationResult(0, 0, new TargetedNotification[0]);
! }
!
! protected void sendConnectionNotificationLost(long number)
! {
! }
!
! protected int getMaxRetries()
! {
! return 2;
! }
! protected long getRetryPeriod()
! {
! return 1000;
! }
! };
! NotificationListener listener = new NotificationListener()
! {
! public void handleNotification(Notification notification, Object handback)
{
}
- };
! ObjectName name = ObjectName.getInstance(":name=emitter");
! Integer id = new Integer(1);
! handler.addNotificationListener(id, new NotificationTuple(name, listener, null, null));
!
! synchronized (holder)
! {
! while (holder.get() != -1) holder.wait(10);
! holder.set(0);
}
! sleep(2000);
!
! handler.removeNotificationListeners(new Integer[] {id});
! sleep(2000);
!
! handler.addNotificationListener(id, new NotificationTuple(name, listener, null, null));
! synchronized (holder)
{
! while (holder.get() != -1) holder.wait(10);
! holder.set(0);
}
-
- handler.removeNotificationListeners(new Integer[] {id});
- sleep(2000);
}
--- 300,322 ----
}
};
! try
{
! handler.start();
! handler.addNotificationListener(id, new NotificationTuple(name, listener, null, null));
! synchronized (holder)
{
+ while (lost.get() == 0) holder.wait(10);
+ assertEquals(lost.get(), losts);
}
! handler.removeNotificationListeners(new Integer[]{id});
}
! finally
{
! handler.stop();
}
}
***************
*** 374,384 ****
};
! ObjectName name = ObjectName.getInstance(":name=emitter");
! Integer id = new Integer(1);
! handler.addNotificationListener(id, new NotificationTuple(name, listener, null, null));
! sleep(5000 + period * retries);
! assertTrue(!handler.isActive());
}
}
--- 354,373 ----
};
! try
! {
! handler.start();
! ObjectName name = ObjectName.getInstance(":name=emitter");
! Integer id = new Integer(1);
! handler.addNotificationListener(id, new NotificationTuple(name, listener, null, null));
! sleep(5000 + period * retries);
!
! assertTrue(!handler.isActive());
! }
! finally
! {
! handler.stop();
! }
}
}
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.