[jbosscache-commits] JBoss Cache SVN: r5387 - core/trunk/src/test/java/org/jboss/cache/api.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Mar 5 11:54:24 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-03-05 11:54:24 -0500 (Wed, 05 Mar 2008)
New Revision: 5387

Modified:
   core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java
   core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
Log:
Cleaned up tests

Modified: core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java	2008-03-05 12:36:31 UTC (rev 5386)
+++ core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java	2008-03-05 16:54:24 UTC (rev 5387)
@@ -1,25 +1,23 @@
 package org.jboss.cache.api;
 
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-
-import javax.transaction.TransactionManager;
-
 import org.jboss.cache.Cache;
+import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.Node;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.misc.TestingUtil;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import javax.transaction.TransactionManager;
+
 /**
  * Tests whether, in a single tx, deleting a parent node with an pre-existing
  * child and then re-adding a node with the parent Fqn results
- * in the pre-existing child remaining in the cache after tx commit. 
+ * in the pre-existing child remaining in the cache after tx commit.
  *
  * @author Brian Stansberry
  * @since 2.1.0
@@ -28,57 +26,64 @@
 public class DeletedChildResurrectionTest
 {
    private Cache<Object, Object> cache;
+   private static final Fqn<String> A_B = Fqn.fromString("/a/b");
+   private static final Fqn<String> A = Fqn.fromString("/a");
+   private static final Fqn<String> A_C = Fqn.fromString("/a/c");
+   private static final String KEY = "key";
+   private static final String VALUE = "value";
+   private static final String K2 = "k2";
+   private static final String V2 = "v2";
 
    @BeforeMethod(alwaysRun = true)
    public void setUp()
-   {      
+   {
+      cache = new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true), false);
+      cache.getConfiguration().setCacheMode(Configuration.CacheMode.LOCAL);
    }
 
    @AfterMethod(alwaysRun = true)
    public void tearDown() throws Exception
    {
-      cache.stop();
-      cache.destroy();
-      cache = null;
+      TestingUtil.killCaches(cache);
    }
-   
+
    /**
     * Tests whether the deleted child re-appears if the parent node is re-added
     * via a simple node.addChild(parentFqn) call. Pessimistic locking case.
-    * 
+    *
     * @throws Exception
     */
    public void testDeletedChildResurrectionPessimistic1() throws Exception
    {
       deletedChildResurrectionTest1(false);
    }
-   
+
    /**
     * Tests whether the deleted child re-appears if the parent node is re-added
     * via a simple node.addChild(parentFqn) call. Optimistic locking case.
-    * 
+    *
     * @throws Exception
     */
    public void testDeletedChildResurrectionOptimistic1() throws Exception
    {
       deletedChildResurrectionTest1(true);
    }
-   
+
    /**
     * Tests whether the deleted child re-appears if the parent node is re-added
     * via a node.addChild(differentChildofParentFqn) call. Pessimistic locking case.
-    * 
+    *
     * @throws Exception
     */
    public void testDeletedChildResurrectionPessimistic2() throws Exception
    {
       deletedChildResurrectionTest2(false);
    }
-   
+
    /**
     * Tests whether the deleted child re-appears if the parent node is re-added
     * via a node.addChild(differentChildofParentFqn) call. Optimistic locking case.
-    * 
+    *
     * @throws Exception
     */
    public void testDeletedChildResurrectionOptimistic2() throws Exception
@@ -89,51 +94,50 @@
    /**
     * Tests whether, in a single tx, deleting a parent node with an pre-existing
     * child and then inserting a different child under the parent Fqn results
-    * in the pre-existing child remaining in the cache after tx commit. 
+    * in the pre-existing child remaining in the cache after tx commit.
     */
    private void deletedChildResurrectionTest1(boolean optimistic) throws Exception
    {
+      cache.getConfiguration().setNodeLockingOptimistic(optimistic);
+      cache.start();
+      CacheSPI spi = (CacheSPI) cache;
+      Node<Object, Object> root = cache.getRoot();
 
-      Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
-      config.setCacheMode(Configuration.CacheMode.LOCAL);
-      config.setNodeLockingOptimistic(optimistic);
-      cache = (Cache<Object, Object>) new DefaultCacheFactory().createCache(config, true);
+      TransactionManager txManager = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
 
-      TransactionManager txManager = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
-      
-      cache.getRoot().addChild(Fqn.fromString("/a/b")).put("key", "value");      
+      root.addChild(A_B).put(KEY, VALUE);
       txManager.begin();
-      cache.getRoot().removeChild(Fqn.fromString("/a"));
-      cache.getRoot().addChild(Fqn.fromString("/a"));
+      root.removeChild(A);
+      root.addChild(A);
       txManager.commit();
-      assertNull(cache.getRoot().getChild(Fqn.fromString("/a/b")));
-      Node a = cache.getRoot().getChild(Fqn.fromString("/a"));
-      assertNotNull(a);
+      assert !root.hasChild(A_B);
+      // do a peek to ensure the node really has been removed and not just marked for removal
+      assert spi.peek(A_B, true, true) == null;
+      assert root.hasChild(A);
    }
 
    /**
     * Tests whether, in a single tx, deleting a parent node with an pre-existing
     * child and then inserting a different child under the parent Fqn results
-    * in the pre-existing child remaining in the cache after tx commit. 
+    * in the pre-existing child remaining in the cache after tx commit.
     */
    private void deletedChildResurrectionTest2(boolean optimistic) throws Exception
    {
-      Configuration config = UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.LOCAL, true);
-      config.setCacheMode(Configuration.CacheMode.LOCAL);
-      config.setNodeLockingOptimistic(optimistic);
-      cache = (Cache<Object, Object>) new DefaultCacheFactory().createCache(config, true);
+      cache.getConfiguration().setNodeLockingOptimistic(optimistic);
+      cache.start();
+      Node<Object, Object> root = cache.getRoot();
 
       TransactionManager txManager = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
-      
-      cache.getRoot().addChild(Fqn.fromString("/a/b")).put("key", "value");
-      
+
+      root.addChild(A_B).put(KEY, VALUE);
+
       txManager.begin();
-      cache.getRoot().removeChild(Fqn.fromString("/a"));
-      cache.getRoot().addChild(Fqn.fromString("/a/c")).put("k2", "v2");
+      root.removeChild(A);
+      root.addChild(A_C).put(K2, V2);
       txManager.commit();
-      assertNull(cache.getRoot().getChild(Fqn.fromString("/a/b")));
-      Node ac = cache.getRoot().getChild(Fqn.fromString("/a/c"));
-      assertNotNull(ac);
-      assertEquals("v2", ac.get("k2"));
+
+      assert !root.hasChild(A_B);
+      assert root.hasChild(A_C);
+      assert V2.equals(root.getChild(A_C).get(K2));
    }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java	2008-03-05 12:36:31 UTC (rev 5386)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java	2008-03-05 16:54:24 UTC (rev 5387)
@@ -356,29 +356,20 @@
       assertEquals(childrenNames, rootNode.getChildrenNames());
    }
 
-   public void testDoubleRemovalOfData()
+   public void testDoubleRemovalOfData() throws Exception
    {
-      try
-      {
-         cache.put("/foo/1/2/3", "item", 1);
-         tm.begin();
-         assertEquals(cache.get("/foo/1/2/3", "item"), 1);
-         cache.removeNode("/foo/1");
-         assertNull(cache.get("/foo/1", "item"));
-         cache.removeNode("/foo/1/2/3");
-         assertNull(cache.get("/foo/1/2/3", "item"));
-         assertNull(cache.get("/foo/1", "item"));
-         tm.commit();
-         assertFalse(cache.exists("/foo/1"));
-         assertNull(cache.get("/foo/1/2/3", "item"));
-         assertNull(cache.get("/foo/1", "item"));
-      }
-      catch (Throwable t)
-      {
-         t.printStackTrace();
-         fail(t.toString());
-      }
-
+      cache.put("/foo/1/2/3", "item", 1);
+      tm.begin();
+      assertEquals(cache.get("/foo/1/2/3", "item"), 1);
+      cache.removeNode("/foo/1");
+      assertNull(cache.get("/foo/1", "item"));
+      cache.removeNode("/foo/1/2/3");
+      assertNull(cache.get("/foo/1/2/3", "item"));
+      assertNull(cache.get("/foo/1", "item"));
+      tm.commit();
+      assertFalse(cache.exists("/foo/1"));
+      assertNull(cache.get("/foo/1/2/3", "item"));
+      assertNull(cache.get("/foo/1", "item"));
    }
 
 }




More information about the jbosscache-commits mailing list