[jbosscache-commits] JBoss Cache SVN: r7705 - in core/branches/flat/src/test/java/org/horizon: test and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Feb 17 11:27:54 EST 2009


Author: manik.surtani at jboss.com
Date: 2009-02-17 11:27:53 -0500 (Tue, 17 Feb 2009)
New Revision: 7705

Modified:
   core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java
   core/branches/flat/src/test/java/org/horizon/test/MultipleCacheManagersTest.java
Log:
Better test fwk

Modified: core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java	2009-02-17 16:04:23 UTC (rev 7704)
+++ core/branches/flat/src/test/java/org/horizon/loader/decorators/SingletonStoreTest.java	2009-02-17 16:27:53 UTC (rev 7705)
@@ -35,6 +35,9 @@
    private static final AtomicInteger storeCounter = new AtomicInteger(0);
    private CacheManager cm0, cm1, cm2;
 
+   public SingletonStoreTest() {
+      cleanup = CleanupPhase.AFTER_METHOD;
+   }
 
    protected void createCacheManagers() {
       cm0 = addClusterEnabledCacheManager();

Modified: core/branches/flat/src/test/java/org/horizon/test/MultipleCacheManagersTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/test/MultipleCacheManagersTest.java	2009-02-17 16:04:23 UTC (rev 7704)
+++ core/branches/flat/src/test/java/org/horizon/test/MultipleCacheManagersTest.java	2009-02-17 16:27:53 UTC (rev 7705)
@@ -6,6 +6,7 @@
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import java.util.ArrayList;
@@ -21,32 +22,51 @@
  *    3) next test method will run on same cacheManager instance. This way the test is much faster, as CacheManagers
  *       are expensive to create.
  * </pre>
+ * If, however, you would like your cache managers destroyed after every <i>test method</i> instead of the </i>test
+ * class</i>, you could set the <tt>cleanup</tt> field to {@link org.horizon.test.MultipleCacheManagersTest.CleanupPhase#AFTER_METHOD}
+ * in your test's constructor.  E.g.: <code> public void MyTest extends MultipleCacheManagersTest { public MyTest() {
+ * cleanup =  CleanupPhase.AFTER_METHOD; } } </code> Note that this will cuse {@link #createCacheManagers()}  to be
+ * called befpre each method.
  *
  * @author Mircea.Markus at jboss.com
  */
 @Test(groups = {"functional", "unit"})
 public abstract class MultipleCacheManagersTest extends AbstractCacheTest {
 
+   protected static enum CleanupPhase {
+      AFTER_METHOD, AFTER_TEST
+   }
+
    private List<CacheManager> cacheManagers = new ArrayList<CacheManager>();
    private IdentityHashMap<Cache, ReplListener> listeners = new IdentityHashMap<Cache, ReplListener>();
+   protected CleanupPhase cleanup = CleanupPhase.AFTER_TEST;
 
    @BeforeClass
-   public void create() throws Throwable {
-      createCacheManagers();
+   public void createBeforeClass() throws Throwable {
+      if (cleanup == CleanupPhase.AFTER_TEST) createCacheManagers();
    }
 
+   @BeforeMethod
+   public void createBeforeMethod() throws Throwable {
+      if (cleanup == CleanupPhase.AFTER_METHOD) createCacheManagers();
+   }
+
    @AfterClass
    protected void destroy() {
-      TestingUtil.killCacheManagers(cacheManagers);
+      if (cleanup == CleanupPhase.AFTER_TEST) TestingUtil.killCacheManagers(cacheManagers);
    }
 
    @AfterMethod
    protected void clearContent() throws Throwable {
-      fwkLogger.debug("*** Test method complete; clearing contents on all caches.");
-      if (cacheManagers.isEmpty())
-         throw new IllegalStateException("No caches registered! Use registerCacheManager(Cache... caches) do that!");
-      for (CacheManager cacheManager : cacheManagers) {
-         super.clearContent(cacheManager);
+      if (cleanup == CleanupPhase.AFTER_TEST) {
+         fwkLogger.debug("*** Test method complete; clearing contents on all caches.");
+         if (cacheManagers.isEmpty())
+            throw new IllegalStateException("No caches registered! Use registerCacheManager(Cache... caches) do that!");
+         for (CacheManager cacheManager : cacheManagers) {
+            super.clearContent(cacheManager);
+         }
+      } else {
+         TestingUtil.killCacheManagers(cacheManagers);
       }
    }
 




More information about the jbosscache-commits mailing list