[jbosscache-commits] JBoss Cache SVN: r6166 - core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Jul 3 16:03:42 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-07-03 16:03:42 -0400 (Thu, 03 Jul 2008)
New Revision: 6166

Modified:
   core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
Log:
Deal with cache.getRoot()

Modified: core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java	2008-07-03 19:58:15 UTC (rev 6165)
+++ core/trunk/src/test/java/org/jboss/cache/options/cachemodelocal/CacheModeLocalTestBase.java	2008-07-03 20:03:42 UTC (rev 6166)
@@ -11,13 +11,14 @@
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
+import org.jboss.cache.NodeSPI;
 import org.jboss.cache.config.Configuration;
+import org.jboss.cache.util.TestingUtil;
 import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import javax.transaction.SystemException;
 import javax.transaction.TransactionManager;
 import java.util.HashMap;
 import java.util.Map;
@@ -42,6 +43,7 @@
 
    private CacheSPI<String, String> cache1;
    private CacheSPI<String, String> cache2;
+   private NodeSPI<String, String> root1, root2;
 
    private Fqn fqn = Fqn.fromString("/a");
    private String key = "key";
@@ -69,44 +71,17 @@
       cache2.getConfiguration().setNodeLockingScheme(nodeLockingScheme);
       cache2.getConfiguration().setCacheMode(cacheMode);
       cache2.start();
+
+      root1 = cache1.getRoot();
+      root2 = cache2.getRoot();
    }
 
    @AfterMethod(alwaysRun = true)
    public void tearDown()
    {
-      if (cache1 != null)
-      {
-         cache1.stop();
-         flushTxs(cache1.getTransactionManager());
-         cache1 = null;
-      }
-
-      if (cache2 != null)
-      {
-         cache2.stop();
-         flushTxs(cache2.getTransactionManager());
-         cache2 = null;
-      }
+      TestingUtil.killCaches(cache1, cache2);
    }
 
-   private void flushTxs(TransactionManager mgr)
-   {
-      if (mgr != null)
-      {
-         try
-         {
-            if (mgr.getTransaction() != null)
-            {
-               mgr.rollback();
-            }
-         }
-         catch (SystemException e)
-         {
-            // do nothing
-         }
-      }
-   }
-
    public void testPutKeyValue() throws Exception
    {
       cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
@@ -158,7 +133,7 @@
 
    public void testPutKeyValueViaNodeAPI() throws Exception
    {
-      Node node1 = cache1.getRoot().addChild(fqn);
+      Node node1 = root1.addChild(fqn);
       cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
       node1.put(key, "value");
       delay();
@@ -187,7 +162,7 @@
 
       // now cache2
       cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
-      Node node2 = cache2.getRoot().addChild(fqn);
+      Node node2 = root2.addChild(fqn);
       cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
       node2.put(key, "value2");
       delay();
@@ -264,7 +239,7 @@
       Map<String, String> map = new HashMap<String, String>();
       map.put(key, "value");
 
-      Node node1 = cache1.getRoot().addChild(fqn);
+      Node node1 = root1.addChild(fqn);
       cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
       node1.putAll(map);
       delay();
@@ -291,7 +266,7 @@
 
       // now cache2
       cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
-      Node node2 = cache2.getRoot().addChild(fqn);
+      Node node2 = root2.addChild(fqn);
       map.put(key, "value2");
       cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
       node2.putAll(map);
@@ -387,7 +362,7 @@
       }
 
       cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
-      cache1.getRoot().removeChild(fqn);
+      root1.removeChild(fqn);
       delay();
 
       // should be removed in cache1
@@ -417,7 +392,7 @@
 
       // now try again with passing the default options
       cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
-      cache1.getRoot().removeChild(fqn);
+      root1.removeChild(fqn);
       delay();
 
       // both should be null
@@ -483,7 +458,7 @@
    public void testRemoveKeyViaNodeAPI() throws Exception
    {
       // put some stuff in the cache first
-      Node node1 = cache1.getRoot().addChild(fqn);
+      Node node1 = root1.addChild(fqn);
       cache1.getInvocationContext().setOptionOverrides(null);
       node1.put(key, "value");
       delay();
@@ -652,7 +627,7 @@
 
    public void testTransactionalBehaviourViaNodeAPI() throws Exception
    {
-      Node node1 = cache1.getRoot().addChild(fqn);
+      Node node1 = root1.addChild(fqn);
       TransactionManager mgr = cache1.getTransactionManager();
       mgr.begin();
       cache1.getInvocationContext().getOptionOverrides().reset();
@@ -695,7 +670,7 @@
       }
 
       // now cache2
-      Node node2 = cache2.getRoot().addChild(fqn);
+      Node node2 = root2.addChild(fqn);
       mgr = cache2.getTransactionManager();
       mgr.begin();
       cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
@@ -738,25 +713,25 @@
    public void testAddChild() throws Exception
    {
       cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
-      cache1.getRoot().addChild(fqn);
+      root1.addChild(fqn);
       delay();
       // cache1 should still have this
-      assertTrue(cache1.getRoot().hasChild(fqn));
+      assertTrue(root1.hasChild(fqn));
       // cache 2 should not
-      Node node2 = cache2.getRoot().getChild(fqn);
+      Node node2 = root2.getChild(fqn);
       assertTrue("Should be null", node2 == null || (isInvalidation && !node2.isValid()));
 
       // now try again with passing the default options
-      cache1.getRoot().removeChild(fqn);
+      root1.removeChild(fqn);
       cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(false);
-      cache1.getRoot().addChild(fqn);
+      root1.addChild(fqn);
       delay();
       // cache1 should still have this
-      assertTrue(cache1.getRoot().hasChild(fqn));
+      assertTrue(root1.hasChild(fqn));
       // cache 2 should as well
       if (!isInvalidation)
       {
-         assertTrue(cache2.getRoot().hasChild(fqn));
+         assertTrue(root2.hasChild(fqn));
       }
       else
       {




More information about the jbosscache-commits mailing list