[jboss-cvs] JBossAS SVN: r59796 - in trunk/testsuite/src/main/org/jboss/test/cluster: test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jan 18 16:18:43 EST 2007
Author: jerrygauth
Date: 2007-01-18 16:18:43 -0500 (Thu, 18 Jan 2007)
New Revision: 59796
Modified:
trunk/testsuite/src/main/org/jboss/test/cluster/ds/DistributedStateUser.java
trunk/testsuite/src/main/org/jboss/test/cluster/test/DistributedStateTestCase.java
Log:
Added notifications test to DistributedState test case
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/ds/DistributedStateUser.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/ds/DistributedStateUser.java 2007-01-18 21:12:45 UTC (rev 59795)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/ds/DistributedStateUser.java 2007-01-18 21:18:43 UTC (rev 59796)
@@ -41,6 +41,9 @@
public class DistributedStateUser extends JBossNotificationBroadcasterSupport
implements IDistributedState, DSListenerEx
{
+ public static final String NOTIFY_CHANGE = "valueHasChanged";
+ public static final String NOTIFY_REMOVAL = "keyHasBeenRemoved";
+
protected static Logger log = Logger.getLogger(DistributedStateUser.class);
protected DistributedState entryMap;
@@ -182,7 +185,7 @@
data.locallyModified = locallyModified;
String address = System.getProperty("jboss.bind.address");
long id = nextSequence();
- Notification msg = new Notification("valueHasChanged", this, id, address);
+ Notification msg = new Notification(NOTIFY_CHANGE, this, id, address);
msg.setUserData(data);
log.debug("valueHasChanged, "+msg);
super.sendNotification(msg);
@@ -198,7 +201,7 @@
data.locallyModified = locallyModified;
String address = System.getProperty("jboss.bind.address");
long id = nextSequence();
- Notification msg = new Notification("keyHasBeenRemoved", this, id, address);
+ Notification msg = new Notification(NOTIFY_REMOVAL, this, id, address);
msg.setUserData(data);
log.debug("keyHasBeenRemoved, "+msg);
super.sendNotification(msg);
Modified: trunk/testsuite/src/main/org/jboss/test/cluster/test/DistributedStateTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/test/DistributedStateTestCase.java 2007-01-18 21:12:45 UTC (rev 59795)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/test/DistributedStateTestCase.java 2007-01-18 21:18:43 UTC (rev 59796)
@@ -32,7 +32,9 @@
import junit.framework.Test;
import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.ds.DistributedStateUser;
import org.jboss.test.cluster.ds.IDistributedState;
+import org.jboss.test.cluster.ds.IDistributedState.NotifyData;
import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
import org.jboss.jmx.adaptor.rmi.RMIAdaptorExt;
import org.jboss.jmx.adaptor.rmi.RMINotificationListener;
@@ -44,17 +46,38 @@
*/
public class DistributedStateTestCase extends JBossClusteredTestCase
{
- static class TestListener extends UnicastRemoteObject
+ private static final String NOTIFY_KEY = "NotifyKey";
+ private static final String NOTIFY_VALUE = "NotifyValue";
+ // note - this static variable must match the category defined in ds-tests.sar
+ private static final String NOTIFY_CATEGORY = "DistributedStateTestCase";
+
+ class TestListener extends UnicastRemoteObject
implements RMINotificationListener
{
+ private String type = null;
+ private Object data = null;
+
TestListener() throws RemoteException
{
}
+
public void handleNotification(Notification notification, Object handback)
throws RemoteException
{
System.out.println(notification);
+ type = notification.getType();
+ data = notification.getUserData();
}
+
+ public String getNotificationType()
+ {
+ return type;
+ }
+
+ public Object getNotificationData()
+ {
+ return data;
+ }
}
public static Test suite() throws Exception
@@ -83,8 +106,8 @@
IDistributedState ds0 = (IDistributedState)
MBeanServerInvocationHandler.newProxyInstance(server0, dsService,
IDistributedState.class, true);
- TestListener listener = new TestListener();
- server0.addNotificationListener(dsService, listener, null, null);
+ TestListener listener0 = new TestListener();
+ server0.addNotificationListener(dsService, listener0, null, null);
ds0.put("key0", "value0");
String value = (String) ds0.get("key0");
log.info("server0: get(key0): "+value);
@@ -97,7 +120,8 @@
IDistributedState ds1 = (IDistributedState)
MBeanServerInvocationHandler.newProxyInstance(server1, dsService,
IDistributedState.class, true);
- server1.addNotificationListener(dsService, listener, null, null);
+ TestListener listener1 = new TestListener();
+ server1.addNotificationListener(dsService, listener1, null, null);
value = (String) ds1.get("key0");
log.info("server1: get(key0): "+value);
assertTrue("server1: value == value0", value.equals("value0"));
@@ -128,6 +152,71 @@
assertTrue("server1: value == null("+value+")", value == null);
value = (String) ds0.get("key0");
assertTrue("server0: value == null("+value+")", value == null);
+
+ // set a key/value on server0 and test its notifications on both servers
+ ds0.put(NOTIFY_KEY, NOTIFY_VALUE);
+ Thread.sleep(5000);
+
+ // check the change notification on server0
+ String type = listener0.getNotificationType();
+ NotifyData data = (NotifyData)listener0.getNotificationData();
+ assertTrue("server0: change notification type = " + type, type.equals(DistributedStateUser.NOTIFY_CHANGE));
+ assertNotNull("server0: change notification data is null", data);
+ String cat = data.category;
+ String key = (String)data.key;
+ String val = (String)data.value;
+ boolean isLocal = data.locallyModified;
+ assertTrue("server0: change notification category = " + cat, cat.equals(NOTIFY_CATEGORY));
+ assertTrue("server0: change notification key = " + key, key.equals(NOTIFY_KEY));
+ assertTrue("server0: change notification value = " + val, val.equals(NOTIFY_VALUE));
+ assertTrue("server0: change notification isLocal = " + isLocal, isLocal == true);
+
+ // check the change notification on server1
+ type = listener1.getNotificationType();
+ data = (NotifyData)listener1.getNotificationData();
+ assertTrue("server1: change notification type = " + type, type.equals(DistributedStateUser.NOTIFY_CHANGE));
+ assertNotNull("server1: change notification data is null", data);
+ cat = data.category;
+ key = (String)data.key;
+ val = (String)data.value;
+ isLocal = data.locallyModified;
+ assertTrue("server1: change notification category = " + cat, cat.equals(NOTIFY_CATEGORY));
+ assertTrue("server1: change notification key = " + key, key.equals(NOTIFY_KEY));
+ assertTrue("server1: change notification value = " + val, val.equals(NOTIFY_VALUE));
+ assertTrue("server1: change notification isLocal = " + isLocal, isLocal == false);
+
+ // remove the key from server1 and check its notifications
+ ds1.remove(NOTIFY_KEY);
+ Thread.sleep(5000);
+
+ // check the remove notification on server0
+ type = listener0.getNotificationType();
+ data = (NotifyData)listener0.getNotificationData();
+ assertTrue("server0: removal notification type = " + type, type.equals(DistributedStateUser.NOTIFY_REMOVAL));
+ assertNotNull("server0: removal notification data is null", data);
+ cat = data.category;
+ key = (String)data.key;
+ val = (String)data.value;
+ isLocal = data.locallyModified;
+ assertTrue("server0: removal notification category = " + cat, cat.equals(NOTIFY_CATEGORY));
+ assertTrue("server0: removal notification key = " + key, key.equals(NOTIFY_KEY));
+ assertTrue("server01: removal notification value = " + val, val.equals(NOTIFY_VALUE));
+ assertTrue("server0: removal notification isLocal = " + isLocal, isLocal == false);
+
+ // check the remove notification on server1
+ type = listener1.getNotificationType();
+ data = (NotifyData)listener1.getNotificationData();
+ assertTrue("server1: removal notification type = " + type, type.equals(DistributedStateUser.NOTIFY_REMOVAL));
+ assertNotNull("server1: removal notification data is null", data);
+ cat = data.category;
+ key = (String)data.key;
+ val = (String)data.value;
+ isLocal = data.locallyModified;
+ assertTrue("server1: removal notification category = " + cat, cat.equals(NOTIFY_CATEGORY));
+ assertTrue("server1: removal notification key = " + key, key.equals(NOTIFY_KEY));
+ assertTrue("server1: removal notification value = " + val, val.equals(NOTIFY_VALUE));
+ assertTrue("server1: removal notification isLocal = " + isLocal, isLocal == true);
+
}
}
More information about the jboss-cvs-commits
mailing list