[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/passivation ...
Manik Surtani
manik at jboss.org
Thu Jun 28 12:53:36 EDT 2007
User: msurtani
Date: 07/06/28 12:53:36
Modified: tests/functional/org/jboss/cache/passivation
BasicPassivationTest.java
ReplicatedPassivationIntegrationTest.java
PassivationActivationCallbacksTestCase.java
LocalPassivationIntegrationTest.java
Log:
Notification changes
Revision Changes Path
1.19 +22 -25 JBossCache/tests/functional/org/jboss/cache/passivation/BasicPassivationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: BasicPassivationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/passivation/BasicPassivationTest.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- BasicPassivationTest.java 15 Jun 2007 12:54:09 -0000 1.18
+++ BasicPassivationTest.java 28 Jun 2007 16:53:35 -0000 1.19
@@ -10,20 +10,21 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.jboss.cache.AbstractCacheListener;
import org.jboss.cache.CacheImpl;
-import org.jboss.cache.CacheListener;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.misc.TestingUtil;
-
-import java.util.Map;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeActivated;
+import org.jboss.cache.notifications.annotation.NodePassivated;
+import org.jboss.cache.notifications.event.Event;
+import org.jboss.cache.notifications.event.NodeEvent;
/**
* @author Ben Wang
- * @version $Revision: 1.18 $
+ * @version $Revision: 1.19 $
*/
public class BasicPassivationTest extends TestCase
{
@@ -36,7 +37,6 @@
final String FQNSTR = "/org/jboss/3";
int activationCount = 0;
int passivationCount = 0;
- private static final int LISTENER_WAIT_TIME = 200; // needed since notifications are delivered asynchronously
public BasicPassivationTest(String s)
{
@@ -63,7 +63,7 @@
cache_ = (CacheImpl) DefaultCacheFactory.getInstance().createCache(false);
cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-passivation-service.xml"));// read in generic local xml
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
- CacheListener listener = new TestCacheListener();
+ Object listener = new TestCacheListener();
cache_.getConfiguration().getCacheLoaderConfig().getFirstCacheLoaderConfig().setClassName(DummyInMemoryCacheLoader.class.getName());
cache_.start();
cache_.getNotifier().addCacheListener(listener);
@@ -103,7 +103,6 @@
e.printStackTrace();
fail("Failed to get" + e);
}
- TestingUtil.sleepThread(LISTENER_WAIT_TIME);
assertEquals("activation count:", 1, activationCount);
assertEquals("passivation count:", 1, passivationCount);
}
@@ -143,23 +142,21 @@
junit.textui.TestRunner.run(org.jboss.cache.passivation.BasicPassivationTest.suite());
}
- public class TestCacheListener extends AbstractCacheListener
- {
- public void nodeActivated(Fqn fqn, boolean pre, Map<Object, Object> data)
+ @CacheListener
+ public class TestCacheListener
{
- if (pre) return;// we are not interested in postActivate event
- if (!fqn.isChildOrEquals(Fqn.fromString(FQNSTR))) return;// don't care about fqn that doesn't belong to me.
+ @NodeActivated
+ @NodePassivated
+ public void callback(NodeEvent ne)
+ {
+ if (ne.isPre()) return;// we are not interested in postActivate event
+ if (!ne.getFqn().isChildOrEquals(Fqn.fromString(FQNSTR)))
+ return;// don't care about fqn that doesn't belong to me.
- log("nodeActivate(): send postActivate event on fqn: " + fqn);
+ log("got event " + ne);
+ if (ne.getType() == Event.Type.NODE_ACTIVATED)
activationCount++;
- }
-
- public void nodePassivated(Fqn fqn, boolean pre, Map<Object, Object> data)
- {
- if (!pre) return;// we are not interested in postPassivate event
- if (!fqn.isChildOrEquals(Fqn.fromString(FQNSTR))) return;// don't care about fqn that doesn't belong to me.
-
- log("nodePassivate(): send prePassivate event on fqn: " + fqn);
+ else if (ne.getType() == Event.Type.NODE_PASSIVATED)
passivationCount++;
}
}
1.10 +18 -13 JBossCache/tests/functional/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ReplicatedPassivationIntegrationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/passivation/ReplicatedPassivationIntegrationTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- ReplicatedPassivationIntegrationTest.java 30 May 2007 11:35:14 -0000 1.9
+++ ReplicatedPassivationIntegrationTest.java 28 Jun 2007 16:53:35 -0000 1.10
@@ -25,15 +25,16 @@
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.AbstractCacheListener;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.misc.TestingUtil;
-
-import java.util.Map;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeActivated;
+import org.jboss.cache.notifications.annotation.NodeLoaded;
+import org.jboss.cache.notifications.annotation.NodePassivated;
+import org.jboss.cache.notifications.event.NodeEvent;
/**
* @author Ben Wang, Feb 11, 2004
@@ -115,7 +116,8 @@
System.out.println("-- " + msg);
}
- class PassivationListener extends AbstractCacheListener
+ @CacheListener
+ class PassivationListener
{
int counter = 0;
int loadedCounter = 0;
@@ -131,27 +133,30 @@
loadedCounter = 0;
}
- public void nodeActivated(Fqn fqn, boolean pre, Map<Object, Object> data)
+ @NodeActivated
+ public void nodeActivated(NodeEvent ne)
{
- if (!pre)
+ if (!ne.isPre())
{
counter++;
System.out.println("nodeActivate(): counter: " + counter);
- System.out.println("nodeActivate(): " + fqn);
+ System.out.println("nodeActivate(): " + ne.getFqn());
}
}
- public void nodePassivated(Fqn fqn, boolean pre, Map<Object, Object> data)
+ @NodePassivated
+ public void nodePassivated(NodeEvent ne)
{
- if (pre)
+ if (ne.isPre())
{
- System.out.println("nodePassivate(): " + fqn);
+ System.out.println("nodePassivate(): " + ne.getFqn());
}
}
- public void nodeLoaded(Fqn f, boolean pre, Map data)
+ @NodeLoaded
+ public void nodeLoaded(NodeEvent ne)
{
- if (!pre)
+ if (!ne.isPre())
{
loadedCounter++;
}
1.7 +24 -21 JBossCache/tests/functional/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PassivationActivationCallbacksTestCase.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/passivation/PassivationActivationCallbacksTestCase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- PassivationActivationCallbacksTestCase.java 30 May 2007 11:35:14 -0000 1.6
+++ PassivationActivationCallbacksTestCase.java 28 Jun 2007 16:53:35 -0000 1.7
@@ -9,7 +9,6 @@
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.AbstractCacheListener;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.CacheSPI;
@@ -24,11 +23,13 @@
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.misc.TestingUtil;
+import org.jboss.cache.notifications.annotation.NodeActivated;
+import org.jboss.cache.notifications.annotation.NodePassivated;
+import org.jboss.cache.notifications.event.NodeEvent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
/**
@@ -138,9 +139,10 @@
}
/**
- * Mimics the TreeCacheListener used by EJB3 SFSBs.
+ * Mimics the CacheListener used by EJB3 SFSBs.
*/
- private class CacheListener extends AbstractCacheListener
+ @org.jboss.cache.notifications.annotation.CacheListener
+ private class CacheListener
{
protected Log log = LogFactory.getLog(CacheListener.class);
@@ -149,23 +151,23 @@
protected Exception passivationException;
protected Exception activationException;
- @Override
- public void nodeActivated(Fqn fqn, boolean pre, Map<Object, Object> data)
+ @NodeActivated
+ public void nodeActivated(NodeEvent e)
{
- if (pre)
- return; // we are not interested in postActivate event
+ if (e.isPre())
+ return; // we are not interested in preActivate event
- if (!fqn.isChildOrEquals(BASE)) return; // don't care about fqn that doesn't belong to me.
+ if (!e.getFqn().isChildOrEquals(BASE)) return; // don't care about fqn that doesn't belong to me.
Object bean = null;
try
{
- bean = cache.get(fqn, "bean");
+ bean = cache.get(e.getFqn(), "bean");
}
- catch (CacheException e)
+ catch (CacheException ex)
{
- log.error("nodeActivate(): can't retrieve bean instance from: " + fqn + " with exception: " + e);
- activationException = e;
+ log.error("nodeActivate(): can't retrieve bean instance from: " + e.getFqn() + " with exception: " + ex);
+ activationException = ex;
return;
}
if (bean == null)
@@ -176,16 +178,17 @@
if (log.isTraceEnabled())
{
- log.trace("nodeActivate(): saw postActivate event on fqn: " + fqn);
+ log.trace("nodeActivate(): saw postActivate event on fqn: " + e.getFqn());
}
- activated.add(fqn);
+ activated.add(e.getFqn());
}
- @Override
- public void nodePassivated(Fqn fqn, boolean pre, Map<Object, Object> data)
+ @NodePassivated
+ public void nodePassivated(NodeEvent e)
{
- if (!pre) return; // we are not interested in postPassivate event
+ if (!e.isPre()) return; // we are not interested in postPassivate event
+ Fqn fqn = e.getFqn();
if (!fqn.isChildOrEquals(BASE)) return; // don't care about fqn that doesn't belong to me.
try
@@ -202,10 +205,10 @@
}
}
- catch (CacheException e)
+ catch (CacheException ex)
{
- log.error("nodePassivate(): can't retrieve bean instance from: " + fqn + " with exception: " + e);
- passivationException = e;
+ log.error("nodePassivate(): can't retrieve bean instance from: " + fqn + " with exception: " + ex);
+ passivationException = ex;
return;
}
1.19 +18 -12 JBossCache/tests/functional/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocalPassivationIntegrationTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/passivation/LocalPassivationIntegrationTest.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- LocalPassivationIntegrationTest.java 15 Jun 2007 12:54:09 -0000 1.18
+++ LocalPassivationIntegrationTest.java 28 Jun 2007 16:53:35 -0000 1.19
@@ -10,15 +10,17 @@
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.AbstractCacheListener;
import org.jboss.cache.CacheImpl;
import org.jboss.cache.DefaultCacheFactory;
-import org.jboss.cache.Fqn;
import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.loader.DummyInMemoryCacheLoader;
import org.jboss.cache.misc.TestingUtil;
-
-import java.util.Map;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeActivated;
+import org.jboss.cache.notifications.annotation.NodeLoaded;
+import org.jboss.cache.notifications.annotation.NodePassivated;
+import org.jboss.cache.notifications.event.Event;
+import org.jboss.cache.notifications.event.NodeEvent;
/**
* @author Ben Wang, Feb 11, 2004
@@ -94,7 +96,8 @@
System.out.println("-- " + msg);
}
- class PassivationListener extends AbstractCacheListener
+ @CacheListener
+ class PassivationListener
{
int counter = 0;
int loadedCounter = 0;
@@ -110,26 +113,29 @@
loadedCounter = 0;
}
- public void nodeActivated(Fqn fqn, boolean pre, Map<Object, Object> data)
+ @NodeActivated
+ public void nodeActivated(NodeEvent ne)
{
- if (!pre)
+ if (!ne.isPre())
{
counter++;
System.out.println("nodeActivate(): counter: " + counter);
}
}
- public void nodePassivated(Fqn fqn, boolean pre, Map<Object, Object> data)
+ @NodePassivated
+ public void nodePassivated(NodeEvent ne)
{
- if (pre)
+ if (ne.isPre())
{
- System.out.println("nodePassivate(): " + fqn);
+ System.out.println("nodePassivate(): " + ne.getFqn());
}
}
- public void nodeLoaded(Fqn f, boolean pre, Map data)
+ @NodeLoaded
+ public void nodeLoaded(Event e)
{
- if (!pre)
+ if (!e.isPre())
{
loadedCounter++;
}
More information about the jboss-cvs-commits
mailing list