[infinispan-commits] Infinispan SVN: r924 - in trunk/core/src/test/java/org/infinispan: api/batch and 22 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Oct 8 15:19:44 EDT 2009


Author: vblagojevic at jboss.com
Date: 2009-10-08 15:19:42 -0400 (Thu, 08 Oct 2009)
New Revision: 924

Modified:
   trunk/core/src/test/java/org/infinispan/api/AsyncAPITest.java
   trunk/core/src/test/java/org/infinispan/api/CacheAPITest.java
   trunk/core/src/test/java/org/infinispan/api/CacheClusterJoinTest.java
   trunk/core/src/test/java/org/infinispan/api/MixedModeTest.java
   trunk/core/src/test/java/org/infinispan/api/batch/BatchWithTMTest.java
   trunk/core/src/test/java/org/infinispan/api/batch/BatchWithoutTMTest.java
   trunk/core/src/test/java/org/infinispan/api/mvcc/LockPerEntryTest.java
   trunk/core/src/test/java/org/infinispan/api/mvcc/repeatable_read/WriteSkewTest.java
   trunk/core/src/test/java/org/infinispan/atomic/APITest.java
   trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/atomic/ClusteredAPITest.java
   trunk/core/src/test/java/org/infinispan/distribution/AsyncAPIAsyncDistTest.java
   trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/distribution/DistAsyncFuncTest.java
   trunk/core/src/test/java/org/infinispan/distribution/DistAsyncTxFuncTest.java
   trunk/core/src/test/java/org/infinispan/distribution/DistAsyncTxUnsafeFuncTest.java
   trunk/core/src/test/java/org/infinispan/distribution/DistSyncTxFuncTest.java
   trunk/core/src/test/java/org/infinispan/distribution/rehash/SingleJoinTest.java
   trunk/core/src/test/java/org/infinispan/eviction/BaseEvictionFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/expiry/ExpiryTest.java
   trunk/core/src/test/java/org/infinispan/expiry/ReplicatedExpiryTest.java
   trunk/core/src/test/java/org/infinispan/interceptors/MarshalledValueInterceptorTest.java
   trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPIAsyncInvalTest.java
   trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPISyncInvalTest.java
   trunk/core/src/test/java/org/infinispan/invalidation/BaseInvalidationTest.java
   trunk/core/src/test/java/org/infinispan/jmx/ActivationAndPassivationInterceptorMBeanTest.java
   trunk/core/src/test/java/org/infinispan/jmx/CacheLoaderAndCacheStoreInterceptorMBeanTest.java
   trunk/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/jmx/TxInterceptorMBeanTest.java
   trunk/core/src/test/java/org/infinispan/loaders/BaseCacheStoreTest.java
   trunk/core/src/test/java/org/infinispan/loaders/CacheLoaderFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/loaders/ClusterCacheLoaderTest.java
   trunk/core/src/test/java/org/infinispan/loaders/ConcurrentLoadAndEvictTest.java
   trunk/core/src/test/java/org/infinispan/loaders/PassivationFunctionalTest.java
   trunk/core/src/test/java/org/infinispan/loaders/decorators/ChainingCacheLoaderTest.java
   trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreTest.java
   trunk/core/src/test/java/org/infinispan/manager/CacheManagerXmlConfigurationTest.java
   trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java
   trunk/core/src/test/java/org/infinispan/notifications/AsyncNotificationTest.java
   trunk/core/src/test/java/org/infinispan/notifications/CacheListenerRemovalTest.java
   trunk/core/src/test/java/org/infinispan/notifications/ConcurrentNotificationTest.java
   trunk/core/src/test/java/org/infinispan/notifications/cachelistener/CacheNotifierTest.java
   trunk/core/src/test/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierTest.java
   trunk/core/src/test/java/org/infinispan/remoting/TransportSenderExceptionHandlingTest.java
   trunk/core/src/test/java/org/infinispan/replication/AsyncAPIAsyncReplTest.java
   trunk/core/src/test/java/org/infinispan/replication/AsyncAPISyncReplTest.java
   trunk/core/src/test/java/org/infinispan/replication/AsyncReplTest.java
   trunk/core/src/test/java/org/infinispan/replication/BaseReplicatedAPITest.java
   trunk/core/src/test/java/org/infinispan/replication/ReplicationExceptionTest.java
   trunk/core/src/test/java/org/infinispan/replication/ReplicationQueueTest.java
   trunk/core/src/test/java/org/infinispan/replication/SyncCacheListenerTest.java
   trunk/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java
   trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
   trunk/core/src/test/java/org/infinispan/replication/SyncReplTest.java
   trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
   trunk/core/src/test/java/org/infinispan/tx/LargeTransactionTest.java
   trunk/core/src/test/java/org/infinispan/tx/LocalDeadlockDetectionTest.java
   trunk/core/src/test/java/org/infinispan/tx/LocalModeTxTest.java
   trunk/core/src/test/java/org/infinispan/tx/ReplDeadlockDetectionTest.java
Log:
[ISPN-220] - Test suite has memory leaks

Modified: trunk/core/src/test/java/org/infinispan/api/AsyncAPITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/AsyncAPITest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/api/AsyncAPITest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -1,15 +1,16 @@
 package org.infinispan.api;
 
+import java.util.Collections;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
 import org.infinispan.Cache;
 import org.infinispan.manager.CacheManager;
 import org.infinispan.test.SingleCacheManagerTest;
 import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
-import java.util.Collections;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-
 @Test(groups = "functional", testName = "api.AsyncAPITest")
 public class AsyncAPITest extends SingleCacheManagerTest {
    Cache<String, String> c;
@@ -19,7 +20,13 @@
       c = cm.getCache();
       return cm;
    }
-
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroyAfterClass() { 
+      super.destroyAfterClass();
+      c = null;
+   }
+  
    public void testAsyncMethods() throws ExecutionException, InterruptedException {
       // put
       Future<String> f = c.putAsync("k", "v");

Modified: trunk/core/src/test/java/org/infinispan/api/CacheAPITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/CacheAPITest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/api/CacheAPITest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -25,8 +25,7 @@
  * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
  */
 @Test(groups = "functional")
-public abstract class CacheAPITest extends SingleCacheManagerTest {
-   protected Cache cache;
+public abstract class CacheAPITest extends SingleCacheManagerTest {  
 
    protected CacheManager createCacheManager() throws Exception {
       // start a single cache instance

Modified: trunk/core/src/test/java/org/infinispan/api/CacheClusterJoinTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/CacheClusterJoinTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/api/CacheClusterJoinTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -6,6 +6,7 @@
 import org.infinispan.manager.CacheManager;
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.infinispan.test.TestingUtil;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 import java.util.List;
@@ -50,6 +51,16 @@
       assert 1 == memb2.size();
       assert !coord.equals(memb2.get(0));
    }
+   
+   @AfterClass(alwaysRun=true)
+   public void destroy() {
+      super.destroy();
+      cache1=null;
+      cache2=null;
+      cm1 = null;
+      cm2 = null;
+      cfg = null;
+   }
 
    public void testIsCoordinator() throws Exception {
       cm1.getCache("cache"); // this will make sure any lazy components are started.

Modified: trunk/core/src/test/java/org/infinispan/api/MixedModeTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/MixedModeTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/api/MixedModeTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -8,11 +8,6 @@
 
 @Test(groups = "functional", testName = "api.MixedModeTest")
 public class MixedModeTest extends MultipleCacheManagersTest {
-   AdvancedCache replSyncCache1, replSyncCache2;
-   AdvancedCache replAsyncCache1, replAsyncCache2;
-   AdvancedCache invalAsyncCache1, invalAsyncCache2;
-   AdvancedCache invalSyncCache1, invalSyncCache2;
-   AdvancedCache localCache1, localCache2;
 
    protected void createCacheManagers() throws Throwable {
       Configuration replSync = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
@@ -27,6 +22,16 @@
       defineConfigurationOnAllManagers("invalAsync", invalAsync);
       defineConfigurationOnAllManagers("local", local);
 
+   }
+
+   public void testMixedMode() {
+
+      AdvancedCache replSyncCache1, replSyncCache2;
+      AdvancedCache replAsyncCache1, replAsyncCache2;
+      AdvancedCache invalAsyncCache1, invalAsyncCache2;
+      AdvancedCache invalSyncCache1, invalSyncCache2;
+      AdvancedCache localCache1, localCache2;
+
       replSyncCache1 = cache(0, "replSync").getAdvancedCache();
       replSyncCache2 = cache(1, "replSync").getAdvancedCache();
       replAsyncCache1 = cache(0, "replAsync").getAdvancedCache();
@@ -37,11 +42,7 @@
       invalAsyncCache2 = cache(1, "invalAsync").getAdvancedCache();
       localCache1 = cache(0, "local").getAdvancedCache();
       localCache2 = cache(1, "local").getAdvancedCache();
-   }
 
-
-   public void testMixedMode() {
-
       invalSyncCache2.put("k", "v", Flag.CACHE_MODE_LOCAL);
       assert invalSyncCache2.get("k").equals("v");
       assert invalSyncCache1.get("k") == null;

Modified: trunk/core/src/test/java/org/infinispan/api/batch/BatchWithTMTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/batch/BatchWithTMTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/api/batch/BatchWithTMTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -26,6 +26,7 @@
    @AfterClass
    public void destroyCacheManager() {
       TestingUtil.killCacheManagers(cm);
+      cm = null;
    }
 
    public void testBatchWithOngoingTM() throws Exception {

Modified: trunk/core/src/test/java/org/infinispan/api/batch/BatchWithoutTMTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/batch/BatchWithoutTMTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/api/batch/BatchWithoutTMTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -23,6 +23,7 @@
    @AfterClass
    public void destroyCacheManager() {
       TestingUtil.killCacheManagers(cm);
+      cm = null;
    }
 
    public void testBatchWithoutCfg() {

Modified: trunk/core/src/test/java/org/infinispan/api/mvcc/LockPerEntryTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/mvcc/LockPerEntryTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/api/mvcc/LockPerEntryTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -1,6 +1,5 @@
 package org.infinispan.api.mvcc;
 
-import org.infinispan.Cache;
 import org.infinispan.config.Configuration;
 import org.infinispan.context.InvocationContextContainer;
 import org.infinispan.manager.CacheManager;
@@ -16,8 +15,7 @@
 import java.util.concurrent.CountDownLatch;
 
 @Test(groups = "functional", sequential = true, testName = "api.mvcc.LockPerEntryTest")
-public class LockPerEntryTest extends SingleCacheManagerTest {
-   Cache cache;
+public class LockPerEntryTest extends SingleCacheManagerTest {   
 
    protected CacheManager createCacheManager() throws Exception {
       Configuration cfg = new Configuration();

Modified: trunk/core/src/test/java/org/infinispan/api/mvcc/repeatable_read/WriteSkewTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/api/mvcc/repeatable_read/WriteSkewTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/api/mvcc/repeatable_read/WriteSkewTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -39,6 +39,11 @@
    @AfterTest
    public void tearDown() {
       TestingUtil.killCacheManagers(cacheManager);
+      cacheManager = null;
+      cache =null;
+      lockManager = null;
+      tm = null;
+      icc = null;
    }
 
    private void postStart() {

Modified: trunk/core/src/test/java/org/infinispan/atomic/APITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/APITest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/atomic/APITest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -43,7 +43,7 @@
    TransactionManager tm;
 
    @BeforeTest
-   private void setUp() {
+   public void setUp() {
       Configuration c = new Configuration();
       c.setInvocationBatchingEnabled(true);
       cache = TestCacheManagerFactory.createCacheManager(c, true).getCache();
@@ -51,12 +51,14 @@
    }
 
    @AfterTest
-   private void tearDown() {
+   public void tearDown() {
       TestingUtil.killCaches(cache);
+      cache =null;
+      tm = null;
    }
 
    @AfterMethod
-   private void clearUp() throws SystemException {
+   public void clearUp() throws SystemException {
       if (tm.getTransaction() != null) {
          try {
             tm.rollback();

Modified: trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/atomic/AtomicMapFunctionalTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -37,6 +37,8 @@
    @AfterMethod
    public void tearDown() {
       TestingUtil.killCaches(cache);
+      cache = null;
+      tm = null;
    }
 
    public void testChangesOnAtomicMap() {

Modified: trunk/core/src/test/java/org/infinispan/atomic/ClusteredAPITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/atomic/ClusteredAPITest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/atomic/ClusteredAPITest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -1,30 +1,29 @@
 package org.infinispan.atomic;
 
-import org.infinispan.Cache;
 import static org.infinispan.atomic.AtomicHashMapTestAssertions.assertIsEmpty;
 import static org.infinispan.atomic.AtomicHashMapTestAssertions.assertIsEmptyMap;
+
+import org.infinispan.Cache;
 import org.infinispan.config.Configuration;
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.infinispan.test.TestingUtil;
 import org.testng.annotations.Test;
 
-import java.util.List;
-
-
 @Test(groups = "functional", testName = "atomic.ClusteredAPITest")
 public class ClusteredAPITest extends MultipleCacheManagersTest {
-   Cache<String, Object> cache1, cache2;
 
    protected void createCacheManagers() throws Throwable {
       Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC, true);
       c.setInvocationBatchingEnabled(true);
 
-      List<Cache<String, Object>> caches = createClusteredCaches(2, "atomic", c);
-      cache1 = caches.get(0);
-      cache2 = caches.get(1);
+      createClusteredCaches(2, "atomic", c);
+
    }
 
    public void testReplicationCommit() throws Exception {
+      Cache<String, Object> cache1 = cache(0, "atomic");
+      Cache<String, Object> cache2 = cache(1, "atomic");
+
       AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache1, "map");
 
       TestingUtil.getTransactionManager(cache1).begin();
@@ -42,6 +41,8 @@
    }
 
    public void testReplicationRollback() throws Exception {
+      Cache<String, Object> cache1 = cache(0, "atomic");
+      Cache<String, Object> cache2 = cache(1, "atomic");
       assertIsEmptyMap(cache2, "map");
       AtomicMap<String, String> map = AtomicMapLookup.getAtomicMap(cache1, "map");
 

Modified: trunk/core/src/test/java/org/infinispan/distribution/AsyncAPIAsyncDistTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/AsyncAPIAsyncDistTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/distribution/AsyncAPIAsyncDistTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -3,6 +3,7 @@
 import org.infinispan.commands.write.WriteCommand;
 import org.infinispan.test.AbstractCacheTest;
 import org.infinispan.test.ReplListener;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 import java.util.concurrent.TimeUnit;
@@ -31,6 +32,12 @@
    protected void resetListeners() {
       rl.resetEager();
    }
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroy() {     
+      super.destroy();
+      rl = null;
+   }
 
    @Override
    protected void asyncWait(boolean tx, Class<? extends WriteCommand>... cmds) {

Modified: trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/distribution/BaseDistFunctionalTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -65,9 +65,11 @@
    }
    
    @AfterClass(alwaysRun=true)
-   protected void destroy() {
+   public void destroy() {
       super.destroy();     
       caches.clear();
+      caches = null;
+      configuration=null;
       c1 = null;c2=null;c3=null;c4=null;
    }
 

Modified: trunk/core/src/test/java/org/infinispan/distribution/DistAsyncFuncTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/DistAsyncFuncTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/distribution/DistAsyncFuncTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -5,8 +5,10 @@
 import org.infinispan.commands.write.InvalidateL1Command;
 import org.infinispan.test.ReplListener;
 import org.infinispan.test.TestingUtil;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -34,6 +36,14 @@
       listenerLookup = new HashMap<Cache<?, ?>, ReplListener>();
       for (ReplListener rl : r) listenerLookup.put(rl.getCache(), rl);
    }
+   
+   @AfterClass(alwaysRun=true)
+   public void destroy() {
+      super.destroy();           
+      r1=null;r2=null;r3=null;r4=null;
+      Arrays.fill(r, null);
+      listenerLookup.clear();
+   }
 
 
    @Override

Modified: trunk/core/src/test/java/org/infinispan/distribution/DistAsyncTxFuncTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/DistAsyncTxFuncTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/distribution/DistAsyncTxFuncTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -6,6 +6,7 @@
 import org.infinispan.remoting.transport.Address;
 import org.infinispan.test.ReplListener;
 import org.infinispan.test.TestingUtil;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 import java.util.ArrayList;
@@ -47,6 +48,15 @@
          listenerLookup.put(rl.getCache(), rl);
       }
    }
+   
+   @AfterClass(alwaysRun=true)
+   public void destroy() {
+      super.destroy();           
+      r1=null;r2=null;r3=null;r4=null;
+      Arrays.fill(r, null);
+      listenerLookup.clear();
+      listenerCaches.clear();
+   }
 
    @Override
    protected void asyncWait(Object key, Class<? extends VisitableCommand> command, Cache<?, ?>... cachesOnWhichKeyShouldInval) {

Modified: trunk/core/src/test/java/org/infinispan/distribution/DistAsyncTxUnsafeFuncTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/DistAsyncTxUnsafeFuncTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/distribution/DistAsyncTxUnsafeFuncTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -1,5 +1,6 @@
 package org.infinispan.distribution;
 
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 @Test(groups = "functional", testName = "distribution.DistAsyncTxUnsafeFuncTest")
@@ -10,4 +11,8 @@
       testRetVals = false;
       cleanup = CleanupPhase.AFTER_METHOD; // ensure any stale TXs are wiped
    }
+   @AfterClass(alwaysRun=true)
+   public void destroy() {
+      super.destroy();           
+   }
 }

Modified: trunk/core/src/test/java/org/infinispan/distribution/DistSyncTxFuncTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/DistSyncTxFuncTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/distribution/DistSyncTxFuncTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -10,6 +10,7 @@
 
 @Test(groups = "functional", testName = "distribution.DistSyncTxFuncTest")
 public class DistSyncTxFuncTest extends BaseDistFunctionalTest {
+   
    public DistSyncTxFuncTest() {
       sync = true;
       tx = true;

Modified: trunk/core/src/test/java/org/infinispan/distribution/rehash/SingleJoinTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/distribution/rehash/SingleJoinTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/distribution/rehash/SingleJoinTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -2,6 +2,7 @@
 
 import org.infinispan.Cache;
 import org.infinispan.manager.CacheManager;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 import static java.util.concurrent.TimeUnit.SECONDS;
@@ -16,6 +17,13 @@
       joinerManager.defineConfiguration(cacheName, configuration);
       joiner = joinerManager.getCache(cacheName);
    }
+   
+   @AfterClass(alwaysRun=true)
+   public void destroy() {
+      super.destroy();     
+      joiner = null;
+      joinerManager=null;
+   }
 
    void waitForRehashCompletion() {
       // need to block until this join has completed!

Modified: trunk/core/src/test/java/org/infinispan/eviction/BaseEvictionFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/eviction/BaseEvictionFunctionalTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/eviction/BaseEvictionFunctionalTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -12,9 +12,7 @@
 
 @Test(groups = "functional", testName = "eviction.BaseEvictionFunctionalTest")
 public abstract class BaseEvictionFunctionalTest extends SingleCacheManagerTest {
-
-   Cache cache;
-
+   
    protected BaseEvictionFunctionalTest() {
       cleanup = CleanupPhase.AFTER_METHOD;
    }

Modified: trunk/core/src/test/java/org/infinispan/expiry/ExpiryTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/expiry/ExpiryTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/expiry/ExpiryTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -28,6 +28,7 @@
    @AfterMethod
    public void tearDown() {
       TestingUtil.killCacheManagers(cm);
+      cm = null;
    }
 
    public void testLifespanExpiryInPut() throws InterruptedException {

Modified: trunk/core/src/test/java/org/infinispan/expiry/ReplicatedExpiryTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/expiry/ReplicatedExpiryTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/expiry/ReplicatedExpiryTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -9,22 +9,19 @@
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.testng.annotations.Test;
 
-import java.util.List;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 @Test(groups = "functional", testName = "expiry.ReplicatedExpiryTest")
 public class ReplicatedExpiryTest extends MultipleCacheManagersTest {
 
-   Cache c1, c2;
-
    protected void createCacheManagers() throws Throwable {
       Configuration cfg = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
-      List<Cache<Object, Object>> caches = createClusteredCaches(2, "cache", cfg);
-      c1 = caches.get(0);
-      c2 = caches.get(1);
+      createClusteredCaches(2, "cache", cfg);      
    }
 
    public void testLifespanExpiryReplicates() throws InterruptedException {
+      Cache c1 = cache(0,"cache");
+      Cache c2 = cache(1,"cache");
       long lifespan = 3000;
       c1.put("k", "v", lifespan, MILLISECONDS);
       InternalCacheEntry ice = c2.getAdvancedCache().getDataContainer().get("k");
@@ -35,6 +32,8 @@
    }
 
    public void testIdleExpiryReplicates() throws InterruptedException {
+      Cache c1 = cache(0,"cache");
+      Cache c2 = cache(1,"cache");
       long idle = 3000;
       c1.put("k", "v", -1, MILLISECONDS, idle, MILLISECONDS);
       InternalCacheEntry ice = c2.getAdvancedCache().getDataContainer().get("k");
@@ -45,6 +44,8 @@
    }
 
    public void testBothExpiryReplicates() throws InterruptedException {
+      Cache c1 = cache(0,"cache");
+      Cache c2 = cache(1,"cache");
       long lifespan = 10000;
       long idle = 3000;
       c1.put("k", "v", lifespan, MILLISECONDS, idle, MILLISECONDS);

Modified: trunk/core/src/test/java/org/infinispan/interceptors/MarshalledValueInterceptorTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/interceptors/MarshalledValueInterceptorTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/interceptors/MarshalledValueInterceptorTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -32,6 +32,7 @@
    @AfterTest
    public void tearDown() {
       TestingUtil.killCacheManagers(cm);
+      cm = null;
    }
 
    public void testDefaultInterceptorStack() {

Modified: trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPIAsyncInvalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPIAsyncInvalTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPIAsyncInvalTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -1,8 +1,10 @@
 package org.infinispan.invalidation;
 
+import org.infinispan.Cache;
 import org.infinispan.commands.write.WriteCommand;
 import org.infinispan.test.AbstractCacheTest;
 import org.infinispan.test.ReplListener;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 @Test(groups = "functional", testName = "invalidation.AsyncAPIAsyncInvalTest")
@@ -16,6 +18,7 @@
    @Override
    protected void createCacheManagers() throws Throwable {
       super.createCacheManagers();
+      Cache c2 = cache(1, super.getClass().getSimpleName());
       rl = new ReplListener(c2, true);
    }
 
@@ -23,6 +26,12 @@
    protected boolean sync() {
       return false;
    }
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroy() {     
+      super.destroy();
+      rl = null;
+   }
 
    @Override
    protected void resetListeners() {

Modified: trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPISyncInvalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPISyncInvalTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/invalidation/AsyncAPISyncInvalTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -10,22 +10,18 @@
 import org.testng.annotations.Test;
 
 import java.util.Collections;
-import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
 @Test(groups = "functional", testName = "invalidation.AsyncAPISyncInvalTest")
-public class AsyncAPISyncInvalTest extends MultipleCacheManagersTest {
+public class AsyncAPISyncInvalTest extends MultipleCacheManagersTest {   
 
-   Cache<Key, String> c1, c2;
-
    @SuppressWarnings("unchecked")
    protected void createCacheManagers() throws Throwable {
-      Configuration c =
-            getDefaultClusteredConfig(sync() ? Configuration.CacheMode.INVALIDATION_SYNC : Configuration.CacheMode.INVALIDATION_ASYNC, true);
-      List<Cache<Key, String>> l = createClusteredCaches(2, getClass().getSimpleName(), c);
-      c1 = l.get(0);
-      c2 = l.get(1);
+      Configuration c = getDefaultClusteredConfig(
+               sync() ? Configuration.CacheMode.INVALIDATION_SYNC
+                        : Configuration.CacheMode.INVALIDATION_ASYNC, true);
+      createClusteredCaches(2, getClass().getSimpleName(), c);
    }
 
    protected boolean sync() {
@@ -39,16 +35,22 @@
    }
 
    private void assertInvalidated(Key k, String value) {
+      Cache c1 = cache(0,getClass().getSimpleName());
+      Cache c2 = cache(1,getClass().getSimpleName());
       assert Util.safeEquals(c1.get(k), value);
       assert !c2.containsKey(k);
    }
 
    private void initC2(Key k) {
+      Cache c1 = cache(0,getClass().getSimpleName());
+      Cache c2 = cache(1,getClass().getSimpleName());
       c2.getAdvancedCache().put(k, "v", Flag.CACHE_MODE_LOCAL);
    }
 
    public void testAsyncMethods() throws ExecutionException, InterruptedException {
 
+      Cache c1 = cache(0,getClass().getSimpleName());
+      Cache c2 = cache(1,getClass().getSimpleName());
       String v = "v";
       String v2 = "v2";
       String v3 = "v3";

Modified: trunk/core/src/test/java/org/infinispan/invalidation/BaseInvalidationTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/invalidation/BaseInvalidationTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/invalidation/BaseInvalidationTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -2,7 +2,6 @@
 
 import static org.easymock.EasyMock.*;
 import org.infinispan.AdvancedCache;
-import org.infinispan.Cache;
 import org.infinispan.api.mvcc.LockAssert;
 import org.infinispan.commands.remote.CacheRpcCommand;
 import org.infinispan.commands.write.ClearCommand;
@@ -29,7 +28,6 @@
 
 @Test(groups = "functional")
 public abstract class BaseInvalidationTest extends MultipleCacheManagersTest {
-   protected AdvancedCache cache1, cache2;
    protected boolean isSync;
 
    protected BaseInvalidationTest() {
@@ -40,12 +38,13 @@
       Configuration c = getDefaultClusteredConfig(isSync ? Configuration.CacheMode.INVALIDATION_SYNC : Configuration.CacheMode.INVALIDATION_ASYNC, true);
       c.setStateRetrievalTimeout(1000);
       c.setLockAcquisitionTimeout(500);
-      List<Cache<Object, Object>> caches = createClusteredCaches(2, "invalidation", c);
-      cache1 = caches.get(0).getAdvancedCache();
-      cache2 = caches.get(1).getAdvancedCache();
+      createClusteredCaches(2, "invalidation", c);
+
    }
 
    public void testRemove() throws Exception {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       cache1.put("key", "value", Flag.CACHE_MODE_LOCAL);
       assertEquals("value", cache1.get("key"));
       cache2.put("key", "value", Flag.CACHE_MODE_LOCAL);
@@ -59,6 +58,8 @@
    }
 
    public void testResurrectEntry() throws Exception {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       replListener(cache2).expect(InvalidateCommand.class);
       cache1.put("key", "value");
       replListener(cache2).waitForRpc();
@@ -96,6 +97,9 @@
    }
 
    public void testDeleteNonExistentEntry() throws Exception {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
+      
       assertNull("Should be null", cache1.get("key"));
       assertNull("Should be null", cache2.get("key"));
 
@@ -120,6 +124,8 @@
    }
 
    public void testTxSyncUnableToInvalidate() throws Exception {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       replListener(cache2).expect(InvalidateCommand.class);
       cache1.put("key", "value");
       replListener(cache2).waitForRpc();
@@ -177,6 +183,8 @@
    }
 
    public void testCacheMode() throws Exception {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       RpcManagerImpl rpcManager = (RpcManagerImpl) TestingUtil.extractComponent(cache1, RpcManager.class);
       Transport origTransport = TestingUtil.extractComponent(cache1, Transport.class);
       try {
@@ -204,6 +212,8 @@
    }
 
    public void testPutIfAbsent() {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       assert null == cache2.put("key", "value", Flag.CACHE_MODE_LOCAL);
       assert cache2.get("key").equals("value");
       assert cache1.get("key") == null;
@@ -227,6 +237,8 @@
    }
 
    public void testRemoveIfPresent() {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key").equals("value1");
@@ -246,6 +258,8 @@
    }
 
    public void testClear() {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key").equals("value1");
@@ -260,6 +274,8 @@
    }
 
    public void testReplace() {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
@@ -280,6 +296,8 @@
    }
 
    public void testReplaceWithOldVal() {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
@@ -305,6 +323,8 @@
    }
 
    public void testLocalOnlyClear() {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key").equals("value1");
@@ -318,6 +338,8 @@
    }
 
    public void testPutForExternalRead() throws Exception {
+      AdvancedCache cache1 = cache(0,"invalidation").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"invalidation").getAdvancedCache();
       cache1.putForExternalRead("key", "value1");
       Thread.sleep(500); // sleep so that async invalidation (result of PFER) is propagated
       cache2.putForExternalRead("key", "value2");

Modified: trunk/core/src/test/java/org/infinispan/jmx/ActivationAndPassivationInterceptorMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/ActivationAndPassivationInterceptorMBeanTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/jmx/ActivationAndPassivationInterceptorMBeanTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -11,7 +11,9 @@
 import org.infinispan.manager.CacheManager;
 import org.infinispan.test.SingleCacheManagerTest;
 import org.infinispan.test.TestingUtil;
+import org.infinispan.test.AbstractCacheTest.CleanupPhase;
 import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
@@ -63,6 +65,16 @@
    public void resetStats() throws Exception {
       threadMBeanServer.invoke(activationInterceptorObjName, "resetStatistics", new Object[0], new String[0]);
    }
+   
+   @AfterClass(alwaysRun = true)
+   protected void destroyAfterClass() {
+      super.destroyAfterClass();
+      cache = null;
+      threadMBeanServer = null;
+      activationInterceptorObjName = null;
+      passivationInterceptorObjName = null;
+      cacheStore = null;
+   }
 
    public void testDisbaleStatistics() throws Exception {
       threadMBeanServer.setAttribute(activationInterceptorObjName, new Attribute("StatisticsEnabled", Boolean.FALSE));

Modified: trunk/core/src/test/java/org/infinispan/jmx/CacheLoaderAndCacheStoreInterceptorMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/CacheLoaderAndCacheStoreInterceptorMBeanTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/jmx/CacheLoaderAndCacheStoreInterceptorMBeanTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -11,6 +11,7 @@
 import org.infinispan.test.SingleCacheManagerTest;
 import org.infinispan.test.TestingUtil;
 import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
@@ -60,6 +61,13 @@
       threadMBeanServer.invoke(loaderInterceptorObjName, "resetStatistics", new Object[0], new String[0]);
       threadMBeanServer.invoke(storeInterceptorObjName, "resetStatistics", new Object[0], new String[0]);
    }
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroyAfterClass() {      
+      super.destroyAfterClass();
+      cacheStore = null; threadMBeanServer =null;storeInterceptorObjName=null;
+      loaderInterceptorObjName =null;
+   }
 
 
    public void testPutKeyValue() throws Exception {

Modified: trunk/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/jmx/JmxStatsFunctionalTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -31,9 +31,11 @@
    private CacheManager cm, cm2, cm3;
 
 
-   @AfterMethod
+   @AfterMethod(alwaysRun=true)
    public void destroyCacheManager() {
       TestingUtil.killCacheManagers(cm, cm2, cm3);
+      cm=null;cm2=null;cm3=null;
+      server=null;
       assert !existsDomains("infinispan");
    }
 

Modified: trunk/core/src/test/java/org/infinispan/jmx/TxInterceptorMBeanTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/jmx/TxInterceptorMBeanTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/jmx/TxInterceptorMBeanTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -7,6 +7,7 @@
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.infinispan.test.TestingUtil;
 import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 
@@ -50,9 +51,20 @@
    public void resetStats() throws Exception {
       threadMBeanServer.invoke(txInterceptor, "resetStatistics", new Object[0], new String[0]);
    }
+   
+   @AfterClass(alwaysRun=true)
+   public void destroy() {
+      super.destroy();
+      cache1 = null;
+      cache2 = null;
+      tm = null;
+      threadMBeanServer = null;
+      txInterceptor = null;
+   }
 
 
    public void testCommit() throws Exception {
+      
       assertCommitRollback(0, 0);
       tm.begin();
       assertCommitRollback(0, 0);

Modified: trunk/core/src/test/java/org/infinispan/loaders/BaseCacheStoreTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/BaseCacheStoreTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/loaders/BaseCacheStoreTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -60,11 +60,14 @@
 
    @AfterMethod
    public void tearDown() throws CacheLoaderException {
-      if (cs != null) {
-         cs.clear();
-         cs.stop();
+      try {
+         if (cs != null) {
+            cs.clear();
+            cs.stop();
+         }
+      } finally {
+         cs = null;
       }
-      cs = null;
    }
 
    @AfterMethod

Modified: trunk/core/src/test/java/org/infinispan/loaders/CacheLoaderFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/CacheLoaderFunctionalTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/loaders/CacheLoaderFunctionalTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -51,6 +51,11 @@
    @AfterTest
    public void tearDown() {
       TestingUtil.killCacheManagers(cm);
+      cache = null;
+      cm = null;
+      cfg = null;
+      tm = null;
+      store = null;
    }
 
    @AfterMethod

Modified: trunk/core/src/test/java/org/infinispan/loaders/ClusterCacheLoaderTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/ClusterCacheLoaderTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/loaders/ClusterCacheLoaderTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -19,9 +19,6 @@
  */
 @Test(groups = "functional", testName = "loaders.ClusterCacheLoaderTest")
 public class ClusterCacheLoaderTest extends MultipleCacheManagersTest {
-   private Cache cache1;
-   private Cache cache2;
-   private CacheStore cs2;
 
    protected void createCacheManagers() throws Throwable {
       CacheManager cacheManager1 = TestCacheManagerFactory.createClusteredCacheManager();
@@ -43,14 +40,14 @@
 
       cacheManager1.defineConfiguration("clusteredCl", config1);
       cacheManager2.defineConfiguration("clusteredCl", config2);
-      cache1 = cache(0, "clusteredCl");
-      cache2 = cache(1, "clusteredCl");
-      CacheLoaderManager manager2 = cache2.getAdvancedCache().getComponentRegistry().getComponent(CacheLoaderManager.class);
-      ChainingCacheStore chainingCacheStore = (ChainingCacheStore) manager2.getCacheStore();
-      cs2 = chainingCacheStore.getStores().keySet().iterator().next();
+      Cache cache1 = cache(0, "clusteredCl");
+      Cache cache2 = cache(1, "clusteredCl");
+      
    }
 
    public void testRemoteLoad() {
+      Cache cache1 = cache(0, "clusteredCl");
+      Cache cache2 = cache(1, "clusteredCl");
       assert cache1.get("key") == null;
       assert cache1.get("key") == null;
       cache2.put("key", "value");
@@ -58,6 +55,12 @@
    }
 
    public void testRemoteLoadFromCacheLoader() throws Exception {
+      Cache cache1 = cache(0, "clusteredCl");
+      Cache cache2 = cache(1, "clusteredCl");
+      CacheLoaderManager manager2 = cache2.getAdvancedCache().getComponentRegistry().getComponent(CacheLoaderManager.class);
+      ChainingCacheStore chainingCacheStore = (ChainingCacheStore) manager2.getCacheStore();
+      CacheStore cs2 = chainingCacheStore.getStores().keySet().iterator().next();
+      
       assert cache1.get("key") == null;
       assert cache2.get("key") == null;
       cs2.store(InternalEntryFactory.create("key", "value"));

Modified: trunk/core/src/test/java/org/infinispan/loaders/ConcurrentLoadAndEvictTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/ConcurrentLoadAndEvictTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/loaders/ConcurrentLoadAndEvictTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -16,6 +16,7 @@
 import org.infinispan.test.SingleCacheManagerTest;
 import org.infinispan.test.TestingUtil;
 import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 import java.util.Collections;
@@ -54,6 +55,12 @@
       config.setCustomInterceptors(Collections.singletonList(cic));
       return TestCacheManagerFactory.createCacheManager(config);
    }
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroyAfterClass() {
+      super.destroyAfterClass();
+      sdi = null;
+   }
 
    public void testEvictBeforeRead() throws CacheLoaderException, ExecutionException, InterruptedException {
       cache = cacheManager.getCache();

Modified: trunk/core/src/test/java/org/infinispan/loaders/PassivationFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/PassivationFunctionalTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/loaders/PassivationFunctionalTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -49,6 +49,11 @@
    @AfterTest
    public void tearDown() {
       TestingUtil.killCacheManagers(cm);
+      cm = null;
+      cfg = null;
+      store = null;
+      cache = null;
+      tm = null;
    }
 
    @AfterMethod

Modified: trunk/core/src/test/java/org/infinispan/loaders/decorators/ChainingCacheLoaderTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/decorators/ChainingCacheLoaderTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/loaders/decorators/ChainingCacheLoaderTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
@@ -59,8 +60,16 @@
 
    @AfterMethod
    public void afterMethod() {
-      if (store1 != null) store1.clear();
-      if (store2 != null) store2.clear();
+      try {
+         if (store1 != null)
+            store1.clear();
+         if (store2 != null)
+            store2.clear();
+      } finally {
+         store1 = null;
+         store2 = null;
+         Arrays.fill(stores, null);
+      }
    }
 
    public void testPropagatingWrites() throws Exception {

Modified: trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/loaders/file/FileCacheStoreTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -10,6 +10,8 @@
 import org.infinispan.loaders.bucket.Bucket;
 import org.infinispan.marshall.Marshaller;
 import org.infinispan.test.TestingUtil;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.AfterTest;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Parameters;
@@ -51,6 +53,13 @@
       fcs.start();
       return fcs;
    }
+   
+   @AfterClass(alwaysRun=true)
+   public void tearDown() throws CacheLoaderException {
+      super.tearDown();
+      fcs = null;
+      tmpDirectory = null;
+   }
 
    @Override
    public void testPreload() throws CacheLoaderException {

Modified: trunk/core/src/test/java/org/infinispan/manager/CacheManagerXmlConfigurationTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/manager/CacheManagerXmlConfigurationTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/manager/CacheManagerXmlConfigurationTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -22,6 +22,7 @@
    @AfterMethod
    public void tearDown() {
       if (cm != null) cm.stop();
+      cm =null;
    }
 
    public void testNamedCacheXML() throws IOException {

Modified: trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/marshall/MarshalledValueTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -40,9 +40,11 @@
 import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.infinispan.test.TestingUtil;
+import org.infinispan.test.AbstractCacheTest.CleanupPhase;
 import org.infinispan.util.ObjectDuplicator;
 import org.infinispan.util.logging.Log;
 import org.infinispan.util.logging.LogFactory;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -71,13 +73,13 @@
  * @since 4.0
  */
 @Test(groups = "functional", testName = "marshall.MarshalledValueTest")
-public class MarshalledValueTest extends MultipleCacheManagersTest {
-   private Cache cache1, cache2;
+public class MarshalledValueTest extends MultipleCacheManagersTest {   
    private MarshalledValueListenerInterceptor mvli;
    String k = "key", v = "value";
    private VersionAwareMarshaller marshaller;
 
    protected void createCacheManagers() throws Throwable {
+      Cache cache1, cache2;
       Configuration replSync = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
       replSync.setUseLazyDeserialization(true);
 
@@ -97,6 +99,9 @@
 
    @BeforeMethod
    public void addMarshalledValueInterceptor() {
+      Cache cache1, cache2;
+      cache1 = cache(0, "replSync");
+      cache2 = cache(1, "replSync");
       InterceptorChain chain = TestingUtil.extractComponent(cache1, InterceptorChain.class);
       chain.removeInterceptor(MarshalledValueListenerInterceptor.class);
       mvli = new MarshalledValueListenerInterceptor();
@@ -106,6 +111,16 @@
       marshaller.inject(Thread.currentThread().getContextClassLoader(), null);
       marshaller.start();
    }
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroy() {     
+      super.destroy();
+      if(marshaller != null) {
+         marshaller.stop();
+         marshaller = null;
+      }
+      mvli = null;
+   }
 
    @AfterMethod
    public void tearDown() {
@@ -130,7 +145,9 @@
       assert Pojo.deserializationCount == deserializationCount : "Deserialization count: expected " + deserializationCount + " but was " + Pojo.deserializationCount;
    }
 
-   public void testNonSerializable() {
+   public void testNonSerializable() {      
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       try {
          cache1.put("Hello", new Object());
          assert false : "Should have failed";
@@ -153,6 +170,9 @@
    }
 
    public void testReleaseObjectValueReferences() {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
+      
       assert cache1.isEmpty();
       Pojo value = new Pojo();
       System.out.println(TestingUtil.extractComponent(cache1, InterceptorChain.class).toString());
@@ -193,6 +213,8 @@
    }
 
    public void testReleaseObjectKeyReferences() throws IOException, ClassNotFoundException {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       Pojo key = new Pojo();
       cache1.put(key, "value");
 
@@ -232,6 +254,9 @@
    }
    
    public void testKeySetValuesEntrySetCollectionReferences() {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
+      
       Pojo key1 = new Pojo(), value1 = new Pojo(), key2 = new Pojo(), value2 = new Pojo();
       String key3 = "3", value3 = "three"; 
       cache1.put(key1, value1);
@@ -336,6 +361,8 @@
    }
 
    public void testMarshallValueWithCustomReadObjectMethod() {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       CustomReadObjectMethod obj = new CustomReadObjectMethod();
       cache1.put("ab-key", obj);
       assert cache2.get("ab-key").equals(obj);
@@ -385,6 +412,8 @@
     */
    @Test(dependsOnMethods = "org.infinispan.marshall.MarshalledValueTest.test(?!CacheLoaders)[a-zA-Z]*")
    public void testCacheLoaders() throws CloneNotSupportedException {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       tearDown();
 
       Configuration cacheCofig = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
@@ -412,6 +441,8 @@
    }
 
    public void testCallbackValues() {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       MockListener l = new MockListener();
       cache1.addListener(l);
       Pojo pojo = new Pojo();
@@ -425,6 +456,8 @@
    }
 
    public void testRemoteCallbackValues() throws Exception {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       MockListener l = new MockListener();
       cache2.addListener(l);
       Pojo pojo = new Pojo();
@@ -438,6 +471,8 @@
    }
    
    public void testEvictWithMarshalledValueKey() {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       Pojo pojo = new Pojo();
       cache1.put(pojo, pojo);
       cache1.evict(pojo);

Modified: trunk/core/src/test/java/org/infinispan/notifications/AsyncNotificationTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/notifications/AsyncNotificationTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/notifications/AsyncNotificationTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -26,6 +26,8 @@
    @AfterMethod
    public void tearDown() {
       TestingUtil.killCacheManagers(cm);
+      cm = null;
+      c = null;
    }
 
    public void testAsyncNotification() throws InterruptedException {

Modified: trunk/core/src/test/java/org/infinispan/notifications/CacheListenerRemovalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/notifications/CacheListenerRemovalTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/notifications/CacheListenerRemovalTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -29,6 +29,8 @@
    @AfterMethod
    public void tearDown() {
       TestingUtil.killCacheManagers(cm);
+      cm = null;
+      cache = null;
    }
 
    public void testListenerRemoval() {

Modified: trunk/core/src/test/java/org/infinispan/notifications/ConcurrentNotificationTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/notifications/ConcurrentNotificationTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/notifications/ConcurrentNotificationTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -38,6 +38,9 @@
    @AfterMethod
    public void tearDown() {
       TestingUtil.killCacheManagers(cm);
+      cm = null;
+      cache = null;
+      listener = null;
    }
 
    public void testThreads() throws Exception {

Modified: trunk/core/src/test/java/org/infinispan/notifications/cachelistener/CacheNotifierTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/notifications/cachelistener/CacheNotifierTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/notifications/cachelistener/CacheNotifierTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -48,6 +48,8 @@
    @AfterTest
    public void destroyManager() {
       TestingUtil.killCacheManagers(cache.getCacheManager());
+      cache = null; tm = null; mockNotifier = null;
+      origNotifier = null;
    }
 
    private void initCacheData(Object key, Object value) {

Modified: trunk/core/src/test/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/notifications/cachemanagerlistener/CacheManagerNotifierTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -20,6 +20,8 @@
    @AfterMethod
    public void tearDown() {
       TestingUtil.killCacheManagers(cm1, cm2);
+      cm1 = null;
+      cm2 = null;
    }
 
    public void testViewChange() {

Modified: trunk/core/src/test/java/org/infinispan/remoting/TransportSenderExceptionHandlingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/remoting/TransportSenderExceptionHandlingTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/remoting/TransportSenderExceptionHandlingTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -43,19 +43,18 @@
 @Test(groups = "functional", testName = "remoting.TransportSenderExceptionHandlingTest")
 public class TransportSenderExceptionHandlingTest extends MultipleCacheManagersTest {
    final String key = "k-illyria", value = "v-illyria", value2 = "v2-illyria";
-   Cache cache1;
-   Cache cache2;
 
+
    @Override
    protected void createCacheManagers() throws Throwable {
       Configuration c = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
       c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
-      createClusteredCaches(2, "replSync", c);
-      cache1 = cache(0, "replSync");
-      cache2 = cache(1, "replSync");
+      createClusteredCaches(2, "replSync", c);   
    }
    
    public void testInvokeAndExceptionWhileUnmarshalling() throws Exception {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       JGroupsTransport transport1 = (JGroupsTransport) TestingUtil.extractComponent(cache1, Transport.class);
       CommandAwareRpcDispatcher dispatcher1 = transport1.getCommandAwareRpcDispatcher();
       Marshaller2 originalMarshaller1 = (Marshaller2) dispatcher1.getMarshaller();

Modified: trunk/core/src/test/java/org/infinispan/replication/AsyncAPIAsyncReplTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/AsyncAPIAsyncReplTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/AsyncAPIAsyncReplTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -2,6 +2,7 @@
 
 import org.infinispan.commands.write.WriteCommand;
 import org.infinispan.test.ReplListener;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 @Test(groups = "functional", testName = "replication.AsyncAPIAsyncReplTest")
@@ -23,6 +24,12 @@
    protected boolean sync() {
       return false;
    }
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroy() {     
+      super.destroy();
+      rl = null;
+   }
 
    @Override
    protected void resetListeners() {

Modified: trunk/core/src/test/java/org/infinispan/replication/AsyncAPISyncReplTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/AsyncAPISyncReplTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/AsyncAPISyncReplTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -11,6 +11,7 @@
 import org.infinispan.test.TestingUtil;
 import org.infinispan.test.data.Key;
 import org.infinispan.util.Util;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 import javax.transaction.Transaction;
@@ -43,6 +44,12 @@
 
    protected void resetListeners() {
    }
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroy() {     
+      super.destroy();
+      c1 = null; c2 = null;
+   }
 
    protected void assertOnAllCaches(Key k, String v) {
       Object real;

Modified: trunk/core/src/test/java/org/infinispan/replication/AsyncReplTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/AsyncReplTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/AsyncReplTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -17,22 +17,20 @@
 import org.testng.annotations.Test;
 
 import javax.transaction.TransactionManager;
-import java.util.List;
 
 @Test(groups = "functional", testName = "replication.AsyncReplTest")
 public class AsyncReplTest extends MultipleCacheManagersTest {
 
-   Cache cache1, cache2;
 
    protected void createCacheManagers() throws Throwable {
       Configuration asyncConfiguration = getDefaultClusteredConfig(Configuration.CacheMode.REPL_ASYNC, true);
-      List<Cache<Object, Object>> caches = createClusteredCaches(2, "asyncRepl", asyncConfiguration);
-      cache1 = caches.get(0);
-      cache2 = caches.get(1);
+      createClusteredCaches(2, "asyncRepl", asyncConfiguration);   
    }
 
    public void testWithNoTx() throws Exception {
 
+      Cache cache1 = cache(0,"asyncRepl");
+      Cache cache2 = cache(1,"asyncRepl");
       String key = "key";
 
       replListener(cache2).expect(PutKeyValueCommand.class);
@@ -53,6 +51,9 @@
    }
 
    public void testWithTx() throws Exception {
+      Cache cache1 = cache(0,"asyncRepl");
+      Cache cache2 = cache(1,"asyncRepl");
+      
       String key = "key";
       replListener(cache2).expect(PutKeyValueCommand.class);
       cache1.put(key, "value1");
@@ -91,6 +92,9 @@
    }
 
    public void simpleTest() throws Exception {
+      Cache cache1 = cache(0,"asyncRepl");
+      Cache cache2 = cache(1,"asyncRepl");
+      
       String key = "key";
       TransactionManager mgr = TestingUtil.getTransactionManager(cache1);
 

Modified: trunk/core/src/test/java/org/infinispan/replication/BaseReplicatedAPITest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/BaseReplicatedAPITest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/BaseReplicatedAPITest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -1,7 +1,6 @@
 package org.infinispan.replication;
 
 import org.infinispan.AdvancedCache;
-import org.infinispan.Cache;
 import org.infinispan.commands.write.ClearCommand;
 import org.infinispan.commands.write.PutKeyValueCommand;
 import org.infinispan.commands.write.PutMapCommand;
@@ -13,24 +12,22 @@
 import org.testng.annotations.Test;
 
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 @Test(groups = "functional", testName = "replication.BaseReplicatedAPITest")
 public abstract class BaseReplicatedAPITest extends MultipleCacheManagersTest {
 
-   AdvancedCache cache1, cache2;
    protected boolean isSync;
 
    protected void createCacheManagers() throws Throwable {
       Configuration c = getDefaultClusteredConfig(isSync ? Configuration.CacheMode.REPL_SYNC : Configuration.CacheMode.REPL_ASYNC, true);
       c.setStateRetrievalTimeout(1000);
-      List<Cache<Object, Object>> caches = createClusteredCaches(2, "replication", c);
-      cache1 = caches.get(0).getAdvancedCache();
-      cache2 = caches.get(1).getAdvancedCache();
+      createClusteredCaches(2, "replication", c);      
    }
 
    public void put() {
+      AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
       // test a simple put!
       assert cache1.get("key") == null;
       assert cache2.get("key") == null;
@@ -59,6 +56,8 @@
    }
 
    public void remove() {
+      AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
       cache2.put("key", "value", Flag.CACHE_MODE_LOCAL);
       assert cache2.get("key").equals("value");
       assert cache1.get("key") == null;
@@ -84,6 +83,8 @@
    }
 
    public void testPutIfAbsent() {
+      AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
       cache2.put("key", "valueOld", Flag.CACHE_MODE_LOCAL);
       assert cache2.get("key").equals("valueOld");
       assert cache1.get("key") == null;
@@ -107,6 +108,8 @@
    }
 
    public void testRemoveIfPresent() {
+      AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
       cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key").equals("value1");
@@ -126,6 +129,8 @@
    }
 
    public void testClear() {
+      AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
       cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key").equals("value1");
@@ -140,6 +145,8 @@
    }
 
    public void testReplace() {
+      AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
@@ -160,6 +167,8 @@
    }
 
    public void testReplaceWithOldVal() {
+      AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key") == null;
       assert cache2.get("key").equals("value2");
@@ -185,6 +194,8 @@
    }
 
    public void testLocalOnlyClear() {
+      AdvancedCache cache1 = cache(0,"replication").getAdvancedCache();
+      AdvancedCache cache2 = cache(1,"replication").getAdvancedCache();
       cache1.put("key", "value1", Flag.CACHE_MODE_LOCAL);
       cache2.put("key", "value2", Flag.CACHE_MODE_LOCAL);
       assert cache1.get("key").equals("value1");

Modified: trunk/core/src/test/java/org/infinispan/replication/ReplicationExceptionTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/ReplicationExceptionTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/ReplicationExceptionTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -8,7 +8,6 @@
 package org.infinispan.replication;
 
 import org.infinispan.AdvancedCache;
-import org.infinispan.Cache;
 import org.infinispan.commands.VisitableCommand;
 import org.infinispan.config.Configuration;
 import org.infinispan.context.InvocationContext;
@@ -27,40 +26,38 @@
 import javax.transaction.TransactionManager;
 import java.io.NotSerializableException;
 import java.io.Serializable;
-import java.util.List;
 
 @Test(groups = "functional", testName = "replication.ReplicationExceptionTest")
 public class ReplicationExceptionTest extends MultipleCacheManagersTest {
-   private AdvancedCache cache1, cache2;
 
    protected void createCacheManagers() throws Throwable {
-      Configuration configuration = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC, true);
+      Configuration configuration = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC,true);
       configuration.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
-
       configuration.setLockAcquisitionTimeout(5000);
 
-      List<Cache<Object, Object>> caches = createClusteredCaches(2, "replicatinExceptionTest", configuration);
-
-      cache1 = caches.get(0).getAdvancedCache();
-      cache2 = caches.get(1).getAdvancedCache();
+      createClusteredCaches(2, "replicatinExceptionTest", configuration);
    }
 
    private TransactionManager beginTransaction() throws SystemException, NotSupportedException {
+      AdvancedCache cache1 = cache(0, "replicatinExceptionTest").getAdvancedCache();
+
       TransactionManager mgr = TestingUtil.getTransactionManager(cache1);
       mgr.begin();
       return mgr;
    }
 
    public void testNonSerializableRepl() throws Exception {
+      AdvancedCache cache1 = cache(0, "replicatinExceptionTest").getAdvancedCache();
+      AdvancedCache cache2 = cache(1, "replicatinExceptionTest").getAdvancedCache();
       try {
          cache1.put("test", new ContainerData());
 
          // We should not come here.
          assertNotNull("NonSerializableData should not be null on cache2", cache2.get("test"));
-      }
-      catch (RuntimeException runtime) {
+      } catch (RuntimeException runtime) {
          Throwable t = runtime.getCause();
-         if (t instanceof NotSerializableException || t.getCause() instanceof NotSerializableException) {
+         if (t instanceof NotSerializableException
+                  || t.getCause() instanceof NotSerializableException) {
             System.out.println("received NotSerializableException - as expected");
          } else {
             throw runtime;
@@ -69,6 +66,8 @@
    }
 
    public void testNonSerializableReplWithTx() throws Exception {
+      AdvancedCache cache1 = cache(0, "replicatinExceptionTest").getAdvancedCache();
+      AdvancedCache cache2 = cache(1, "replicatinExceptionTest").getAdvancedCache();
       TransactionManager tm;
 
       try {
@@ -78,21 +77,22 @@
 
          // We should not come here.
          assertNotNull("NonSerializableData should not be null on cache2", cache2.get("test"));
-      }
-      catch (RollbackException rollback) {
+      } catch (RollbackException rollback) {
          System.out.println("received RollbackException - as expected");
-      }
-      catch (Exception e) {
+      } catch (Exception e) {
          // We should also examine that it is indeed throwing a NonSerilaizable exception.
          fail(e.toString());
       }
    }
 
-   @Test(groups = "functional", expectedExceptions = {TimeoutException.class})
+   @Test(groups = "functional", expectedExceptions = { TimeoutException.class })
    public void testSyncReplTimeout() {
+      AdvancedCache cache1 = cache(0, "replicatinExceptionTest").getAdvancedCache();
+      AdvancedCache cache2 = cache(1, "replicatinExceptionTest").getAdvancedCache();
       cache2.addInterceptor(new CommandInterceptor() {
          @Override
-         protected Object handleDefault(InvocationContext ctx, VisitableCommand cmd) throws Throwable {
+         protected Object handleDefault(InvocationContext ctx, VisitableCommand cmd)
+                  throws Throwable {
             // Add a delay
             Thread.sleep(100);
             return super.handleDefault(ctx, cmd);
@@ -106,8 +106,10 @@
       cache1.put("k", "v");
    }
 
-   @Test(groups = "functional", expectedExceptions = {TimeoutException.class})
+   @Test(groups = "functional", expectedExceptions = { TimeoutException.class })
    public void testLockAcquisitionTimeout() throws Exception {
+      AdvancedCache cache1 = cache(0, "replicatinExceptionTest").getAdvancedCache();
+      AdvancedCache cache2 = cache(1, "replicatinExceptionTest").getAdvancedCache();
       cache2.getConfiguration().setLockAcquisitionTimeout(1);
       TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
 

Modified: trunk/core/src/test/java/org/infinispan/replication/ReplicationQueueTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/ReplicationQueueTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/ReplicationQueueTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -27,8 +27,6 @@
 @Test(groups = "functional", testName = "replication.ReplicationQueueTest")
 public class ReplicationQueueTest extends MultipleCacheManagersTest {
 
-   Cache cache1;
-   Cache cache2;
    private static final int REPL_QUEUE_INTERVAL = 5000;
    private static final int REPL_QUEUE_MAX_ELEMENTS = 10;
    long creationTime;
@@ -51,9 +49,6 @@
       Configuration conf2 = config.clone();
       conf2.setUseReplQueue(false);
       manager(1).defineConfiguration("replQueue", conf2);
-
-      cache1 = cache(0, "replQueue");
-      cache2 = cache(1, "replQueue");
    }
 
    /**
@@ -73,6 +68,10 @@
     * <tt>replQueueInterval</tt> is reached.
     */
    public void testReplicationBasedOnTime() throws InterruptedException {
+      
+      Cache cache1 = cache(0, "replQueue");
+      Cache cache2 = cache(1, "replQueue");
+      
       //only place one element, queue size is 10. 
       cache1.put("key", "value");
       ReplicationQueue replicationQueue = TestingUtil.extractComponent(cache1, ReplicationQueue.class);
@@ -98,6 +97,9 @@
     * <tt>replQueueInterval</tt> is reached.
     */
    public void testReplicationBasedOnTimeWithTx() throws Exception {
+      Cache cache1 = cache(0, "replQueue");
+      Cache cache2 = cache(1, "replQueue");
+      
       //only place one element, queue size is 10.
       TransactionManager transactionManager = TestingUtil.getTransactionManager(cache1);
       transactionManager.begin();
@@ -128,6 +130,10 @@
     * <tt>replQueueInterval</tt> is not reached.
     */
    public void testReplicationBasedOnSize() throws Exception {
+      
+      Cache cache1 = cache(0, "replQueue");
+      Cache cache2 = cache(1, "replQueue");
+      
       //only place one element, queue size is 10.
       for (int i = 0; i < REPL_QUEUE_MAX_ELEMENTS; i++) {
          cache1.put("key" + i, "value" + i);
@@ -148,6 +154,10 @@
     * <tt>replQueueInterval</tt> is not reached.
     */
    public void testReplicationBasedOnSizeWithTx() throws Exception {
+      
+      Cache cache1 = cache(0, "replQueue");
+      Cache cache2 = cache(1, "replQueue");
+      
       //only place one element, queue size is 10.
       TransactionManager transactionManager = TestingUtil.getTransactionManager(cache1);
       for (int i = 0; i < REPL_QUEUE_MAX_ELEMENTS; i++) {
@@ -170,6 +180,8 @@
     * Test that replication queue works fine when multiple threads are putting into the queue.
     */
    public void testReplicationQueueMultipleThreads() throws Exception {
+      final Cache cache1 = cache(0, "replQueue");
+      Cache cache2 = cache(1, "replQueue");
       int numThreads = 4;
       final int numLoopsPerThread = 3;
       Thread[] threads = new Thread[numThreads];

Modified: trunk/core/src/test/java/org/infinispan/replication/SyncCacheListenerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncCacheListenerTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncCacheListenerTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -22,6 +22,8 @@
 import org.infinispan.util.logging.Log;
 import org.infinispan.util.logging.LogFactory;
 import static org.testng.AssertJUnit.*;
+
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.Test;
 
 import javax.transaction.Transaction;
@@ -47,6 +49,13 @@
       cache1 = caches.get(0);
       cache2 = caches.get(1);
    }
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroy() {     
+      super.destroy();
+      cache1 = null;
+      cache2 = null;
+   }
 
    public void testSyncTxRepl() throws Exception {
       Integer age;

Modified: trunk/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -46,7 +46,7 @@
  */
 @Test(groups = "functional", testName = "replication.SyncReplImplicitLockingTest")
 public class SyncReplImplicitLockingTest extends MultipleCacheManagersTest {
-   Cache<String, String> cache1, cache2;
+   //Cache<String, String> cache1, cache2;
    String k = "key", v = "value";
 
    protected void createCacheManagers() throws Throwable {
@@ -54,9 +54,6 @@
       replSync.setLockAcquisitionTimeout(500);
       replSync.setUseEagerLocking(true);
       createClusteredCaches(2, "replication.SyncReplImplicitLockingTest", replSync);
-
-      cache1 = manager(0).getCache("replication.SyncReplImplicitLockingTest");
-      cache2 = manager(1).getCache("replication.SyncReplImplicitLockingTest");
    }
 
    public void testBasicOperation() throws Exception {
@@ -71,7 +68,8 @@
 
    public void testLocksReleasedWithNoMods() throws Exception {
       assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
-
+      Cache cache1 = cache(0,"replication.SyncReplImplicitLockingTest");
+      Cache cache2 = cache(1,"replication.SyncReplImplicitLockingTest");
       assertNull("Should be null", cache1.get(k));
       assertNull("Should be null", cache2.get(k));
 
@@ -84,12 +82,15 @@
 
       assertNoLocks(cache1);
       assertNoLocks(cache2);
-
-      cleanup();
+      cache1.clear();cache2.clear();
    }
 
    private void concurrentLockingHelper(final boolean sameNode, final boolean useTx)
          throws Exception {
+      
+      final Cache cache1 = cache(0,"replication.SyncReplImplicitLockingTest");
+      final Cache cache2 = cache(1,"replication.SyncReplImplicitLockingTest");
+      
       assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
 
       assertNull("Should be null", cache1.get(k));
@@ -140,10 +141,13 @@
       t.join();
 
       cache2.remove(k);
-      cleanup();
+      cache1.clear();cache2.clear();
    }
 
    private void testBasicOperationHelper(boolean useCommit) throws Exception {
+      Cache cache1 = cache(0,"replication.SyncReplImplicitLockingTest");
+      Cache cache2 = cache(1,"replication.SyncReplImplicitLockingTest");
+      
       assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
 
       assertNull("Should be null", cache1.get(k));
@@ -190,8 +194,7 @@
       cache2.remove(k);
       cache2.remove(key2);
       cache2.remove(key3);
-      cache2.remove(key4);
-      cleanup();
+      cache2.remove(key4);     
    }
 
    @SuppressWarnings("unchecked")
@@ -199,11 +202,4 @@
       LockManager lm = TestingUtil.extractLockManager(cache);
       for (Object key : cache.keySet()) assert !lm.isLocked(key);
    }
-
-   protected void cleanup() {
-      assert cache1.isEmpty();
-      assert cache2.isEmpty();
-      cache1.clear();
-      cache2.clear();
-   }
 }

Modified: trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -45,16 +45,12 @@
  */
 @Test(groups = "functional", testName = "replication.SyncReplLockingTest")
 public class SyncReplLockingTest extends MultipleCacheManagersTest {
-   Cache<String, String> cache1, cache2;
    String k = "key", v = "value";
 
    protected void createCacheManagers() throws Throwable {
       Configuration replSync = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC, true);
       replSync.setLockAcquisitionTimeout(500);
       createClusteredCaches(2, "replSync", replSync);
-
-      cache1 = manager(0).getCache("replSync");
-      cache2 = manager(1).getCache("replSync");
    }
 
    public void testLocksReleasedWithoutExplicitUnlock() throws Exception {
@@ -76,6 +72,8 @@
 
 
    public void testLocksReleasedWithNoMods() throws Exception {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
 
       assertNull("Should be null", cache1.get(k));
@@ -93,11 +91,16 @@
       assertNoLocks(cache1);
       assertNoLocks(cache2);
 
-      cleanup();
+      assert cache1.isEmpty();
+      assert cache2.isEmpty();
+      cache1.clear();
+      cache2.clear();
    }
 
    private void concurrentLockingHelper(final boolean sameNode, final boolean useTx)
          throws Exception {
+      final Cache cache1 = cache(0, "replSync");
+      final Cache cache2 = cache(1, "replSync");
       assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
 
       assertNull("Should be null", cache1.get(k));
@@ -148,11 +151,18 @@
       t.join();
 
       cache2.remove(k);
-      cleanup();
+      assert cache1.isEmpty();
+      assert cache2.isEmpty();
+      cache1.clear();
+      cache2.clear();
    }
 
    private void locksReleasedWithoutExplicitUnlockHelper(boolean lockPriorToPut, boolean useCommit)
          throws Exception {
+      
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
+      
       assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
 
       assertNull("Should be null", cache1.get(k));
@@ -181,7 +191,10 @@
       }
 
       cache2.remove(k);
-      cleanup();
+      assert cache1.isEmpty();
+      assert cache2.isEmpty();
+      cache1.clear();
+      cache2.clear();
    }
 
    @SuppressWarnings("unchecked")
@@ -189,11 +202,4 @@
       LockManager lm = TestingUtil.extractLockManager(cache);
       for (Object key : cache.keySet()) assert !lm.isLocked(key);
    }
-
-   protected void cleanup() {
-      assert cache1.isEmpty();
-      assert cache2.isEmpty();
-      cache1.clear();
-      cache2.clear();
-   }
 }

Modified: trunk/core/src/test/java/org/infinispan/replication/SyncReplTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncReplTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncReplTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -32,18 +32,18 @@
  */
 @Test(groups = "functional", testName = "replication.SyncReplTest")
 public class SyncReplTest extends MultipleCacheManagersTest {
-   Cache cache1, cache2;
+
    String k = "key", v = "value";
 
    protected void createCacheManagers() throws Throwable {
       Configuration replSync = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
       createClusteredCaches(2, "replSync", replSync);
-
-      cache1 = manager(0).getCache("replSync");
-      cache2 = manager(1).getCache("replSync");
    }
 
    public void testBasicOperation() {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
+
       assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
 
       assertNull("Should be null", cache1.get(k));
@@ -60,6 +60,9 @@
    }
 
    public void testMultpleCachesOnSharedTransport() {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
+
       assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
       assert cache1.isEmpty();
       assert cache2.isEmpty();
@@ -90,6 +93,8 @@
    }
 
    public void testReplicateToNonExistentCache() {
+      Cache cache1 = cache(0, "replSync");
+      Cache cache2 = cache(1, "replSync");
       assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
       assert cache1.isEmpty();
       assert cache2.isEmpty();
@@ -118,6 +123,7 @@
    }
 
    public void testMixingSyncAndAsyncOnSameTransport() throws Exception {
+      Cache cache1 = cache(0, "replSync");
       Transport originalTransport = null;
       RpcManagerImpl rpcManager = null;
       List<Response> emptyResponses = Collections.emptyList();
@@ -142,9 +148,11 @@
          rpcManager = (RpcManagerImpl) TestingUtil.extractComponent(asyncCache1, RpcManager.class);
          rpcManager.setTransport(mockTransport);
 
-         expect(mockTransport.invokeRemotely((List<Address>) anyObject(), (CacheRpcCommand) anyObject(), eq(ResponseMode.SYNCHRONOUS),
-                                             anyLong(), anyBoolean(), (ResponseFilter) anyObject(), anyBoolean()))
-               .andReturn(emptyResponses).once();
+         expect(
+                  mockTransport.invokeRemotely((List<Address>) anyObject(),
+                           (CacheRpcCommand) anyObject(), eq(ResponseMode.SYNCHRONOUS), anyLong(),
+                           anyBoolean(), (ResponseFilter) anyObject(), anyBoolean())).andReturn(
+                  emptyResponses).once();
 
          replay(mockTransport);
          // check that the replication call was sync
@@ -154,9 +162,11 @@
          reset(mockTransport);
          expect(mockTransport.getAddress()).andReturn(mockAddressOne).anyTimes();
          expect(mockTransport.getMembers()).andReturn(addresses).anyTimes();
-         expect(mockTransport.invokeRemotely((List<Address>) anyObject(), (CacheRpcCommand) anyObject(), eq(ResponseMode.ASYNCHRONOUS),
-                                             anyLong(), anyBoolean(), (ResponseFilter) anyObject(), anyBoolean()))
-               .andReturn(emptyResponses).once();
+         expect(
+                  mockTransport.invokeRemotely((List<Address>) anyObject(),
+                           (CacheRpcCommand) anyObject(), eq(ResponseMode.ASYNCHRONOUS), anyLong(),
+                           anyBoolean(), (ResponseFilter) anyObject(), anyBoolean())).andReturn(
+                  emptyResponses).once();
 
          replay(mockTransport);
          asyncCache1.put("k", "v");
@@ -164,7 +174,8 @@
          verify(mockTransport);
       } finally {
          // replace original transport
-         if (rpcManager != null) rpcManager.setTransport(originalTransport);
+         if (rpcManager != null)
+            rpcManager.setTransport(originalTransport);
       }
    }
 }

Modified: trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/test/MultipleCacheManagersTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -71,6 +71,9 @@
    protected void destroy() {     
       if (cleanup == CleanupPhase.AFTER_TEST) TestingUtil.killCacheManagers(cacheManagers);
       cacheManagers.clear();  
+      cacheManagers=null;     
+      listeners.clear();
+      listeners=null;
    }
 
    @AfterMethod(alwaysRun=true)

Modified: trunk/core/src/test/java/org/infinispan/tx/LargeTransactionTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/tx/LargeTransactionTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/tx/LargeTransactionTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -19,12 +19,8 @@
  */
 @Test(testName = "tx.LargeTransactionTest", groups = "functional")
 public class LargeTransactionTest extends MultipleCacheManagersTest {
-
    private static Log log = LogFactory.getLog(LargeTransactionTest.class);
 
-   private Cache cache1;
-   private Cache cache2;
-
    protected void createCacheManagers() throws Throwable {
 
       Configuration c = new Configuration();
@@ -40,18 +36,20 @@
       manager.start();
       manager.getCache();
       registerCacheManager(manager);
-      cache1 = manager.getCache("TestCache");
+      Cache cache1 = manager.getCache("TestCache");
       assert cache1.getConfiguration().getCacheMode().equals(Configuration.CacheMode.REPL_SYNC);
       cache1.start();
 
       manager = TestCacheManagerFactory.createClusteredCacheManager(c);
       manager.start();
       registerCacheManager(manager);
-      cache2 = manager.getCache("TestCache");
+      Cache cache2 = manager.getCache("TestCache");
       assert cache1.getConfiguration().getCacheMode().equals(Configuration.CacheMode.REPL_SYNC);
    }
 
    public void testLargeTx() throws Exception {
+      Cache cache1 = cache(0, "TestCache");
+      Cache cache2 = cache(1, "TestCache");
       TransactionManager tm = TestingUtil.getTransactionManager(cache1);
       tm.begin();
       for (int i = 0; i < 200; i++)
@@ -65,6 +63,8 @@
    }
 
    public void testSinglePutInTx() throws Exception {
+      Cache cache1 = cache(0, "TestCache");
+      Cache cache2 = cache(1, "TestCache");
       TransactionManager tm = TestingUtil.getTransactionManager(cache1);
 
       tm.begin();
@@ -76,6 +76,8 @@
    }
 
    public void testSimplePutNoTx() {
+      Cache cache1 = cache(0, "TestCache");
+      Cache cache2 = cache(1, "TestCache");
       cache1.put("key", "val");
       assert cache2.get("key").equals("val");
    }

Modified: trunk/core/src/test/java/org/infinispan/tx/LocalDeadlockDetectionTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/tx/LocalDeadlockDetectionTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/tx/LocalDeadlockDetectionTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -9,6 +9,8 @@
 import org.infinispan.util.concurrent.locks.DeadlockDetectedException;
 import org.infinispan.util.concurrent.locks.DeadlockDetectingLockManager;
 import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -54,6 +56,15 @@
       t1.stopThread();
       t2.stopThread();
    }
+   
+   @AfterClass(alwaysRun=true)
+   protected void destroyAfterClass() {      
+      super.destroyAfterClass();
+      lockManager = null;
+      t1 = null; t2 = null;
+      response1 = null;
+      response2 = null;
+   }
 
 
    public void testDldPutAndPut() {

Modified: trunk/core/src/test/java/org/infinispan/tx/LocalModeTxTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/tx/LocalModeTxTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/tx/LocalModeTxTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -21,7 +21,6 @@
  */
 package org.infinispan.tx;
 
-import org.infinispan.Cache;
 import org.infinispan.manager.CacheManager;
 import org.infinispan.test.SingleCacheManagerTest;
 import org.infinispan.test.TestingUtil;
@@ -34,51 +33,49 @@
 @Test(groups = "functional", testName = "tx.LocalModeTxTest")
 public class LocalModeTxTest extends SingleCacheManagerTest {
 
-   Cache c;
-
    protected CacheManager createCacheManager() {
       CacheManager cm = TestCacheManagerFactory.createLocalCacheManager(true);
-      c = cm.getCache();
+      cache = cm.getCache();
       return cm;
    }
 
    public void testTxCommit1() throws Exception {
-      TransactionManager tm = TestingUtil.getTransactionManager(c);
+      TransactionManager tm = TestingUtil.getTransactionManager(cache);
       tm.begin();
-      c.put("key", "value");
+      cache.put("key", "value");
       Transaction t = tm.suspend();
-      assert c.isEmpty();
+      assert cache.isEmpty();
       tm.resume(t);
       tm.commit();
-      assert !c.isEmpty();
+      assert !cache.isEmpty();
    }
 
    public void testTxCommit3() throws Exception {
-      TransactionManager tm = TestingUtil.getTransactionManager(c);
+      TransactionManager tm = TestingUtil.getTransactionManager(cache);
       tm.begin();
-      c.put("key", "value");
+      cache.put("key", "value");
       tm.commit();
-      assert !c.isEmpty();
+      assert !cache.isEmpty();
    }
 
    public void testNonTx() throws Exception {
-      c.put("key", "value");
-      assert !c.isEmpty();
+      cache.put("key", "value");
+      assert !cache.isEmpty();
    }
 
    public void testTxCommit2() throws Exception {
-      TransactionManager tm = TestingUtil.getTransactionManager(c);
-      c.put("key", "old");
+      TransactionManager tm = TestingUtil.getTransactionManager(cache);
+      cache.put("key", "old");
       tm.begin();
-      assert c.get("key").equals("old");
-      c.put("key", "value");
-      assert c.get("key").equals("value");
+      assert cache.get("key").equals("old");
+      cache.put("key", "value");
+      assert cache.get("key").equals("value");
       Transaction t = tm.suspend();
-      assert c.get("key").equals("old");
+      assert cache.get("key").equals("old");
       tm.resume(t);
       tm.commit();
-      assert c.get("key").equals("value");
-      assert !c.isEmpty();
+      assert cache.get("key").equals("value");
+      assert !cache.isEmpty();
    }
 
 }

Modified: trunk/core/src/test/java/org/infinispan/tx/ReplDeadlockDetectionTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/tx/ReplDeadlockDetectionTest.java	2009-10-08 09:49:06 UTC (rev 923)
+++ trunk/core/src/test/java/org/infinispan/tx/ReplDeadlockDetectionTest.java	2009-10-08 19:19:42 UTC (rev 924)
@@ -17,9 +17,11 @@
 import org.infinispan.test.MultipleCacheManagersTest;
 import org.infinispan.test.PerCacheExecutorThread;
 import org.infinispan.test.TestingUtil;
+import org.infinispan.test.AbstractCacheTest.CleanupPhase;
 import org.infinispan.util.concurrent.NotifyingNotifiableFuture;
 import org.infinispan.util.concurrent.locks.DeadlockDetectingLockManager;
 import org.infinispan.util.concurrent.locks.LockManager;
+import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -97,6 +99,19 @@
       ((DeadlockDetectingLockManager) TestingUtil.extractLockManager(cache(0, "test"))).resetStatistics();
       ((DeadlockDetectingLockManager) TestingUtil.extractLockManager(cache(1, "test"))).resetStatistics();
    }
+   
+   @AfterClass(alwaysRun = true)
+   protected void destroy() {
+      super.destroy();
+      controlledRpcManager1 = null;
+      controlledRpcManager2 = null;
+      replicationLatch = null;
+      t1 = null;
+      t2 = null;
+      ddLm1 = null;
+      ddLm2 = null;
+      ;
+   }
 
    public void testExpectedInnerStructure() {
       LockManager lockManager = TestingUtil.extractComponent(cache(0, "test"), LockManager.class);



More information about the infinispan-commits mailing list