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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Nov 24 13:01:37 EST 2008


Author: mircea.markus
Date: 2008-11-24 13:01:37 -0500 (Mon, 24 Nov 2008)
New Revision: 7188

Modified:
   core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java
   core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java
Log:
fix and ut for https://jira.jboss.org/jira/browse/JBCACHE-1445

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java	2008-11-24 07:17:06 UTC (rev 7187)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/LegacyDataGravitatorInterceptor.java	2008-11-24 18:01:37 UTC (rev 7188)
@@ -32,6 +32,7 @@
 import org.jboss.cache.commands.CommandsFactory;
 import org.jboss.cache.commands.DataCommand;
 import org.jboss.cache.commands.ReplicableCommand;
+import org.jboss.cache.commands.VisitableCommand;
 import org.jboss.cache.commands.read.GetChildrenNamesCommand;
 import org.jboss.cache.commands.read.GetDataMapCommand;
 import org.jboss.cache.commands.read.GetKeyValueCommand;
@@ -41,6 +42,8 @@
 import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
 import org.jboss.cache.commands.tx.CommitCommand;
 import org.jboss.cache.commands.tx.RollbackCommand;
+import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.marshall.NodeData;
 import org.jboss.cache.transaction.GlobalTransaction;
@@ -143,9 +146,35 @@
       }
    }
 
+
+   /**
+    * Make sure you also run a cleanup if we have an 1pc.
+    */
    @Override
+   public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+   {
+      if (command.isOnePhaseCommit())
+      {
+         return dataGravitationCleanupOnCommit(ctx, command);
+      }
+      return invokeNextInterceptor(ctx, command);
+   }
+
+   @Override
    public Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
    {
+      return dataGravitationCleanupOnCommit(ctx, command);
+   }
+
+   @Override
+   public Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
+   {
+      return visitPrepareCommand(ctx, command);
+   }
+
+   private Object dataGravitationCleanupOnCommit(InvocationContext ctx, VisitableCommand command)
+         throws Throwable
+   {
       GlobalTransaction gtx = ctx.getGlobalTransaction();
       try
       {

Modified: core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java	2008-11-24 07:17:06 UTC (rev 7187)
+++ core/trunk/src/test/java/org/jboss/cache/buddyreplication/GravitationCleanupTest.java	2008-11-24 18:01:37 UTC (rev 7188)
@@ -2,10 +2,14 @@
 
 import org.jboss.cache.CacheSPI;
 import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.remote.DataGravitationCleanupCommand;
+import org.jboss.cache.config.Configuration;
 import org.jboss.cache.util.CachePrinter;
 import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.util.internals.replicationlisteners.ReplicationListener;
 import org.testng.annotations.Test;
 
+import javax.transaction.TransactionManager;
 import java.util.List;
 
 /**
@@ -39,6 +43,45 @@
       testBuddy(true);
    }
 
+   /**
+    * UT for https://jira.jboss.org/jira/browse/JBCACHE-1445.
+    */
+   public void testDataGravitationCleanup1Pc() throws Exception
+   {
+      CacheSPI cache0 = createCache(1, null, true, false);
+      cache0.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+      CacheSPI cache1 = createCache(1, null, true, false);
+      cache1.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+      cache0.start();
+      cache1.start();
+      try
+      {
+         waitForSingleBuddy(cache0, cache1);
+
+         Fqn fqn = Fqn.fromString("/a/b/c");
+
+         assert  null == cache0.get(fqn, "k");
+         cache0.put(fqn, "key", "val");
+
+         ReplicationListener replicationListener = ReplicationListener.getReplicationListener(cache0);
+         replicationListener.expect(DataGravitationCleanupCommand.class);
+         TransactionManager transactionManager = cache1.getTransactionManager();
+
+         transactionManager.begin();
+         assert cache1.get(fqn, "key").equals("val");
+         transactionManager.commit();
+         replicationListener.waitForReplicationToOccur(1000);
+
+         assert !cache0.exists(fqn);
+
+         System.out.println(CachePrinter.printCacheDetails(cache0));
+      } finally
+      {
+         TestingUtil.killCaches(cache0, cache1);
+      }
+   }
+
+
    private void testDataOwner(boolean optimistic) throws Exception
    {
       List<CacheSPI<Object, Object>> caches = createCaches(1, 2, false, true, optimistic);




More information about the jbosscache-commits mailing list