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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Oct 5 09:22:46 EDT 2007


Author: manik.surtani at jboss.com
Date: 2007-10-05 09:22:46 -0400 (Fri, 05 Oct 2007)
New Revision: 4555

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
   core/trunk/src/test/java/org/jboss/cache/api/NodeReplicatedMoveTest.java
Log:
nullcheck in ICI and better fqn searching algo in II

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java	2007-10-05 13:22:05 UTC (rev 4554)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvalidationInterceptor.java	2007-10-05 13:22:46 UTC (rev 4555)
@@ -80,15 +80,16 @@
          if (m.getMethodId() != MethodDeclarations.putForExternalReadMethodLocal_id)
          {
             if (log.isDebugEnabled()) log.debug("Is a CRUD method");
-            Fqn fqn = findFqn(m.getArgs());
-            if (fqn != null)
+            Set<Fqn> fqns = new HashSet<Fqn>();
+            findAndAddFqns(m.getArgs(), fqns, m.getMethodId() == MethodDeclarations.moveMethodLocal_id);
+            if (!fqns.isEmpty())
             {
                // could be potentially TRANSACTIONAL.  Ignore if it is, until we see a prepare().
                if (tx == null || !isValid(tx))
                {
                   // the no-tx case:
                   //replicate an evict call.
-                  invalidateAcrossCluster(fqn, null, isSynchronous(optionOverride), ctx);
+                  for (Fqn fqn : fqns) invalidateAcrossCluster(fqn, null, isSynchronous(optionOverride), ctx);
                }
             }
          }
@@ -289,10 +290,23 @@
       return entry.getTransactionWorkSpace();
    }
 
-   protected Fqn findFqn(Object[] objects)
+   @SuppressWarnings("unchecked")
+   protected void findAndAddFqns(Object[] objects, Set<Fqn> fqns, boolean isMove)
    {
-      // it *should* be the 2nd param...
-      return (Fqn) objects[1];
+      if (isMove)
+      {
+         Fqn f = (Fqn) objects[0];
+         fqns.add(f);
+         // now if this is a "move" operation, then we also have another Fqn -
+         Object le = f.getLastElement();
+         Fqn parent = (Fqn) objects[1];
+         fqns.add(new Fqn(parent, le));
+      }
+      else
+      {
+         // it *should* be the 2nd param...
+         fqns.add((Fqn) objects[1]);
+      }
    }
 
    /**
@@ -312,7 +326,7 @@
          {
             if (MethodDeclarations.isCrudMethod(mc.getMethodId()))
             {
-               fqns.add(findFqn(mc.getArgs()));
+               findAndAddFqns(mc.getArgs(), fqns, MethodDeclarations.moveMethodLocal_id == mc.getMethodId());
             }
          }
       }

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java	2007-10-05 13:22:05 UTC (rev 4554)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/InvocationContextInterceptor.java	2007-10-05 13:22:46 UTC (rev 4555)
@@ -67,7 +67,7 @@
             if (suppressExceptions) return null;
 
             Throwable t = (Throwable) retval;
-            if (t instanceof RuntimeException)
+            if (t instanceof RuntimeException && t.getCause() != null)
                throw t.getCause();
             else
                throw t;

Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeReplicatedMoveTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeReplicatedMoveTest.java	2007-10-05 13:22:05 UTC (rev 4554)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeReplicatedMoveTest.java	2007-10-05 13:22:46 UTC (rev 4555)
@@ -6,12 +6,6 @@
  */
 package org.jboss.cache.api;
 
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-import static org.testng.AssertJUnit.fail;
-
-import javax.transaction.TransactionManager;
-
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
@@ -19,10 +13,14 @@
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.config.Configuration.CacheMode;
 import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import static org.testng.AssertJUnit.*;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import javax.transaction.TransactionManager;
+import java.util.Collections;
+
 @Test(groups = {"functional", "jgroups"})
 public class NodeReplicatedMoveTest
 {
@@ -93,6 +91,8 @@
       cache2.stop();
       cache1.destroy();
       cache2.destroy();
+      cache1.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
+      cache2.getConfiguration().setNodeLockingScheme(Configuration.NodeLockingScheme.OPTIMISTIC);
       cache1.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
       cache2.getConfiguration().setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
       cache1.start();
@@ -107,8 +107,8 @@
       assertEquals(vA, cache1.getRoot().getChild(A).get(k));
       assertEquals(vB, cache1.getRoot().getChild(A).getChild(B).get(k));
 
-      assertNull(cache2.getRoot().getChild(A));
-      assertNull(cache2.getRoot().getChild(B));
+      assert cache2.getRoot().getChild(A) != null : "Should not be null";
+      assert cache2.getRoot().getChild(A).getChild(B) != null : "Should not be null";
 
       // now move...
       cache1.move(nodeB.getFqn(), Fqn.ROOT);
@@ -116,21 +116,14 @@
       assertEquals(vA, cache1.getRoot().getChild(A).get(k));
       assertEquals(vB, cache1.getRoot().getChild(B).get(k));
 
-      assertNull(cache2.getRoot().getChild(A));
-      assertNull(cache2.getRoot().getChild(B));
+      assert cache2.getRoot().getChild(A) != null : "Should not be null";
+      assert cache2.getRoot().getChild(B) != null : "Should not be null";
 
       // now make sure a node exists on cache 2
-      cache2.getRoot().addChild(A);
+      cache2.getRoot().getChild(A).put("k2", "v2");
 
-      try
-      {
-         cache1.move(cache1.getRoot().getChild(B).getFqn(), cache1.getRoot().getChild(A).getFqn());// should throw an NPE
-         fail("Expecting an exception");
-      }
-      catch (Exception e)
-      {
-         // expected
-      }
+      // te invalidation will happen in afterCompletion, hence no exception!
+      cache1.move(cache1.getRoot().getChild(B).getFqn(), cache1.getRoot().getChild(A).getFqn());// should throw an NPE
    }
 
    public void testReplTxCommit() throws Exception




More information about the jbosscache-commits mailing list