[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/jmx ...
Brian Stansberry
brian.stansberry at jboss.com
Thu May 10 13:30:52 EDT 2007
User: bstansberry
Date: 07/05/10 13:30:52
Modified: tests/functional/org/jboss/cache/jmx NotificationTest.java
Log:
[JBCACHE-855] Inform CacheListener of our ObjectName
Revision Changes Path
1.2 +148 -107 JBossCache/tests/functional/org/jboss/cache/jmx/NotificationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NotificationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/jmx/NotificationTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- NotificationTest.java 10 May 2007 04:00:24 -0000 1.1
+++ NotificationTest.java 10 May 2007 17:30:52 -0000 1.2
@@ -9,6 +9,7 @@
import javax.management.NotificationListener;
import javax.management.ObjectName;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.jboss.cache.CacheImpl;
@@ -27,7 +28,7 @@
* Functional tests for CacheJmxWrapper broadcast of cache event notifications
*
* @author Jerry Gauthier
- * @version $Id: NotificationTest.java,v 1.1 2007/05/10 04:00:24 bstansberry Exp $
+ * @version $Id: NotificationTest.java,v 1.2 2007/05/10 17:30:52 bstansberry Exp $
*/
public class NotificationTest extends TestCase
{
@@ -110,9 +111,10 @@
assertNotNull("MBeanServer is null.", m_server);
assertNotNull("Cache is null.", cache);
- MyListener listener = new MyListener();
-
ObjectName mgmt = getWrapperObjectName();
+ MyListener listener = new MyListener(mgmt);
+
+
m_server.addNotificationListener(mgmt, listener, null, null);
// start the cache after registering listener - this will trigger CacheStarted
@@ -169,6 +171,7 @@
assertTrue("Expected NodeRemoved notification", events.contains(Type.PREREMOVE));
assertTrue("Expected NodeRemoved notification", events.contains(Type.POSTREMOVE));
assertTrue("Expected ViewChange notification", events.contains(Type.VIEWCHANGE));
+ validateHealthyListener(listener);
}
public void testEarlyRegistration() throws Exception
@@ -179,7 +182,7 @@
CacheJmxWrapper wrapper = new CacheJmxWrapper();
ObjectName mgmt = getWrapperObjectName();
m_server.registerMBean(wrapper, mgmt);
- MyListener listener = new MyListener();
+ MyListener listener = new MyListener(mgmt);
m_server.addNotificationListener(mgmt, listener, null, null);
cache = createCache(CLUSTER_NAME);
@@ -188,6 +191,7 @@
try
{
assertTrue("Expected CacheStarted notification", events.contains(Type.STARTED));
+ validateHealthyListener(listener);
}
finally
{
@@ -205,9 +209,10 @@
try
{
- MyListener listener = new MyListener();
-
ObjectName mgmt = getWrapperObjectName();
+ MyListener listener = new MyListener(mgmt);
+
+
m_server.addNotificationListener(mgmt, listener, null, null);
// add a node - this will trigger NodeCreated, NodeModify(pre/post) and NodeModified
@@ -219,6 +224,7 @@
// run the tests
assertTrue("Expected NodeModified notification", events.contains(Type.PREMODIFY));
assertTrue("Expected NodeModified notification", events.contains(Type.POSTMODIFY));
+ validateHealthyListener(listener);
}
finally
{
@@ -231,9 +237,9 @@
assertNotNull("MBeanServer is null.", m_server);
assertNotNull("Cache is null.", cache);
- MyListener listener = new MyListener();
-
ObjectName mgmt = getWrapperObjectName();
+ MyListener listener = new MyListener(mgmt);
+
m_server.addNotificationListener(mgmt, listener, null, null);
// start the cache after registering listener - this will trigger CacheStarted
@@ -251,7 +257,10 @@
{
cache.stop();
if (ok)
+ {
assertFalse("Expected no CacheStopped notification", events.contains(Type.STOPPED));
+ validateHealthyListener(listener);
+ }
}
}
@@ -279,7 +288,7 @@
return System.getProperty("java.io.tempdir", "/tmp");
}
- private boolean getPre(Object data)
+ private static boolean getPre(Object data)
{
assertNotNull("User data is null, should be Object[]", data);
assertTrue("User data is " + data.getClass().getName() + ", should be Object[]", data instanceof Object[]);
@@ -289,7 +298,7 @@
return (Boolean) parms[1];
}
- private CacheLoaderConfig getCacheLoaderConfig(String properties) throws Exception
+ private static CacheLoaderConfig getCacheLoaderConfig(String properties) throws Exception
{
String xml = "<config>\n" +
"<passivation>true</passivation>\n" +
@@ -307,20 +316,41 @@
return XmlConfigurationParser.parseCacheLoaderConfig(element);
}
+ private static void validateHealthyListener(MyListener listener)
+ {
+ if (listener.failure != null)
+ throw listener.failure;
+ if (listener.exception != null)
+ throw listener.exception;
+ }
+
private class MyListener implements NotificationListener
{
+ private RuntimeException exception;
+ private AssertionFailedError failure;
+ private final String emitterObjectName;
+
+ MyListener(ObjectName emitter)
+ {
+ this.emitterObjectName = emitter.getCanonicalName();
+ }
+
public void handleNotification(Notification notification, Object handback)
{
+ try
+ {
String type = notification.getType();
Object userData = notification.getUserData();
if (type.equals(CacheNotificationBroadcaster.NOTIF_CACHE_STARTED))
{
events.add(Type.STARTED);
+ assertEquals("Correct object name in start notification", emitterObjectName, userData);
}
else if (type.equals(CacheNotificationBroadcaster.NOTIF_CACHE_STOPPED))
{
events.add(Type.STOPPED);
+ assertEquals("Correct object name in stop notification", emitterObjectName, userData);
}
else if (type.equals(CacheNotificationBroadcaster.NOTIF_NODE_CREATED))
{
@@ -415,6 +445,17 @@
}
}
}
+ catch (RuntimeException e)
+ {
+ // Store so the test can rethrow
+ exception = e;
+ }
+ catch (AssertionFailedError e)
+ {
+ // Store so the test can rethrow
+ failure = e;
+ }
+ }
}
}
More information about the jboss-cvs-commits
mailing list