[jbosscache-commits] JBoss Cache SVN: r5393 - in core/trunk/src: test/java/org/jboss/cache/invalidation and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Mar 6 19:56:48 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-03-06 19:56:47 -0500 (Thu, 06 Mar 2008)
New Revision: 5393

Modified:
   core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
   core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
Log:
JBCACHE-1298 - removal of nonexistent nodes using invalidation and creation of invalid tombstones

Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2008-03-06 21:51:14 UTC (rev 5392)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2008-03-07 00:56:47 UTC (rev 5393)
@@ -11,6 +11,7 @@
 import org.jboss.cache.buddyreplication.BuddyManager;
 import org.jboss.cache.buddyreplication.GravitateResult;
 import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Option;
 import org.jboss.cache.factories.ComponentRegistry;
 import org.jboss.cache.factories.InterceptorChainFactory;
 import org.jboss.cache.factories.annotations.ComponentName;
@@ -1595,12 +1596,20 @@
          NodeSPI nodeSPI = peek(fqn, false, true);
          if (nodeSPI == null)
          {
-            log.trace("Node doesn't exist; creating a tombstone");
+            if (versionToInvalidate == null)
+            {
+               if (trace)
+                  log.trace("Would have created a tombstone since the node doesn't exist, but the version to invalidate is null and hence cannot create a tombstone!");
+               return;
+            }
+            if (trace) log.trace("Node doesn't exist; creating a tombstone with data version " + versionToInvalidate);
             // create the node we need.
             Map m = Collections.emptyMap();
             InvocationContext ic = spi.getInvocationContext();
-            boolean origCacheModeLocal = ic.getOptionOverrides().isCacheModeLocal();
-            ic.getOptionOverrides().setCacheModeLocal(true);
+            Option o = ic.getOptionOverrides();
+            boolean origCacheModeLocal = o.isCacheModeLocal();
+            o.setCacheModeLocal(true);
+            o.setDataVersion(versionToInvalidate);
             // if we are in a tx this call should happen outside of any tx
             try
             {

Modified: core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java	2008-03-06 21:51:14 UTC (rev 5392)
+++ core/trunk/src/test/java/org/jboss/cache/invalidation/InvalidationInterceptorTest.java	2008-03-07 00:56:47 UTC (rev 5393)
@@ -20,7 +20,6 @@
 import org.jboss.cache.optimistic.DefaultDataVersion;
 import org.jboss.cache.xml.XmlHelper;
 import static org.testng.AssertJUnit.*;
-
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
 import org.w3c.dom.Element;
@@ -463,7 +462,7 @@
 
    /**
     * Test for JBCACHE-1251.
-    * 
+    *
     * @throws Exception
     */
    public void testPessimisticNodeResurrection2() throws Exception
@@ -475,7 +474,7 @@
     * OPTIMISTIC locking verion of test for JBCACHE-1251. JBCACHE-1251
     * did not effect optimistic, but we add the test to guard against
     * regressions.
-    * 
+    *
     * @throws Exception
     */
    public void testOptimisticNodeResurrection2() throws Exception
@@ -485,17 +484,17 @@
 
    /**
     * Here we model a scenario where a parent node represents
-    * a structural node, and then child nodes represent different 
+    * a structural node, and then child nodes represent different
     * data elements.
-    * 
-    * Such data structures are set up on both caches, and then the parent node 
-    * is removed (globally) and re-added (locally) on one cache.  This 
-    * represents an attempt to clear the region -- removing a node and 
+    * <p/>
+    * Such data structures are set up on both caches, and then the parent node
+    * is removed (globally) and re-added (locally) on one cache.  This
+    * represents an attempt to clear the region -- removing a node and
     * re-adding is one of the only ways to do this.
-    * 
+    * <p/>
     * On the second cache, the fact that the structural node is missing is
     * detected, and an attempt is made to re-add it locally.
-    * 
+    *
     * @param optimistic should the cache be configured for optimistic locking
     * @throws Exception
     */
@@ -515,20 +514,20 @@
       cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
       root1.addChild(fqn);
       assertEquals(true, root1.hasChild(fqn));
-      
+
       Fqn<String> child = new Fqn(fqn, "child");
       cache1.putForExternalRead(child, "key", "value");
       cache2.putForExternalRead(child, "key", "value");
       assertEquals("value", cache1.get(child, "key"));
-      assertEquals("value", cache2.get(child, "key"));     
-      
+      assertEquals("value", cache2.get(child, "key"));
+
       assertEquals(true, cache1.removeNode(fqn));
       assertFalse(root1.hasChild(fqn));
 
       cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
       root1.addChild(fqn);
       assertEquals(true, root1.hasChild(fqn));
-      
+
       Node remoteNode = root2.getChild(fqn);
       checkRemoteNodeIsRemoved(remoteNode);
       cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
@@ -756,22 +755,22 @@
       n = caches.get(0).getNode(fqn);
       assertHasBeenInvalidated(n, "Should have been invalidated");
    }
-   
+
    public void testDeleteNonExistentPessimistic() throws Exception
    {
       deleteNonExistentTest(false);
    }
-   
+
    /**
     * Test for JBCACHE-1297
-    * 
+    *
     * @throws Exception
     */
    public void testDeleteNonExistentOptimistic() throws Exception
    {
       deleteNonExistentTest(true);
    }
-   
+
    private void deleteNonExistentTest(boolean optimistic) throws Exception
    {
       List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
@@ -791,10 +790,10 @@
       assertNull("Should be null", cache2.getNode(fqn));
 
       cache1.putForExternalRead(fqn, "key", "value");
-      
-      assertEquals("value",cache1.getNode(fqn).get("key"));
+
+      assertEquals("value", cache1.getNode(fqn).get("key"));
       assertNull("Should be null", cache2.getNode(fqn));
-      
+
       // OK, here's the real test
       TransactionManager tm = cache2.getTransactionManager();
       tm.begin();
@@ -810,34 +809,28 @@
          log.error(msg, e);
          fail(msg + " -- " + e);
       }
-      
-      assertHasBeenInvalidated(cache1.getNode(fqn), "Should have been invalidated");      
-      assertNull("Should be null", cache2.getNode(fqn));      
+
+      assertHasBeenInvalidated(cache1.getNode(fqn), "Should have been invalidated");
+      assertNull("Should be null", cache2.getNode(fqn));
    }
-   
+
    /**
     * Test for JBCACHE-1298.
-    * 
+    *
     * @throws Exception
     */
    public void testAddOfDeletedNonExistent() throws Exception
    {
-      List<CacheSPI<Object, Object>> caches = new ArrayList<CacheSPI<Object, Object>>();
-      caches.add(createUnstartedCache(true));
-      caches.add(createUnstartedCache(true));
-      cache1 = caches.get(0);
-      cache2 = caches.get(1);
+      cache1 = createCache(true);
+      cache2 = createCache(true);
 
-      cache1.start();
-      cache2.start();
+      TestingUtil.blockUntilViewsReceived(5000, cache1, cache2);
 
-      TestingUtil.blockUntilViewsReceived(caches.toArray(new CacheSPI[0]), 5000);
-
       Fqn fqn = Fqn.fromString("/a/b");
 
       assertNull("Should be null", cache1.getNode(fqn));
       assertNull("Should be null", cache2.getNode(fqn));
-      
+
       // OK, here's the real test
       TransactionManager tm = cache2.getTransactionManager();
       tm.begin();
@@ -853,17 +846,17 @@
          log.error(msg, e);
          fail(msg + " -- " + e);
       }
-      
+
       // Actually, it shouldn't have been invalidated, should be null
       // But, this assertion will pass if it is null, and we want
-      assertHasBeenInvalidated(cache1.getNode(fqn), "Should have been invalidated");      
-      assertNull("Should be null", cache2.getNode(fqn));  
+      assertHasBeenInvalidated(cache1.getNode(fqn), "Should have been invalidated");
+      assertNull("Should be null", cache2.getNode(fqn));
 
       cache1.getInvocationContext().getOptionOverrides().setDataVersion(new DefaultDataVersion());
       cache1.put(fqn, "key", "value");
-      
+
       assertEquals("value", cache1.getNode(fqn).get("key"));
-      assertHasBeenInvalidated(cache2.getNode(fqn), "Should have been invalidated");    
+      assertHasBeenInvalidated(cache2.getNode(fqn), "Should have been invalidated");
    }
 
    protected CacheSPI<Object, Object> createUnstartedCache(boolean optimistic) throws Exception




More information about the jbosscache-commits mailing list