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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Feb 26 10:46:14 EST 2008


Author: bstansberry at jboss.com
Date: 2008-02-26 10:46:14 -0500 (Tue, 26 Feb 2008)
New Revision: 5372

Added:
   core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java
Log:
[JBCACHE-1296] Test for JBCACHE-1296

Added: core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java	                        (rev 0)
+++ core/trunk/src/test/java/org/jboss/cache/api/DeletedChildResurrectionTest.java	2008-02-26 15:46:14 UTC (rev 5372)
@@ -0,0 +1,139 @@
+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.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.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * 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. 
+ *
+ * @author Brian Stansberry
+ * @since 2.1.0
+ */
+ at Test(groups = {"functional"})
+public class DeletedChildResurrectionTest
+{
+   private Cache<Object, Object> cache;
+
+   @BeforeMethod(alwaysRun = true)
+   public void setUp()
+   {      
+   }
+
+   @AfterMethod(alwaysRun = true)
+   public void tearDown() throws Exception
+   {
+      cache.stop();
+      cache.destroy();
+      cache = null;
+   }
+   
+   /**
+    * 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
+   {
+      deletedChildResurrectionTest2(true);
+   }
+
+   /**
+    * 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. 
+    */
+   private void deletedChildResurrectionTest1(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);
+
+      TransactionManager txManager = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+      
+      cache.getRoot().addChild(Fqn.fromString("/a/b")).put("key", "value");      
+      txManager.begin();
+      cache.getRoot().removeChild(Fqn.fromString("/a"));
+      cache.getRoot().addChild(Fqn.fromString("/a"));
+      txManager.commit();
+      assertNull(cache.getRoot().getChild(Fqn.fromString("/a/b")));
+      Node a = cache.getRoot().getChild(Fqn.fromString("/a"));
+      assertNotNull(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. 
+    */
+   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);
+
+      TransactionManager txManager = cache.getConfiguration().getRuntimeConfig().getTransactionManager();
+      
+      cache.getRoot().addChild(Fqn.fromString("/a/b")).put("key", "value");
+      
+      txManager.begin();
+      cache.getRoot().removeChild(Fqn.fromString("/a"));
+      cache.getRoot().addChild(Fqn.fromString("/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"));
+   }
+}




More information about the jbosscache-commits mailing list