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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Sep 26 22:48:37 EDT 2007


Author: mircea.markus
Date: 2007-09-26 22:48:37 -0400 (Wed, 26 Sep 2007)
New Revision: 4514

Modified:
   core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
Log:
JBCACHE-1154 added unit test for optimistic locking

Modified: core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java	2007-09-26 23:42:55 UTC (rev 4513)
+++ core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java	2007-09-27 02:48:37 UTC (rev 4514)
@@ -6,6 +6,7 @@
 import static org.testng.Assert.*;
 import static org.testng.Assert.assertNotNull;
 import org.jboss.cache.*;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
 import org.jboss.cache.misc.TestingUtil;
 import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
 import org.jboss.cache.config.CacheLoaderConfig;
@@ -137,7 +138,7 @@
    {
       Fqn theNode = Fqn.fromString("/a_a");
       cache.put(theNode, "key", "value");
-      
+
       assertEquals(cache.getRoot().getChild(theNode).getKeys().size(), 1);
 
       cache.getRoot().getChild(theNode).setResident(true);
@@ -255,6 +256,38 @@
       cache.stop();
    }
 
+   /**
+    * When using optimistic locking , check to see that at commit time the cache is successfully updated.
+    */
+   public void testResidencyAndOptimisticLocking() throws Exception
+   {
+      javax.transaction.TransactionManager txManager = new DummyTransactionManagerLookup().getTransactionManager();
+      CacheImpl cache = (CacheImpl<Object, Object>) DefaultCacheFactory.getInstance().createCache("META-INF/optimistic-eviction.xml");
+
+      cache.put(Fqn.fromString("/a/b"), "key", "value");
+
+      txManager.begin();
+      cache.getRoot().getChild(Fqn.fromString("/a/b")).setResident(true);
+      txManager.rollback();
+      assertFalse(cache.getRoot().getChild(Fqn.fromString("/a/b")).isResident());
+
+      txManager.begin();
+      cache.getRoot().getChild(Fqn.fromString("/a/b")).setResident(true);
+      txManager.commit();
+      assertTrue(cache.getRoot().getChild(Fqn.fromString("/a/b")).isResident());
+
+      try
+      {
+         if (cache.getTransactionManager().getTransaction() != null)
+         {
+            cache.getTransactionManager().rollback();
+         }
+      } finally
+      {
+         cache.stop();
+      }
+   }
+
    private Fqn getSubFqn(String str)
    {
       return Fqn.fromString("/" + TEST_NODES_ROOT + str);




More information about the jbosscache-commits mailing list