[jbosscache-commits] JBoss Cache SVN: r6690 - core/branches/1.4.X/tests/functional/org/jboss/cache.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Sep 4 10:12:45 EDT 2008


Author: mircea.markus
Date: 2008-09-04 10:12:45 -0400 (Thu, 04 Sep 2008)
New Revision: 6690

Added:
   core/branches/1.4.X/tests/functional/org/jboss/cache/RemoveOnTxTest.java
Log:
http://jira.jboss.com/jira/browse/JBCACHE-1384

Added: core/branches/1.4.X/tests/functional/org/jboss/cache/RemoveOnTxTest.java
===================================================================
--- core/branches/1.4.X/tests/functional/org/jboss/cache/RemoveOnTxTest.java	                        (rev 0)
+++ core/branches/1.4.X/tests/functional/org/jboss/cache/RemoveOnTxTest.java	2008-09-04 14:12:45 UTC (rev 6690)
@@ -0,0 +1,154 @@
+/*
+ * 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;
+
+import junit.framework.TestCase;
+
+import javax.transaction.TransactionManager;
+import javax.transaction.Transaction;
+
+/**
+ * When deleting a node in TX and adding one of it's parrents in same tx, the node node does not get deleted when
+ * tx finishes. This tests is for reproducing the issue above.
+ */
+public class RemoveOnTxTest extends TestCase
+{
+   TreeCache cache;
+   protected void setUp() throws Exception
+   {
+      cache = new TreeCache();
+      PropertyConfigurator config = new PropertyConfigurator();
+      config.configure(cache, "META-INF/local-service.xml");
+      cache.create();
+      cache.start();
+   }
+
+   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.remove("/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")) == null);
+         assertTrue(cache.exists("/a/b/c"));
+         assertTrue(cache.exists("/a/b/d"));
+         cache.printLockInfo();
+      } catch (Exception ex)
+      {
+         ex.printStackTrace();
+         tm.rollback();
+      }
+      cache.printLockInfo();
+      System.out.println(" lock info " + cache.printLockInfo());
+      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.putFailFast("/a/b/c", "test", "test", 0);
+         } 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)
+      {
+         ex.printStackTrace();
+         tm.rollback();
+      }
+   }
+
+   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.remove("/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();
+      assertNull(cache.peek(Fqn.fromString("/a/b/c")));
+      assertTrue(!cache.exists("/a/b/c"));
+      assertTrue(cache.exists("/a/b/d"));
+      cache.printLockInfo();
+   }
+
+   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")) != null);
+      cache.remove("/a/b");
+      assertTrue(cache.peek(Fqn.fromString("/a/b/c")).getDataKeys().contains("__JBOSS_MARKED_FOR_REMOVAL"));
+      tm.commit();
+      assertTrue(cache.peek(Fqn.fromString("/a/b/c")) == null);
+   }
+}




More information about the jbosscache-commits mailing list