[jbosscache-commits] JBoss Cache SVN: r6739 - in core/branches/2.1.X/src: test/java/org/jboss/cache/transaction and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Sep 16 13:20:57 EDT 2008


Author: mircea.markus
Date: 2008-09-16 13:20:57 -0400 (Tue, 16 Sep 2008)
New Revision: 6739

Added:
   core/branches/2.1.X/src/test/java/org/jboss/cache/transaction/RemoveOnTxTest.java
Modified:
   core/branches/2.1.X/src/main/java/org/jboss/cache/CacheImpl.java
Log:
fixing https://jira.jboss.org/jira/browse/JBCACHE-1406

Modified: core/branches/2.1.X/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/branches/2.1.X/src/main/java/org/jboss/cache/CacheImpl.java	2008-09-16 16:58:18 UTC (rev 6738)
+++ core/branches/2.1.X/src/main/java/org/jboss/cache/CacheImpl.java	2008-09-16 17:20:57 UTC (rev 6739)
@@ -45,15 +45,7 @@
 import javax.transaction.SystemException;
 import javax.transaction.Transaction;
 import javax.transaction.TransactionManager;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * The default implementation class of {@link org.jboss.cache.Cache} and {@link org.jboss.cache.CacheSPI}.  This class
@@ -2226,7 +2218,7 @@
          else
          {
             // mark the node to be removed (and all children) as invalid so anyone holding a direct reference to it will
-            // be aware that it is no longer valid.            
+            // be aware that it is no longer valid.
             n.setValid(false, true);
             return n.getParent().removeChildDirect(n.getFqn().getLastElement());
          }
@@ -2234,7 +2226,16 @@
       else
       {
          if (log.isDebugEnabled()) log.debug("Node " + f + " NOT marked for removal as expected, not removing!");
-         return false;
+         //also check whether children are marked for deletion, JBCACHE-1406
+         Set<NodeSPI> children = n.getChildrenDirect(true);
+         if (children == null || children.size() == 0) {
+             return false;
+         }
+         for (NodeSPI aChild : children)
+         {
+            realRemove(aChild.getFqn(), skipMarkerCheck);
+         }
+         return true;
       }
    }
 

Added: core/branches/2.1.X/src/test/java/org/jboss/cache/transaction/RemoveOnTxTest.java
===================================================================
--- core/branches/2.1.X/src/test/java/org/jboss/cache/transaction/RemoveOnTxTest.java	                        (rev 0)
+++ core/branches/2.1.X/src/test/java/org/jboss/cache/transaction/RemoveOnTxTest.java	2008-09-16 17:20:57 UTC (rev 6739)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.cache.transaction;
+
+import javax.transaction.TransactionManager;
+import javax.transaction.Transaction;
+
+import org.jboss.cache.*;
+import org.jboss.cache.util.CachePrinter;
+import org.jboss.cache.config.Configuration;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.AfterMethod;
+import static org.testng.Assert.*;
+
+/**
+ * This is for checking issue: https://jira.jboss.org/jira/browse/JBCACHE-1406
+ * This is an issue portated from 1.4.x
+ * @author Mircea.Markus at jboss.com
+ */
+ at Test (groups = "functional")
+public class RemoveOnTxTest
+{
+   private CacheSPI cache;
+
+   @BeforeMethod
+   protected void setUp() throws Exception
+   {
+      Configuration configuration = new Configuration();
+      configuration.setCacheMode(Configuration.CacheMode.LOCAL);
+      configuration.setTransactionManagerLookupClass("org.jboss.cache.transaction.GenericTransactionManagerLookup");
+      configuration.setNodeLockingScheme(Configuration.NodeLockingScheme.PESSIMISTIC);
+      cache = (CacheSPI) new DefaultCacheFactory().createCache(configuration);
+   }
+
+   @AfterMethod
+   protected void tearDown() throws Exception
+   {
+      cache.stop();
+      cache.destroy();
+   }
+
+   public void testFailure() throws Exception
+   {
+
+      TransactionManager tm = cache.getTransactionManager();
+      try
+      {
+         tm.begin();
+         print("put()");
+         cache.put("/a/b/c", "test", "test");
+         assertTrue(cache.get("/a/b/c", "test").equals("test"));
+         print("remove()");
+         cache.removeNode("/a/b");
+         assertTrue(!cache.exists("/a/b"));
+         assertTrue(!cache.exists("/a/b/c"));
+         cache.put("/a/b/d", "test1", "test1");
+         assertTrue(!cache.exists("/a/b/c"));
+         assertTrue(cache.exists("/a/b/d"));
+         print("Exists? " + cache.exists("/a/b/c"));
+         print("get(): " + cache.get("/a/b/c", "test"));
+         tm.commit();
+         assertTrue(cache.peek(Fqn.fromString("/a/b/c"), true, true) == null);
+         assertTrue(!cache.exists("/a/b/c"));
+         assertTrue(cache.exists("/a/b/d"));
+         CachePrinter.printCacheLockingInfo(cache);
+      }
+      catch (Exception ex) {
+         tm.rollback();
+         throw ex;
+      }
+      CachePrinter.printCacheLockingInfo(cache);
+      System.out.println(" lock info " + CachePrinter.printCacheLockingInfo(cache));
+      try
+      {
+         tm.begin();
+         print(cache.exists("/a/b/c"));
+         print("get(): " + cache.get("/a/b/c", "test"));
+         print("get(): " + cache.get("/a/b/c", "test"));
+         Transaction t = tm.suspend();
+         try
+         {
+            cache.putForExternalRead(Fqn.fromString("/a/b/c"), "test", "test");
+         }
+         catch (Exception ignore) {
+            ignore.printStackTrace();
+         }
+         tm.resume(t);
+         print("get(): " + cache.get("/a/b/c", "test"));
+         print(cache.exists("/a/b/c"));
+         cache.put("/a/b/c", "test", "test");
+         print(cache.exists("/a/b/c"));
+         tm.commit();
+      }
+      catch (Exception ex) {
+         tm.rollback();
+         throw ex;
+      }
+   }
+
+   private void print(Object s)
+   {
+      System.out.println(s);
+   }
+
+   private void print(boolean s)
+   {
+      System.out.println(s);
+   }
+
+   public void testReal() throws Exception
+   {
+      TransactionManager tm = cache.getTransactionManager();
+      tm.begin();
+      print("put()");
+      cache.put("/a/b/c", "test", "test");
+      assertTrue(cache.get("/a/b/c", "test").equals("test"));
+      print("remove()");
+      cache.removeNode("/a/b");
+      assertTrue(!cache.exists("/a/b"));
+      assertTrue(!cache.exists("/a/b/c"));
+      cache.put("/a/b/d", "test1", "test1");
+      assertTrue(!cache.exists("/a/b/c"));
+      assertTrue(cache.exists("/a/b/d"));
+      print("Exists? " + cache.exists("/a/b/c"));
+      print("get(): " + cache.get("/a/b/c", "test"));
+      tm.commit();
+      assertTrue(!cache.exists("/a/b/c"));
+      assertTrue(cache.exists("/a/b/d"));
+      assertNull(cache.peek(Fqn.fromString("/a/b/c"), true, true));
+   }
+
+   public void testSimplified() throws Exception
+   {
+      TransactionManager tm = cache.getTransactionManager();
+      tm.begin();
+      print("put()");
+      cache.put("/a/b/c", "test", "test");
+      assertTrue(cache.peek(Fqn.fromString("/a/b/c"), true, true) != null);
+      cache.removeNode("/a/b");
+      tm.commit();
+      assertTrue(cache.peek(Fqn.fromString("/a/b/c"), true, true) == null);
+   }
+}




More information about the jbosscache-commits mailing list