[jboss-cvs] JBossCache/tests/functional/org/jboss/cache ...
Manik Surtani
manik at jboss.org
Tue Jul 17 10:17:27 EDT 2007
User: msurtani
Date: 07/07/17 10:17:27
Modified: tests/functional/org/jboss/cache LifeCycleTest.java
Log:
Back to using listeners to generate startup/shutdown disruptions.
Revision Changes Path
1.13 +37 -41 JBossCache/tests/functional/org/jboss/cache/LifeCycleTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LifeCycleTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/LifeCycleTest.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- LifeCycleTest.java 15 Jun 2007 12:02:58 -0000 1.12
+++ LifeCycleTest.java 17 Jul 2007 14:17:27 -0000 1.13
@@ -5,24 +5,22 @@
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.loader.CacheLoader;
-import org.jboss.cache.loader.FileCacheLoader;
-import org.jboss.cache.loader.FileCacheLoaderConfig;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.CacheStarted;
+import org.jboss.cache.notifications.annotation.CacheStopped;
+import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.transaction.DummyTransactionManager;
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
-import java.util.ArrayList;
-import java.util.List;
/**
* Tests restart (stop-destroy-create-start) of CacheImpl
*
* @author Bela Ban
- * @version $Id: LifeCycleTest.java,v 1.12 2007/06/15 12:02:58 msurtani Exp $
+ * @version $Id: LifeCycleTest.java,v 1.13 2007/07/17 14:17:27 msurtani Exp $
*/
public class LifeCycleTest extends TestCase
{
@@ -134,48 +132,22 @@
public void testFailedStart() throws Exception
{
- // since listener notifications are now delivered asynchronously via a thread pool, exceptions in cacheStarted()
- // will not cause the startup to fail. Instead I've changed the test to use a mock cache loader which
- // will barf.
CacheImpl cache = createCache(Configuration.CacheMode.LOCAL);
assertEquals("Correct state", CacheStatus.INSTANTIATED, cache.getCacheStatus());
-// DisruptLifecycleListener listener = new DisruptLifecycleListener();
-// cache.addCacheListener(listener);
+ DisruptLifecycleListener listener = new DisruptLifecycleListener();
+ cache.addCacheListener(listener);
- List<CacheLoaderConfig.IndividualCacheLoaderConfig> list = new ArrayList<CacheLoaderConfig.IndividualCacheLoaderConfig>(1);
- list.add(new FileCacheLoaderConfig());
- CacheLoaderConfig clc = new CacheLoaderConfig();
- clc.setIndividualCacheLoaderConfigs(list);
- cache.getConfiguration().setCacheLoaderConfig(clc);
cache.create();
- assertNotNull(cache.getCacheLoaderManager());
-
- // now inject the cache loader with a mock cache loader
- CacheLoader normalCacheLoader = cache.getCacheLoaderManager().getCacheLoader();
- CacheLoader barfingCacheLoader = new FileCacheLoader()
- {
- public void start()
- {
- throw new CacheException("Prevent startup");
- }
-
- public void stop()
- {
- throw new CacheException("Prevent stop");
- }
- };
-
- cache.getCacheLoaderManager().setCacheLoader(barfingCacheLoader);
-
+ listener.disrupt = true;
assertEquals("Correct state", CacheStatus.CREATED, cache.getCacheStatus());
try
{
cache.start();
- fail("Barfing cache loader did not prevent start");
+ fail("Listener did not prevent start");
}
catch (CacheException good)
{
@@ -183,7 +155,8 @@
assertEquals("Correct state", CacheStatus.FAILED, cache.getCacheStatus());
- cache.getCacheLoaderManager().setCacheLoader(normalCacheLoader);
+ cache.addCacheListener(listener);
+ listener.disrupt = false;
cache.start();
@@ -193,12 +166,13 @@
assertTrue(cache.getNumberOfNodes() > 0);
assertEquals(0, cache.getNumberOfLocksHeld());
- cache.getCacheLoaderManager().setCacheLoader(barfingCacheLoader);
+ listener.disrupt = true;
+ cache.addCacheListener(listener);
try
{
cache.stop();
- fail("Barfing cache loader did not prevent stop");
+ fail("Listener did not prevent stop");
}
catch (CacheException good)
{
@@ -206,7 +180,7 @@
assertEquals("Correct state", CacheStatus.FAILED, cache.getCacheStatus());
- cache.getCacheLoaderManager().setCacheLoader(normalCacheLoader);
+ listener.disrupt = false;
cache.stop();
assertEquals("Correct state", CacheStatus.STOPPED, cache.getCacheStatus());
@@ -260,4 +234,26 @@
junit.textui.TestRunner.run(suite());
}
+ @CacheListener
+ public class DisruptLifecycleListener
+ {
+ private boolean disrupt;
+
+ @CacheStarted
+ public void cacheStarted(Event e)
+ {
+ if (disrupt) throw new IllegalStateException("I don't want to start");
+ }
+
+ @CacheStopped
+ public void cacheStopped(Event e)
+ {
+ if (disrupt) throw new IllegalStateException("I don't want to stop");
+ }
+
+ public void setDisrupt(boolean disrupt)
+ {
+ this.disrupt = disrupt;
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list