[jbosscache-commits] JBoss Cache SVN: r6980 - in core/branches/flat: src/main/java/org/jboss/starobrno/loader and 11 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Oct 17 13:17:17 EDT 2008


Author: dpospisi at redhat.com
Date: 2008-10-17 13:17:17 -0400 (Fri, 17 Oct 2008)
New Revision: 6980

Added:
   core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java
   core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheManager.java
   core/branches/flat/src/test/java/org/jboss/starobrno/util/UnitTestTestNGListener.java
Modified:
   core/branches/flat/pom.xml
   core/branches/flat/src/main/java/org/jboss/starobrno/loader/FileCacheLoaderConfig.java
   core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
   core/branches/flat/src/test/java/org/jboss/starobrno/api/CacheAPITest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/api/CacheSPITest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/api/batch/BatchWithTM.java
   core/branches/flat/src/test/java/org/jboss/starobrno/api/batch/BatchWithoutTM.java
   core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/LockTestBase.java
   core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/repeatable_read/RepeatableReadLockTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/repeatable_read/WriteSkewTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/notifications/AsyncNotificationTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/notifications/CacheListenerTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/notifications/ConcurrentNotificationTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifierAnnotationsTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifierTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifyNodeInvalidatedTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/profiling/AbstractProfileTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/profiling/MemConsumptionTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/profiling/ProfileTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/replication/AsyncReplTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/replication/ExceptionTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/replication/ReplicationExceptionTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/replication/SyncCacheListenerTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/replication/SyncReplTest.java
   core/branches/flat/src/test/java/org/jboss/starobrno/tx/LocalModeTxTest.java
Log:
Updated testsuite to run in parallel mode.

Modified: core/branches/flat/pom.xml
===================================================================
--- core/branches/flat/pom.xml	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/pom.xml	2008-10-17 17:17:17 UTC (rev 6980)
@@ -113,10 +113,36 @@
          <version>2.3</version>
          <scope>test</scope>
       </dependency>
+      <!-- 5.8 is needed for propper parallel test execution -->
+      <dependency>
+         <groupId>org.testng</groupId>
+         <artifactId>testng</artifactId>
+         <version>5.8</version>
+         <scope>test</scope>
+         <classifier>jdk15</classifier>
+      </dependency>      
    </dependencies>
    <build>
       <plugins>
+         <!-- ensure parallel test execution -->
          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>            
+            <artifactId>maven-surefire-plugin</artifactId>            
+            <version>2.4.3-JBOSS</version>
+            <configuration>                
+               <parallel>methods</parallel>
+               <threadCount>10</threadCount>
+               <forkMode>none</forkMode>
+               	<trimStackTrace>false</trimStackTrace>
+	       <properties>
+                 <property>	
+                   <name>listener</name>
+                   <value>org.jboss.starobrno.util.UnitTestTestNGListener</value>
+                 </property>
+               </properties>
+            </configuration>
+         </plugin>                              
+         <plugin>
             <artifactId>maven-assembly-plugin</artifactId>
             <version>2.2-beta-1</version>
             <executions>
@@ -349,6 +375,16 @@
                </plugin>
             </plugins>
          </build>
+       <reporting>
+          <plugins>
+             <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-report-plugin</artifactId>
+                <version>2.4.3-JBOSS</version>
+             </plugin>
+          </plugins>
+       </reporting>
+         
       </profile>
 
       <profile>
@@ -396,7 +432,6 @@
       <profile>
          <id>JBossAS</id>
          <activation>
-            <activeByDefault>false</activeByDefault>
          </activation>
          <properties>
             <jbosscache-core-version>3.0.0-SNAPSHOT-JBossAS</jbosscache-core-version>

Modified: core/branches/flat/src/main/java/org/jboss/starobrno/loader/FileCacheLoaderConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/loader/FileCacheLoaderConfig.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/loader/FileCacheLoaderConfig.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -21,11 +21,11 @@
  */
 package org.jboss.starobrno.loader;
 
-import org.jboss.cache.util.Util;
 import org.jboss.starobrno.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
 import org.jboss.starobrno.config.Dynamic;
 
 import java.util.Properties;
+import org.jboss.starobrno.util.Util;
 
 public class FileCacheLoaderConfig extends IndividualCacheLoaderConfig
 {

Modified: core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/manager/CacheManager.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -37,7 +37,7 @@
  */
 public class CacheManager implements Lifecycle
 {
-   Configuration c;
+   protected Configuration c;
    private final ConcurrentMap<String, Cache> caches = new ConcurrentHashMap<String, Cache>();
 
    public CacheManager(Configuration c)
@@ -79,7 +79,7 @@
       if (c != null) c.stop();
    }
 
-   private Cache createNewCache()
+   protected Cache createNewCache()
    {
       // for now latch on to the existing cache creation mechanisms
       DefaultCacheFactory dcf = new DefaultCacheFactory();

Added: core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheFactory.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -0,0 +1,359 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.starobrno;
+
+import org.jboss.cache.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.config.ConfigurationException;
+import org.jboss.starobrno.config.parsing.XmlConfigurationParser;
+import org.jboss.starobrno.util.TestingUtil;
+import org.jgroups.conf.XmlConfigurator;
+
+/**
+ * @author <a href="mailto:dpospisi at redhat.com">Dominik Pospisil (dpospisi at redhat.com)</a>
+ */
+public class UnitTestCacheFactory<K, V> implements CacheFactory<K, V>
+{
+
+   private final Log log = LogFactory.getLog(UnitTestCacheFactory.class);
+
+
+   /**
+    * Holds unique mcast_addr for each thread used for JGroups channel construction.
+    */
+   private static final ThreadLocal<String> threadMcastIP = new ThreadLocal<String>()
+   {
+      private final AtomicInteger uniqueAddr = new AtomicInteger(11);
+
+      @Override
+      protected String initialValue()
+      {
+         return "228.10.10." + uniqueAddr.getAndIncrement();
+      }
+   };
+
+   /**
+    * Holds unique mcast_port for each thread used for JGroups channel construction.
+    */
+   private static final ThreadLocal<Integer> threadMcastPort = new ThreadLocal<Integer>()
+   {
+      private final AtomicInteger uniquePort = new AtomicInteger(45589);
+
+      @Override
+      protected Integer initialValue()
+      {
+         return uniquePort.getAndIncrement();
+      }
+   };
+
+   /**
+    * For each thread holds list of caches created using this factory.
+    */
+   private static final ThreadLocal<List<Cache>> threadCaches =
+         new ThreadLocal<List<Cache>>()
+         {
+            @Override
+            protected List<Cache> initialValue()
+            {
+               return new ArrayList<Cache>();
+            }
+         };
+
+   private final static List<Cache> allCaches = new ArrayList<Cache>();
+
+   /**
+    * For each thread holds the name of the test class which executed createCache factory method.
+    */
+   private static final ThreadLocal<String> threadTestName = new ThreadLocal<String>();
+
+   // factory methods
+
+   public Cache<K, V> createCache() throws ConfigurationException
+   {
+      return createCache(true);
+   }
+
+   public Cache<K, V> createCache(boolean start) throws ConfigurationException
+   {
+      return createCache(new Configuration(), start);
+   }
+
+   public Cache<K, V> createCache(String configFileName) throws ConfigurationException
+   {
+      return createCache(configFileName, true);
+   }
+
+   public Cache<K, V> createCache(String configFileName, boolean start) throws ConfigurationException
+   {
+      XmlConfigurationParser parser = new XmlConfigurationParser();
+      Configuration c;
+      c = parser.parseFile(configFileName);
+      return createCache(c, start);
+   }
+
+   public Cache<K, V> createCache(Configuration configuration) throws ConfigurationException
+   {
+      return createCache(configuration, true);
+   }
+
+   public Cache<K, V> createCache(InputStream is) throws ConfigurationException
+   {
+      return createCache(is, true);
+   }
+
+   public Cache<K, V> createCache(InputStream is, boolean start) throws ConfigurationException
+   {
+      XmlConfigurationParser parser = new XmlConfigurationParser();
+      Configuration c = parser.parseStream(is);
+      return createCache(c, start);
+   }
+
+   public Cache<K, V> createCache(Configuration configuration, boolean start) throws ConfigurationException
+   {
+      // - Do not print out this exception - since tests are ALSO run from IDEs on the main thread. - MANIK
+//      if (!Thread.currentThread().getName().contains("pool"))
+//      {
+//         System.out.println("CreateCache called from wrong thread: " + Thread.currentThread().getName());
+//      }
+
+      checkCaches();
+
+      switch (configuration.getCacheMode())
+      {
+         case LOCAL:
+            // local cache, no channel used
+            break;
+         case REPL_SYNC:
+         case REPL_ASYNC:
+         case INVALIDATION_ASYNC:
+         case INVALIDATION_SYNC:
+            // replicated cache, update channel setup
+            mangleConfiguration(configuration);
+            break;
+         default:
+            log.info("Unknown cache mode!");
+      }
+
+      Cache<K, V> cache = new DefaultCacheFactory<K, V>().createCache(configuration, start);
+
+      List<Cache> caches = threadCaches.get();
+      caches.add(cache);
+
+      synchronized (allCaches)
+      {
+         allCaches.add(cache);
+      }
+      return cache;
+
+   }
+
+   /**
+    * Destroys all caches created by this factory in the current thread.
+    *
+    * @return true if some cleanup was actually performed
+    */
+   public boolean cleanUp()
+   {
+      List<Cache> caches = new ArrayList<Cache>(threadCaches.get());
+      boolean ret = false;
+
+      for (Cache cache : caches)
+      {
+         TestingUtil.killCaches(cache);
+         ret = true;
+      }
+      return ret;
+   }
+
+   public void removeCache(Cache c)
+   {
+
+      // - Do not print out this exception - since tests are ALSO run from IDEs on the main thread. - MANIK
+//      if (!Thread.currentThread().getName().contains("pool"))
+//      {
+//         System.out.println("RemoveCache called from wrong thread.");
+//      }
+
+      List<Cache> caches = threadCaches.get();
+      synchronized (allCaches)
+      {
+         if (caches.contains(c))
+         {
+            caches.remove(c);
+            allCaches.remove(c);
+         }
+         else if (allCaches.contains(c))
+         {
+            System.out.println("[" + Thread.currentThread().getName() + "] WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Remove cache called from different thread.");
+            Thread.dumpStack();
+         }
+      }
+   }
+
+   /**
+    * Updates cluster configuration to ensure mutual thread isolation.
+    *
+    * @param configuration Configuration to update.
+    */
+   public void mangleConfiguration(Configuration configuration)
+   {
+
+      configuration.setClusterConfig(mangleClusterConfiguration(configuration.getClusterConfig()));
+      // Check if the cluster name contains thread id. If not, append. 
+      // We can not just append the threadId, since some of the tests are crating instances
+      // using configurations derived from configurations returned by this factory.
+
+      String clusterName = configuration.getClusterName();
+
+      // append thread id
+      if (clusterName.indexOf(Thread.currentThread().getName()) == -1)
+      {
+         clusterName = clusterName + "-" + Thread.currentThread().getName();
+//       System.out.println(getThreadId() + " Setting cluster name " + newClusterName);         
+      }
+
+//      String testName = extractTestName();
+
+      // prepend test name
+      /*
+      if (clusterName.indexOf(testName) == -1) {
+         clusterName = testName + "-" + clusterName;
+      }
+      */
+
+      configuration.setClusterName(clusterName);
+
+   }
+
+   /**
+    * Updates cluster configuration to ensure mutual thread isolation.
+    */
+   public String mangleClusterConfiguration(String clusterConfig)
+   {
+      if (clusterConfig == null)
+      {
+         // No explicit cluster configuration found. we need to resolve the default config
+         // now in orded to be able to update it before the cache (and the channel) starts.         
+
+         clusterConfig = getDefaultClusterConfiguration();
+      }
+
+      // replace mcast_addr
+      Pattern pattern = Pattern.compile("mcast_addr=[^;]*");
+      Matcher m = pattern.matcher(clusterConfig);
+      if (m.find())
+      {
+         String origAddr = m.group().substring(m.group().indexOf("=") + 1);
+         String newAddr = threadMcastIP.get();
+//         System.out.println(getThreadId() + " Replacing mcast_addr " + origAddr + " with " + newAddr);
+         clusterConfig = m.replaceFirst("mcast_addr=" + newAddr);
+      }
+      else
+      {
+         Thread.dumpStack();
+         System.exit(1);
+      }
+
+      // replace mcast_port
+      pattern = Pattern.compile("mcast_port=[^;]*");
+      m = pattern.matcher(clusterConfig);
+      if (m.find())
+      {
+//         String origPort = m.group().substring(m.group().indexOf("=") + 1);
+         String newPort = threadMcastPort.get().toString();
+         //       System.out.println(getThreadId() + " Replacing mcast_port " + origPort + " with " + newPort);
+         clusterConfig = m.replaceFirst("mcast_port=" + newPort);
+      }
+
+      return clusterConfig;
+   }
+
+//   private String getThreadId()
+//   {
+//      return "[" + Thread.currentThread().getName() + "]";
+//   }
+
+   private void checkCaches()
+   {
+      String lastTestName = threadTestName.get();
+      String currentTestName = extractTestName();
+
+      if ((lastTestName != null) && (!lastTestName.equals(currentTestName)))
+      {
+
+         String threadId = "[" + Thread.currentThread().getName() + "] ";
+
+         // we are running new test class
+         // check if there is a cache(s) instance left & kill it if possitive
+
+         if (cleanUp())
+         {
+            System.out.print(threadId + "WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ");
+            System.out.print(threadId + " A test method in " + lastTestName + " did not clean all cache instances properly. ");
+            System.out.println(threadId + " Use UnitTestCacheFactory.cleanUp() or TestngUtil.killCaches(...) ");
+         }
+
+      }
+      threadTestName.set(currentTestName);
+   }
+
+   private String extractTestName()
+   {
+      StackTraceElement[] stack = Thread.currentThread().getStackTrace();
+      if (stack.length == 0) return null;
+      for (int i = stack.length - 1; i > 0; i--)
+      {
+         StackTraceElement e = stack[i];
+         String className = e.getClassName();
+         if (className.indexOf("org.jboss.cache") != -1) return className; //+ "." + e.getMethodName();
+      }
+      return null;
+   }
+   
+   private String getDefaultClusterConfiguration() {
+      return getClusterConfigFromFile(new Configuration().getDefaultClusterConfig());
+   }
+   
+   /**
+    * Helper method that takes a <b>JGroups</b> configuration file and creates an old-style JGroups config {@link String} that can be used
+    * in {@link org.jboss.cache.config.Configuration#setClusterConfig(String)}.  Note that expressions
+    * in the file - such as <tt>${jgroups.udp.mcast_port:45588}</tt> are expanded out accordingly.
+    *
+    * @param url url to the cfg file
+    * @return a String
+    */
+   public static String getClusterConfigFromFile(URL url)
+   {
+      try
+      {
+         XmlConfigurator conf = XmlConfigurator.getInstance(url);
+         String tmp = conf.getProtocolStackString();
+         // parse this string for ${} substitutions
+         // Highly crappy approach!!
+         tmp = tmp.replace("${jgroups.udp.mcast_addr:228.10.10.10}", "228.10.10.10");
+         tmp = tmp.replace("${jgroups.udp.mcast_port:45588}", "45588");
+         tmp = tmp.replace("${jgroups.udp.ip_ttl:2}", "2");
+//         System.out.println("config string: " + tmp);
+         return tmp;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Problems with url " + url, e);
+      }
+   }
+   
+}

Added: core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheManager.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheManager.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/UnitTestCacheManager.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -0,0 +1,27 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.jboss.starobrno;
+
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.manager.CacheManager;
+
+/**
+ *
+ * @author dpospisi
+ */
+public class UnitTestCacheManager extends CacheManager
+{
+   public UnitTestCacheManager(Configuration c) {
+      super(c);
+   }
+        
+   @Override
+   protected  Cache createNewCache()
+   {
+      UnitTestCacheFactory dcf = new UnitTestCacheFactory();
+      return dcf.createCache(c);      
+   }
+}

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/api/CacheAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/api/CacheAPITest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/api/CacheAPITest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,7 +1,6 @@
 package org.jboss.starobrno.api;
 
 import org.jboss.cache.CacheFactory;
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.transaction.GenericTransactionManagerLookup;
 import org.jboss.starobrno.CacheSPI;
 import org.jboss.starobrno.config.Configuration;
@@ -13,10 +12,9 @@
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 /**
  * Tests the {@link org.jboss.cache.Cache} public API at a high level
@@ -27,19 +25,18 @@
 @Test(groups = {"functional", "pessimistic"})
 public class CacheAPITest
 {
-   private CacheSPI<String, String> cache;
-   final List<String> events = new ArrayList<String>();
+   private ThreadLocal<CacheSPI<String, String>> cacheTL = new ThreadLocal<CacheSPI<String, String>>();
 
    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception
    {
       // start a single cache instance
-      CacheFactory<String, String> cf = new DefaultCacheFactory<String, String>();
-      cache = (CacheSPI<String, String>) cf.createCache("configs/local-tx.xml", false);
+      CacheFactory<String, String> cf = new UnitTestCacheFactory<String, String>();
+      CacheSPI<String, String> cache = (CacheSPI<String, String>) cf.createCache("configs/local-tx.xml", false);
       cache.getConfiguration().setEvictionConfig(null);
       configure(cache.getConfiguration());
       cache.start();
-      events.clear();
+      cacheTL.set(cache);
    }
 
    protected void configure(Configuration c)
@@ -50,7 +47,9 @@
    @AfterMethod(alwaysRun = true)
    public void tearDown()
    {
+      CacheSPI<String, String> cache = cacheTL.get();
       TestingUtil.killCaches(cache);
+      cacheTL.set(null);
    }
 
    /**
@@ -58,6 +57,7 @@
     */
    public void testConfiguration()
    {
+      CacheSPI<String, String> cache = cacheTL.get();
       Configuration c = cache.getConfiguration();
       assertEquals(Configuration.CacheMode.LOCAL, c.getCacheMode());
       assertEquals(GenericTransactionManagerLookup.class.getName(), c.getTransactionManagerLookupClass());
@@ -79,6 +79,7 @@
 
    public void testGetMembersInLocalMode()
    {
+      CacheSPI<String, String> cache = cacheTL.get();
       assert cache.getRPCManager() == null : "Cache members should be null if running in LOCAL mode";
    }
 
@@ -91,6 +92,7 @@
     */
    public void testConvenienceMethods()
    {
+      CacheSPI<String, String> cache = cacheTL.get();
       String key = "key", value = "value";
       Map<String, String> data = new HashMap<String, String>();
       data.put(key, value);
@@ -115,6 +117,7 @@
     */
    public void testEvict()
    {
+      CacheSPI<String, String> cache = cacheTL.get();
       String key1 = "keyOne", key2 = "keyTwo", value = "value";
 
       cache.put(key1, value);
@@ -140,6 +143,7 @@
 
    public void testStopClearsData() throws Exception
    {
+      CacheSPI<String, String> cache = cacheTL.get();
       String key = "key", value = "value";
       cache.put(key, value);
       assert cache.get(key).equals(value);

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/api/CacheSPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/api/CacheSPITest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/api/CacheSPITest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,6 +1,5 @@
 package org.jboss.starobrno.api;
 
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.starobrno.CacheSPI;
 import org.jboss.starobrno.config.Configuration;
 import org.jboss.starobrno.config.Configuration.CacheMode;
@@ -12,12 +11,13 @@
 
 import java.util.List;
 import java.util.concurrent.TimeUnit;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 @Test(groups = {"functional", "pessimistic"})
 public class CacheSPITest
 {
-   private CacheSPI<Object, Object> cache1;
-   private CacheSPI<Object, Object> cache2;
+   private ThreadLocal<CacheSPI<Object, Object>> cache1TL = new ThreadLocal<CacheSPI<Object, Object>>();
+   private ThreadLocal<CacheSPI<Object, Object>> cache2TL = new ThreadLocal<CacheSPI<Object, Object>>();
 
    @BeforeMethod(alwaysRun = true)
    public void setUp() throws Exception
@@ -28,38 +28,30 @@
 
       Configuration conf2 = conf1.clone();
 
-      cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(conf1, false);
-      cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(conf2, false);
+      CacheSPI<Object, Object> cache1 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(conf1, false);
+      CacheSPI<Object, Object> cache2 = (CacheSPI<Object, Object>) new UnitTestCacheFactory<Object, Object>().createCache(conf2, false);
+      cache1TL.set(cache1);
+      cache2TL.set(cache2);
    }
 
    @AfterMethod(alwaysRun = true)
    public void tearDown() throws Exception
    {
-      if (cache1 != null)
-      {
-         try
-         {
-            cache1.stop();
-         }
-         catch (Exception e)
-         {
-         }
-      }
+      CacheSPI<Object, Object> cache1 = cache1TL.get();
+      CacheSPI<Object, Object> cache2 = cache2TL.get();
 
-      if (cache2 != null)
-      {
-         try
-         {
-            cache2.stop();
-         }
-         catch (Exception e)
-         {
-         }
-      }
+      TestingUtil.killCaches(cache1, cache2);
+      
+      cache1TL.set(null);
+      cache2TL.set(null);
+      
    }
 
    public void testGetMembers() throws Exception
    {
+      CacheSPI<Object, Object> cache1 = cache1TL.get();
+      CacheSPI<Object, Object> cache2 = cache2TL.get();
+
       cache1.start();
       List memb1 = cache1.getRPCManager().getMembers();
       assert 1 == memb1.size();
@@ -82,6 +74,9 @@
 
    public void testIsCoordinator() throws Exception
    {
+      CacheSPI<Object, Object> cache1 = cache1TL.get();
+      CacheSPI<Object, Object> cache2 = cache2TL.get();
+
       cache1.start();
       assert cache1.getRPCManager().isCoordinator();
 

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/api/batch/BatchWithTM.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/api/batch/BatchWithTM.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/api/batch/BatchWithTM.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,7 +1,6 @@
 package org.jboss.starobrno.api.batch;
 
 import org.jboss.cache.CacheFactory;
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.transaction.DummyTransactionManagerLookup;
 import org.jboss.starobrno.Cache;
 import org.jboss.starobrno.config.Configuration;
@@ -9,6 +8,7 @@
 import org.testng.annotations.Test;
 
 import javax.transaction.TransactionManager;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 
 @Test(groups = {"functional", "transaction"})
@@ -113,7 +113,7 @@
 
    private Cache<String, String> createCache()
    {
-      CacheFactory<String, String> cf = new DefaultCacheFactory<String, String>();
+      CacheFactory<String, String> cf = new UnitTestCacheFactory<String, String>();
       Configuration c = new Configuration();
       c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
       c.setInvocationBatchingEnabled(true);

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/api/batch/BatchWithoutTM.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/api/batch/BatchWithoutTM.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/api/batch/BatchWithoutTM.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,8 +1,8 @@
 package org.jboss.starobrno.api.batch;
 
 import org.jboss.cache.CacheFactory;
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.UnitTestCacheFactory;
 import org.jboss.starobrno.config.Configuration;
 import org.jboss.starobrno.config.ConfigurationException;
 import org.jboss.starobrno.util.TestingUtil;
@@ -136,7 +136,7 @@
 
    private Cache<String, String> createCache(boolean enableBatch)
    {
-      CacheFactory<String, String> cf = new DefaultCacheFactory<String, String>();
+      CacheFactory<String, String> cf = new UnitTestCacheFactory<String, String>();
       Configuration c = new Configuration();
       c.setInvocationBatchingEnabled(enableBatch);
       return cf.createCache(c);

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/LockTestBase.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/LockTestBase.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/LockTestBase.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -2,7 +2,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.lock.IsolationLevel;
 import org.jboss.cache.transaction.DummyTransactionManagerLookup;
 import org.jboss.starobrno.Cache;
@@ -18,6 +17,7 @@
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 import java.util.Collections;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 /**
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
@@ -26,54 +26,69 @@
 @Test(groups = {"functional", "mvcc"})
 public abstract class LockTestBase
 {
-   protected Cache<String, String> cache;
-   protected TransactionManager tm;
-   protected LockManager lockManager;
-   protected InvocationContextContainer icc;
    protected boolean repeatableRead = true;
    protected boolean lockParentForChildInsertRemove = false;
    private Log log = LogFactory.getLog(LockTestBase.class);
+   
+   protected class LockTestBaseTL {
+      public Cache<String, String> cache;
+      public TransactionManager tm;
+      public LockManager lockManager;
+      public InvocationContextContainer icc;
+   }
+   
+   protected ThreadLocal<LockTestBaseTL> threadLocal = new ThreadLocal<LockTestBaseTL>();
 
 
    @BeforeMethod
    public void setUp()
    {
-      cache = new DefaultCacheFactory<String, String>().createCache(new Configuration(), false);
-      cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
-      cache.getConfiguration().setIsolationLevel(repeatableRead ? IsolationLevel.REPEATABLE_READ : IsolationLevel.READ_COMMITTED);
-      cache.getConfiguration().setLockParentForChildInsertRemove(lockParentForChildInsertRemove);
+      LockTestBaseTL tl = new LockTestBaseTL();
+      tl.cache = new UnitTestCacheFactory<String, String>().createCache(new Configuration(), false);
+      tl.cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+      tl.cache.getConfiguration().setIsolationLevel(repeatableRead ? IsolationLevel.REPEATABLE_READ : IsolationLevel.READ_COMMITTED);
+      tl.cache.getConfiguration().setLockParentForChildInsertRemove(lockParentForChildInsertRemove);
       // reduce lock acquisition timeout so this doesn't take forever to run
-      cache.getConfiguration().setLockAcquisitionTimeout(200); // 200 ms
-      cache.start();
-      lockManager = TestingUtil.extractComponentRegistry(cache).getComponent(LockManager.class);
-      icc = TestingUtil.extractComponentRegistry(cache).getComponent(InvocationContextContainer.class);
-      tm = TestingUtil.extractComponentRegistry(cache).getComponent(TransactionManager.class);
+      tl.cache.getConfiguration().setLockAcquisitionTimeout(200); // 200 ms
+      tl.cache.start();
+      tl.lockManager = TestingUtil.extractComponentRegistry(tl.cache).getComponent(LockManager.class);
+      tl.icc = TestingUtil.extractComponentRegistry(tl.cache).getComponent(InvocationContextContainer.class);
+      tl.tm = TestingUtil.extractComponentRegistry(tl.cache).getComponent(TransactionManager.class);
+      threadLocal.set(tl);
    }
 
    @AfterMethod
    public void tearDown()
    {
+      LockTestBaseTL tl = threadLocal.get();
       log.debug("**** - STARTING TEARDOWN - ****");
-      TestingUtil.killCaches(cache);
+      TestingUtil.killCaches(tl.cache);
+      threadLocal.set(null);
    }
 
    protected void assertLocked(Object key)
    {
-      LockAssert.assertLocked(key, lockManager, icc);
+      LockTestBaseTL tl = threadLocal.get();
+      LockAssert.assertLocked(key, tl.lockManager, tl.icc);
    }
 
    protected void assertNotLocked(Object key)
    {
-      LockAssert.assertNotLocked(key, icc);
+      LockTestBaseTL tl = threadLocal.get();
+      LockAssert.assertNotLocked(key, tl.icc);
    }
 
    protected void assertNoLocks()
    {
-      LockAssert.assertNoLocks(lockManager, icc);
+      LockTestBaseTL tl = threadLocal.get();
+      LockAssert.assertNoLocks(tl.lockManager, tl.icc);
    }
 
    public void testLocksOnPutKeyVal() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       tm.begin();
       cache.put("k", "v");
       assertLocked("k");
@@ -98,6 +113,9 @@
 
    public void testLocksOnPutData() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       tm.begin();
       cache.putAll(Collections.singletonMap("k", "v"));
       assertLocked("k");
@@ -116,6 +134,9 @@
 
    public void testLocksOnEvictNode() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       // init some data on a node
       cache.putAll(Collections.singletonMap("k", "v"));
 
@@ -131,6 +152,9 @@
 
    public void testLocksOnRemoveNonexistentNode() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       assert !cache.containsKey("k") : "Should not exist";
 
       tm.begin();
@@ -143,6 +167,9 @@
 
    public void testLocksOnEvictNonexistentNode() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       assert !cache.containsKey("k") : "Should not exist";
 
       tm.begin();
@@ -155,6 +182,9 @@
 
    public void testLocksOnRemoveData() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       // init some data on a node
       cache.put("k", "v");
       cache.put("k2", "v2");
@@ -175,6 +205,9 @@
 
    public void testWriteDoesntBlockRead() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       cache.put("k", "v");
 
       // start a write.
@@ -206,6 +239,9 @@
 
    public void testWriteDoesntBlockReadNonexistent() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       // start a write.
       tm.begin();
       cache.put("k", "v");
@@ -238,6 +274,9 @@
 
    public void testConcurrentWriters() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       tm.begin();
       cache.put("k", "v");
       Transaction t1 = tm.suspend();
@@ -260,6 +299,9 @@
 
    public void testRollbacks() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       cache.put("k", "v");
       tm.begin();
       assert "v".equals(cache.get("k"));
@@ -281,6 +323,9 @@
 
    public void testRollbacksOnNullNode() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       tm.begin();
       assert null == cache.get("k");
       Transaction reader = tm.suspend();

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/repeatable_read/RepeatableReadLockTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/repeatable_read/RepeatableReadLockTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/repeatable_read/RepeatableReadLockTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -4,6 +4,8 @@
 import org.testng.annotations.Test;
 
 import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import org.jboss.starobrno.Cache;
 
 @Test(groups = {"functional", "mvcc"})
 public class RepeatableReadLockTest extends LockTestBase
@@ -15,6 +17,9 @@
 
    public void testRepeatableReadWithRemove() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
       cache.put("k", "v");
 
       tm.begin();
@@ -39,6 +44,10 @@
 
    public void testRepeatableReadWithEvict() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
+
       cache.put("k", "v");
 
       tm.begin();
@@ -63,6 +72,10 @@
 
    public void testRepeatableReadWithNull() throws Exception
    {
+      LockTestBaseTL tl = threadLocal.get();
+      Cache<String, String> cache = tl.cache;
+      TransactionManager tm = tl.tm;
+
       assert cache.get("k") == null;
 
       tm.begin();

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/repeatable_read/WriteSkewTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/repeatable_read/WriteSkewTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/api/mvcc/repeatable_read/WriteSkewTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,6 +1,5 @@
 package org.jboss.starobrno.api.mvcc.repeatable_read;
 
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.lock.IsolationLevel;
 import org.jboss.cache.transaction.DummyTransactionManagerLookup;
 import org.jboss.starobrno.Cache;
@@ -19,8 +18,9 @@
 import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
- at Test(groups = {"functional", "mvcc"})
+ at Test(groups = {"functional", "mvcc"}, sequential = true)
 public class WriteSkewTest
 {
    protected Cache<String, String> cache;
@@ -32,7 +32,7 @@
    @BeforeMethod
    public void setUp()
    {
-      cache = new DefaultCacheFactory<String, String>().createCache(new Configuration(), false);
+      cache = new UnitTestCacheFactory<String, String>().createCache(new Configuration(), false);
       cache.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
       cache.getConfiguration().setIsolationLevel(repeatableRead ? IsolationLevel.REPEATABLE_READ : IsolationLevel.READ_COMMITTED);
       // reduce lock acquisition timeout so this doesn't take forever to run

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/notifications/AsyncNotificationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/notifications/AsyncNotificationTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/notifications/AsyncNotificationTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,6 +1,5 @@
 package org.jboss.starobrno.notifications;
 
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.starobrno.Cache;
 import org.jboss.starobrno.notifications.annotation.CacheEntryCreated;
 import org.jboss.starobrno.notifications.annotation.CacheListener;
@@ -10,6 +9,7 @@
 
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 @Test(groups = "functional")
 public class AsyncNotificationTest
@@ -19,7 +19,7 @@
       Cache<String, String> c = null;
       try
       {
-         c = new DefaultCacheFactory<String, String>().createCache();
+         c = new UnitTestCacheFactory<String, String>().createCache();
          CountDownLatch latch = new CountDownLatch(2);
          AbstractListener syncListener = new Listener(latch);
          AbstractListener asyncListener = new AsyncListener(latch);

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/notifications/CacheListenerTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/notifications/CacheListenerTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/notifications/CacheListenerTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,6 +1,5 @@
 package org.jboss.starobrno.notifications;
 
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.lock.IsolationLevel;
 import org.jboss.starobrno.Cache;
 import org.jboss.starobrno.config.Configuration;
@@ -21,6 +20,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 /**
  * Note that this is significantly different from the old <b>TreeCacheListenerTest</b> of the JBoss Cache 1.x series, and
@@ -28,7 +28,7 @@
  *
  * @since 2.0.0
  */
- at Test(groups = "functional")
+ at Test(groups = "functional", sequential = true)
 public class CacheListenerTest
 {
    private Cache<Object, Object> cache;
@@ -43,7 +43,7 @@
       c.setCacheMode(Configuration.CacheMode.LOCAL);
       c.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
       c.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
-      cache = new DefaultCacheFactory<Object, Object>().createCache(c);
+      cache = new UnitTestCacheFactory<Object, Object>().createCache(c);
       tm = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
       eventLog.events.clear();
       cache.addCacheListener(eventLog);

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/notifications/ConcurrentNotificationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/notifications/ConcurrentNotificationTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/notifications/ConcurrentNotificationTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -3,7 +3,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.CacheFactory;
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.starobrno.Cache;
 import org.jboss.starobrno.notifications.annotation.CacheEntryCreated;
 import org.jboss.starobrno.notifications.annotation.CacheEntryModified;
@@ -19,6 +18,7 @@
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicInteger;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 /**
  * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
@@ -34,7 +34,7 @@
    @BeforeMethod(alwaysRun = true)
    public void setUp()
    {
-      CacheFactory<String, String> instance = new DefaultCacheFactory<String, String>();
+      CacheFactory<String, String> instance = new UnitTestCacheFactory<String, String>();
       cache = instance.createCache();
       listener = new Listener();
       cache.addCacheListener(listener);

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifierAnnotationsTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifierAnnotationsTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifierAnnotationsTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -25,25 +25,29 @@
 @Test(groups = {"functional"})
 public class NotifierAnnotationsTest
 {
-   private NotifierImpl n;
+   private ThreadLocal<NotifierImpl> nTL = new ThreadLocal<NotifierImpl>();
 
    @BeforeMethod(alwaysRun = true)
    public void setUp()
    {
-      n = new NotifierImpl();
+      NotifierImpl n = new NotifierImpl();
       n.injectDependencies(createNiceMock(CacheSPI.class), new Configuration());
       n.start();
+      nTL.set(n);
    }
 
    @AfterMethod
    public void tearDown()
    {
+      NotifierImpl n = nTL.get();
       n.stop();
       n.destroy();
+      nTL.set(null);
    }
 
    public void testControl()
    {
+      NotifierImpl n = nTL.get();      
       Object l = new TestControlListener();
       n.addCacheListener(l);
       assertEquals(1, n.getCacheListeners().size());
@@ -51,6 +55,7 @@
 
    public void testCacheListenerNoMethods()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestCacheListenerNoMethodsListener();
       n.addCacheListener(l);
       assertEquals("Hello", l.toString());
@@ -59,6 +64,7 @@
 
    public void testNonAnnotatedListener()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestNonAnnotatedListener();
       try
       {
@@ -74,6 +80,7 @@
 
    public void testNonPublicListener()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestNonPublicListener();
       try
       {
@@ -89,6 +96,7 @@
 
    public void testNonPublicListenerMethod()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestNonPublicListenerMethodListener();
       n.addCacheListener(l);
 
@@ -99,6 +107,7 @@
 
    public void testNonVoidReturnTypeMethod()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestNonVoidReturnTypeMethodListener();
       try
       {
@@ -114,6 +123,7 @@
 
    public void testIncorrectMethodSignature1()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestIncorrectMethodSignature1Listener();
       try
       {
@@ -129,6 +139,7 @@
 
    public void testIncorrectMethodSignature2()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestIncorrectMethodSignature2Listener();
       try
       {
@@ -144,6 +155,7 @@
 
    public void testIncorrectMethodSignature3()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestIncorrectMethodSignature3Listener();
       try
       {
@@ -159,6 +171,7 @@
 
    public void testUnassignableMethodSignature()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestUnassignableMethodSignatureListener();
       try
       {
@@ -174,6 +187,7 @@
 
    public void testPartlyUnassignableMethodSignature()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestPartlyUnassignableMethodSignatureListener();
       try
       {
@@ -188,6 +202,7 @@
 
    public void testMultipleMethods()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestMultipleMethodsListener();
       n.addCacheListener(l);
       List invocations = n.cacheStartedListeners;
@@ -199,6 +214,7 @@
 
    public void testMultipleAnnotationsOneMethod()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestMultipleAnnotationsOneMethodListener();
       n.addCacheListener(l);
       List invocations = n.cacheStartedListeners;
@@ -210,6 +226,7 @@
 
    public void testMultipleMethodsOneAnnotation()
    {
+      NotifierImpl n = nTL.get();
       Object l = new TestMultipleMethodsOneAnnotationListener();
       n.addCacheListener(l);
       List invocations = n.cacheStartedListeners;

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifierTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifierTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifierTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -25,34 +25,47 @@
 @Test(groups = "unit")
 public class NotifierTest
 {
-   private NotifierImpl notifier;
-   private InvocationContext ctx;
-   private AllEventsListener allEventsListener;
-   private Fqn fqn = Fqn.fromString("/a/b/c");
+   
+   private static final Fqn fqn = Fqn.fromString("/a/b/c");
+   private class NotifierTestTL {
+      private NotifierImpl notifier;
+      private InvocationContext ctx;
+      private AllEventsListener allEventsListener;
+   }
+   private ThreadLocal<NotifierTestTL> threadLocal = new ThreadLocal<NotifierTestTL>();
 
    @BeforeMethod
    public void setUp()
    {
-      notifier = new NotifierImpl();
+      NotifierTestTL tl = new NotifierTestTL();
+      threadLocal.set(tl);
+      tl.notifier = new NotifierImpl();
       CacheSPI cacheSPI = createNiceMock(CacheSPI.class);
       expect(cacheSPI.getInvocationContext()).andStubReturn(new InvocationContextImpl());
       replay(cacheSPI);
-      notifier.injectDependencies(cacheSPI, new Configuration());
-      notifier.start();
-      ctx = new InvocationContextImpl();
-      allEventsListener = new AllEventsListener();
-      notifier.addCacheListener(allEventsListener);
+      tl.notifier.injectDependencies(cacheSPI, new Configuration());
+      tl.notifier.start();
+      tl.ctx = new InvocationContextImpl();
+      tl.allEventsListener = new AllEventsListener();
+      tl.notifier.addCacheListener(tl.allEventsListener);
    }
 
    @AfterMethod
    public void tearDown()
    {
-      notifier.stop();
-      notifier.destroy();
+      NotifierTestTL tl = threadLocal.get();
+      tl.notifier.stop();
+      tl.notifier.destroy();
+      threadLocal.set(null);
    }
 
    public void testNotifyNodeCreated()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+      
       assert allEventsListener.nodeCreatedEvent == null;
       notifier.notifyCacheEntryCreated("K", true, ctx);
       assert allEventsListener.nodeCreatedEvent != null;
@@ -62,6 +75,9 @@
 
    public void testShouldNotifyOnNodeModified()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+
       assert notifier.shouldNotifyOnNodeModified();
       notifier.destroy();
       assert !notifier.shouldNotifyOnNodeModified();
@@ -69,6 +85,11 @@
 
    public void testNotifyNodeModified()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.nodeModifiedEvent == null;
       notifier.notifyCacheEntryModified("key", true, ctx);
       assert allEventsListener.nodeModifiedEvent != null;
@@ -77,6 +98,11 @@
 
    public void testNotifyNodeRemoved()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.nodeRemoveEvent == null;
       notifier.notifyCacheEntryRemoved("key", true, ctx);
       assert allEventsListener.nodeRemoveEvent != null;
@@ -86,6 +112,11 @@
 
    public void testNotifyNodeVisited()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.nodeVisistedEvent == null;
       notifier.notifyCacheEntryVisited(fqn, true, ctx);
       assert allEventsListener.nodeVisistedEvent != null;
@@ -94,6 +125,11 @@
 
    public void testNotifyNodeEvicted()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.nodeEvictedEvent == null;
       notifier.notifyCacheEntryEvicted("key", true, ctx);
       assert allEventsListener.nodeEvictedEvent != null;
@@ -103,6 +139,11 @@
 
    public void testNotifyNodeLoaded()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.nodeLoadedEvent == null;
       notifier.notifyCacheEntryLoaded("key", true, ctx);
       assert allEventsListener.nodeLoadedEvent != null;
@@ -112,6 +153,11 @@
 
    public void testNotifyNodeActivated()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.nodeActivatedEvent == null;
       notifier.notifyCacheEntryActivated("key", true, ctx);
       assert allEventsListener.nodeActivatedEvent != null;
@@ -121,6 +167,11 @@
 
    public void testNotifyNodePassivated()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.nodePassivatedEvent == null;
       notifier.notifyCacheEntryPassivated("key", true, ctx);
       assert allEventsListener.nodePassivatedEvent != null;
@@ -130,6 +181,11 @@
 
    public void testNotifyCacheStarted()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.cacheStartedEvent == null;
       notifier.notifyCacheStarted();
       assert allEventsListener.cacheStartedEvent != null;
@@ -138,6 +194,11 @@
 
    public void testNotifyCacheStopped()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.cacheStoppedEvent == null;
       notifier.notifyCacheStopped();
       assert allEventsListener.cacheStoppedEvent != null;
@@ -146,6 +207,11 @@
 
    public void testNotifyViewChange()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.viewChanged == null;
       View view = new View();
       notifier.notifyViewChange(view, ctx);
@@ -156,6 +222,10 @@
 
    public void testNotifyBuddyGroupChange()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.buddyGroupChangedEvent == null;
       BuddyGroup buddyGroup = new BuddyGroup();
       notifier.notifyBuddyGroupChange(buddyGroup, true);
@@ -166,6 +236,11 @@
 
    public void testNotifyTransactionCompleted()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.transactionCompleted == null;
       Transaction tx = createNiceMock(Transaction.class);
       notifier.notifyTransactionCompleted(tx, false, ctx);
@@ -177,6 +252,11 @@
 
    public void testNotifyTransactionRegistered()
    {
+      NotifierTestTL tl = threadLocal.get();
+      NotifierImpl notifier = tl.notifier;
+      InvocationContext ctx = tl.ctx;
+      AllEventsListener allEventsListener = tl.allEventsListener;
+
       assert allEventsListener.transactionRegistered == null;
       Transaction tx = createNiceMock(Transaction.class);
       notifier.notifyTransactionRegistered(tx, ctx);

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifyNodeInvalidatedTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifyNodeInvalidatedTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/notifications/NotifyNodeInvalidatedTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,6 +1,5 @@
 package org.jboss.starobrno.notifications;
 
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.starobrno.Cache;
 import org.jboss.starobrno.config.Configuration;
 import org.jboss.starobrno.config.Configuration.CacheMode;
@@ -11,6 +10,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 @Test(groups = "functional")
 public class NotifyNodeInvalidatedTest
@@ -22,8 +22,8 @@
       {
          Configuration cfg = new Configuration();
          cfg.setCacheMode(CacheMode.INVALIDATION_SYNC);
-         c1 = new DefaultCacheFactory<String, String>().createCache(cfg.clone());
-         c2 = new DefaultCacheFactory<String, String>().createCache(cfg.clone());
+         c1 = new UnitTestCacheFactory<String, String>().createCache(cfg.clone());
+         c2 = new UnitTestCacheFactory<String, String>().createCache(cfg.clone());
          EventLog eventLog = new EventLog();
          c2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
          c2.put("k", "y");

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/profiling/AbstractProfileTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/profiling/AbstractProfileTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/profiling/AbstractProfileTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,6 +1,5 @@
 package org.jboss.starobrno.profiling;
 
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.starobrno.Cache;
 import org.jboss.starobrno.config.Configuration;
 import org.jboss.starobrno.util.TestingUtil;
@@ -9,6 +8,7 @@
 import org.testng.annotations.Test;
 
 import java.util.Map;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 @Test(groups = "profiling")
 public abstract class AbstractProfileTest
@@ -19,7 +19,7 @@
    public void setUp()
    {
       Configuration cfg = new Configuration();
-      cache = new DefaultCacheFactory().createCache(cfg, false);
+      cache = new UnitTestCacheFactory().createCache(cfg, false);
    }
 
    @AfterTest

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/profiling/MemConsumptionTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/profiling/MemConsumptionTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/profiling/MemConsumptionTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -19,9 +19,8 @@
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
-package org.jboss.cache.profiling;
+package org.jboss.starobrno.profiling;
 
-import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.starobrno.Cache;
 import org.jboss.starobrno.util.TestingUtil;
 import org.testng.annotations.Test;
@@ -31,15 +30,16 @@
 import java.util.Arrays;
 import java.util.Random;
 import java.util.concurrent.TimeUnit;
+import org.jboss.starobrno.UnitTestCacheFactory;
 
 @Test(groups = "profiling")
 public class MemConsumptionTest
 {
    // adjust the next 3 numbers
-   int numEntries = 1000000;
-   int payloadSize = 20; // bytes
-   int keySize = 10; // bytes
-   int bytesPerChar = 2;
+   static final int numEntries = 1000000;
+   static final int payloadSize = 20; // bytes
+   static final int keySize = 10; // bytes
+   static final int bytesPerChar = 2;
 
    Random r = new Random();
 
@@ -49,7 +49,7 @@
       System.out.println("Bytes to be cached: " + NumberFormat.getIntegerInstance().format(kBytesCached) + " kb");
 
 //      Cache<byte[], byte[]> c = new DefaultCacheFactory<byte[], byte[]>().createCache(); // default LOCAL cache
-      Cache<String, String> c = new DefaultCacheFactory<String, String>().createCache(); // default LOCAL cache
+      Cache<String, String> c = new UnitTestCacheFactory<String, String>().createCache(); // default LOCAL cache
 //      Map<String, String> c = new ConcurrentHashMap<String, String>();
       long start = System.nanoTime();
       for (int i = 0; i < numEntries; i++)

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/profiling/ProfileTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/profiling/ProfileTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/profiling/ProfileTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -30,7 +30,7 @@
  * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
  * @since 2.1.0
  */
- at Test(groups = "profiling")
+ at Test(groups = "profiling", sequential = true)
 public class ProfileTest extends AbstractProfileTest
 {
    /*
@@ -208,7 +208,7 @@
       double nOps = (double) (NUM_OPERATIONS / 3);
       double avg = ((double) totalNanos) / nOps;
       double avgMicros = avg / 1000;
-      return avgMicros + " µs";
+      return avgMicros + " �s";
    }
 
    private double toMillis(long nanos)

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/replication/AsyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/replication/AsyncReplTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/replication/AsyncReplTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -8,7 +8,6 @@
 
 package org.jboss.starobrno.replication;
 
-import org.jboss.cache.Fqn;
 import org.jboss.cache.transaction.DummyTransactionManagerLookup;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
@@ -18,6 +17,7 @@
 import javax.transaction.TransactionManager;
 import org.jboss.starobrno.CacheSPI;
 import org.jboss.starobrno.Cache;
+import org.jboss.starobrno.UnitTestCacheManager;
 import org.jboss.starobrno.manager.CacheManager;
 import org.jboss.starobrno.config.Configuration;
 import org.jboss.starobrno.util.internals.ReplicationListener;
@@ -30,9 +30,9 @@
 @Test(groups = {"functional", "jgroups"})
 public class AsyncReplTest
 {
-   private Configuration configuration;
 
    private class AsyncReplTestTL {
+      private Configuration configuration;
       private CacheSPI<Object, Object> cache1, cache2;
       private CacheManager cacheManager1, cacheManager2;
       private ReplicationListener replListener1, replListener2;
@@ -46,17 +46,17 @@
       AsyncReplTestTL tl = new AsyncReplTestTL();
       threadLocal.set(tl);
 
-      configuration = new Configuration();
-      configuration.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
-      configuration.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+      tl.configuration = new Configuration();
+      tl.configuration.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+      tl.configuration.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
 
       log("creating cache1");
-      tl.cacheManager1 = new CacheManager(configuration);
+      tl.cacheManager1 = new UnitTestCacheManager(tl.configuration);
       tl.cache1 = (CacheSPI) tl.cacheManager1.createCache("testCache");
       tl.replListener1 = new ReplicationListener(tl.cache1);
 
       log("creating cache2");
-      tl.cacheManager2 = new CacheManager(configuration);
+      tl.cacheManager2 = new UnitTestCacheManager(tl.configuration);
       tl.cache2 = (CacheSPI) tl.cacheManager2.createCache("testCache");
       tl.replListener2 = new ReplicationListener(tl.cache2);
    }
@@ -147,9 +147,9 @@
       CacheSPI<Object, Object> cache3 = null, cache4 = null;
       try
       {
-         configuration.setClusterName("otherTest");
-         cache3 = (CacheSPI<Object, Object>) new CacheManager(configuration).createCache("testCache");
-         cache4 = (CacheSPI<Object, Object>) new CacheManager(configuration).createCache("testCache");
+         tl.configuration.setClusterName("otherTest");
+         cache3 = (CacheSPI<Object, Object>) new UnitTestCacheManager(tl.configuration).createCache("testCache");
+         cache4 = (CacheSPI<Object, Object>) new UnitTestCacheManager(tl.configuration).createCache("testCache");
          replListener2.expectAny();
          cache1.put("age", 38);
          // because we use async repl, modfication may not yet have been propagated to cache2, so

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/replication/ExceptionTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/replication/ExceptionTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/replication/ExceptionTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -1,17 +1,16 @@
 package org.jboss.starobrno.replication;
 
 import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
 import org.jboss.starobrno.Cache;
-import org.jboss.starobrno.manager.CacheManager;
 import org.jboss.starobrno.util.TestingUtil;
 import org.jboss.starobrno.lock.TimeoutException;
 import org.jboss.starobrno.config.Configuration;
 import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.jboss.starobrno.UnitTestCacheManager;
 
 /**
  * Tests the type of exceptions thrown for Lock Acquisition Timeouts versus Sync Repl Timeouts
@@ -47,7 +46,7 @@
       c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
       if (jgroupsConfig != null) c.setClusterConfig(jgroupsConfig);
       c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
-      Cache cache = new CacheManager(c).createCache("testCache");
+      Cache cache = new UnitTestCacheManager(c).createCache("testCache");
       return cache;
    }
 

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/replication/ReplicationExceptionTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/replication/ReplicationExceptionTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/replication/ReplicationExceptionTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -13,7 +13,6 @@
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.jboss.starobrno.CacheSPI;
-import org.jboss.starobrno.manager.CacheManager;
 import org.jboss.starobrno.config.Configuration;
 import org.jboss.starobrno.util.TestingUtil;
 import org.jboss.cache.transaction.DummyTransactionManager;
@@ -26,6 +25,7 @@
 import javax.transaction.TransactionManager;
 import java.io.NotSerializableException;
 import java.io.Serializable;
+import org.jboss.starobrno.UnitTestCacheManager;
 
 /**
  * Teting of replication exception for a Nonerislizable object
@@ -89,8 +89,8 @@
       conf1.setLockAcquisitionTimeout(5000);
       conf2.setLockAcquisitionTimeout(5000);
 
-      cache1 = (CacheSPI) new CacheManager(conf1).createCache("testCache");
-      cache2 = (CacheSPI) new CacheManager(conf2).createCache("testCache");
+      cache1 = (CacheSPI) new UnitTestCacheManager(conf1).createCache("testCache");
+      cache2 = (CacheSPI) new UnitTestCacheManager(conf2).createCache("testCache");
 
 
       cache1.start();

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/replication/SyncCacheListenerTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/replication/SyncCacheListenerTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/replication/SyncCacheListenerTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -15,7 +15,6 @@
 import org.jboss.starobrno.CacheException;
 import org.jboss.starobrno.CacheSPI;
 import org.jboss.starobrno.config.Configuration;
-import org.jboss.starobrno.manager.CacheManager;
 import org.jboss.starobrno.notifications.annotation.CacheEntryModified;
 import org.jboss.starobrno.notifications.annotation.CacheEntryRemoved;
 import org.jboss.starobrno.notifications.annotation.CacheListener;
@@ -30,9 +29,9 @@
 import javax.naming.Context;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+import org.jboss.starobrno.UnitTestCacheManager;
 
 /**
  * Test out the TreeCacheListener
@@ -84,8 +83,8 @@
       conf.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
       conf.setLockAcquisitionTimeout(5000);
 
-      cache1 = (CacheSPI) new CacheManager(conf).createCache("firstCache");
-      cache2 = (CacheSPI) new CacheManager(conf).createCache("firstCache");
+      cache1 = (CacheSPI) new UnitTestCacheManager(conf).createCache("firstCache");
+      cache2 = (CacheSPI) new UnitTestCacheManager(conf).createCache("firstCache");
       TestingUtil.blockUntilViewReceived(cache2, 2, 1000);
    }
 

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/replication/SyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/replication/SyncReplTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/replication/SyncReplTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -11,8 +11,7 @@
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.jboss.starobrno.Cache;
-import org.jboss.starobrno.context.InvocationContext;
-import org.jboss.starobrno.manager.CacheManager;
+import org.jboss.starobrno.UnitTestCacheManager;
 import org.jboss.starobrno.util.TestingUtil;
 import org.jboss.starobrno.config.Configuration;
 
@@ -31,8 +30,8 @@
       Cache<Object, Object>[] caches = new Cache[2];
       Configuration configuration = new Configuration();
       configuration.setCacheMode(Configuration.CacheMode.REPL_SYNC);
-      caches[0] = new CacheManager(configuration).createCache("test");
-      caches[1] = new CacheManager(configuration).createCache("test");
+      caches[0] = new UnitTestCacheManager(configuration).createCache("test");
+      caches[1] = new UnitTestCacheManager(configuration).createCache("test");
       cachesTL.set(caches);
       TestingUtil.blockUntilViewsReceived(caches, 5000);
       System.out.println("*** Finished setUp()");

Modified: core/branches/flat/src/test/java/org/jboss/starobrno/tx/LocalModeTxTest.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/tx/LocalModeTxTest.java	2008-10-17 05:11:03 UTC (rev 6979)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/tx/LocalModeTxTest.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -30,6 +30,7 @@
 
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
+import org.jboss.starobrno.UnitTestCacheManager;
 
 @Test(groups = "functional")
 public class LocalModeTxTest
@@ -38,7 +39,7 @@
    {
       Configuration cfg = new Configuration();
       cfg.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
-      CacheManager cm = new CacheManager(cfg);
+      CacheManager cm = new UnitTestCacheManager(cfg);
       return (CacheSPI<String, String>) cm.createCache("test");
    }
 

Added: core/branches/flat/src/test/java/org/jboss/starobrno/util/UnitTestTestNGListener.java
===================================================================
--- core/branches/flat/src/test/java/org/jboss/starobrno/util/UnitTestTestNGListener.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/jboss/starobrno/util/UnitTestTestNGListener.java	2008-10-17 17:17:17 UTC (rev 6980)
@@ -0,0 +1,93 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.jboss.starobrno.util;
+
+import org.testng.IClass;
+import org.testng.ITestContext;
+import org.testng.ITestListener;
+import org.testng.ITestResult;
+
+/**
+ *
+ * @author dpospisi
+ */
+public class UnitTestTestNGListener implements ITestListener {
+      
+   /**
+    * Holds test classes actually running in all threads.
+    */
+   private ThreadLocal<IClass> threadTestClass = new ThreadLocal<IClass>();
+   
+   private int failed = 0;
+   private int succeded = 0;
+   private int skipped = 0;
+   
+   public void onTestStart(ITestResult res) {
+      System.out.println(getThreadId() + " Starting test " + getTestDesc(res));            
+      
+      /*
+      IClass testClass = threadTestClass.get();
+      if ((testClass != null) && (! res.getTestClass().equals(testClass))) {
+
+         System.out.println(getThreadId() + " New test class" + res.getTestClass() + ", was " + testClass);            
+
+         // the thread has started testing a new test class
+
+         // clean all possibly running caches created in current thread
+         boolean cleaned = new UnitTestCacheFactory().cleanUp();
+         if (cleaned) {
+            // previous test left a cache
+            System.out.println(getThreadId() +" WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+            System.out.println(getThreadId() +" A test method in " + testClass.getName() + " did not clean all cache instances properly.");
+            System.out.println(getThreadId() +" Use UnitTestCacheFactory.cleanUp() or TestngUtil.killCaches(...) ");
+            System.out.println(getThreadId() +" WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+         }
+      }
+      */ 
+      
+      threadTestClass.set(res.getTestClass());
+   }
+
+   synchronized public void onTestSuccess(ITestResult arg0) {
+      System.out.println(getThreadId() + " Test " + getTestDesc(arg0) + " succeded.");
+      succeded++;
+      printStatus();
+   }
+
+   synchronized public void onTestFailure(ITestResult arg0) {
+      System.out.println(getThreadId() + " Test " + getTestDesc(arg0) + " failed.");
+      failed++;
+      printStatus();      
+   }
+
+   synchronized public void onTestSkipped(ITestResult arg0) {
+      System.out.println(getThreadId() + " Test " + getTestDesc(arg0) + " skipped.");
+      skipped++;
+      printStatus();
+   }
+
+   public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) {
+   }
+
+   public void onStart(ITestContext arg0) {      
+   }
+
+   public void onFinish(ITestContext arg0) {
+   }
+   
+   private String getThreadId() {
+       return  "["+ Thread.currentThread().getName() + "]";
+   }
+   
+   private String getTestDesc(ITestResult res) {
+      return res.getMethod().getMethodName() + "(" + res.getTestClass().getName() + ")";
+   }
+   
+   private void printStatus() {
+      System.out.println("Testsuite execution progress: tests succeded " + succeded + ", failed " + failed + ", skipped " + skipped + ".");
+   }
+
+}




More information about the jbosscache-commits mailing list