Author: manik.surtani(a)jboss.com
Date: 2009-08-05 08:23:47 -0400 (Wed, 05 Aug 2009)
New Revision: 8152
Added:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareOptimisticTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareTest.java
core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc/Buddy3NodesFailedRemotePrepareTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
Log:
JBCACHE-1526 GlobalTransaction lost upon buddy fqn transformation of RollbackCommand
Modified:
core/trunk/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java 2009-08-05
11:55:43 UTC (rev 8151)
+++
core/trunk/src/main/java/org/jboss/cache/buddyreplication/Fqn2BuddyFqnVisitor.java 2009-08-05
12:23:47 UTC (rev 8152)
@@ -207,7 +207,7 @@
@Override
public Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command)
throws Throwable
{
- return factory.buildRollbackCommand(null);
+ return factory.buildRollbackCommand(command.getGlobalTransaction());
}
@Override
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2009-08-05
11:55:43 UTC (rev 8151)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java 2009-08-05
12:23:47 UTC (rev 8152)
@@ -256,7 +256,7 @@
try
{
broadcastTxs.remove(gtx);
- RollbackCommand rollbackCommand =
commandsFactory.buildRollbackCommand(null);
+ RollbackCommand rollbackCommand = commandsFactory.buildRollbackCommand(gtx);
if (log.isDebugEnabled())
log.debug("running remote rollback for " + gtx + " and
coord=" + rpcManager.getLocalAddress());
Added:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareOptimisticTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareOptimisticTest.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareOptimisticTest.java 2009-08-05
12:23:47 UTC (rev 8152)
@@ -0,0 +1,12 @@
+package org.jboss.cache.buddyreplication;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", testName =
"buddyreplication.Buddy3NodesFailedRemotePrepareOptimisticTest")
+public class Buddy3NodesFailedRemotePrepareOptimisticTest extends
Buddy3NodesFailedRemotePrepareTest
+{
+ public Buddy3NodesFailedRemotePrepareOptimisticTest()
+ {
+ optimistic = true;
+ }
+}
Property changes on:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareOptimisticTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareTest.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareTest.java 2009-08-05
12:23:47 UTC (rev 8152)
@@ -0,0 +1,100 @@
+package org.jboss.cache.buddyreplication;
+
+import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.util.TestingUtil;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.transaction.DummyTransactionManagerLookup;
+import org.testng.annotations.Test;
+
+import javax.transaction.RollbackException;
+import javax.transaction.TransactionManager;
+import java.util.List;
+
+/**
+ * Tests that a failed PREPARE on a buddy results in a proper rollback.
+ *
+ * @author Brian Stansberry
+ * @since 3.1.12
+ */
+@Test(groups = "functional", testName =
"buddyreplication.Buddy3NodesFailedRemotePrepareTest")
+public class Buddy3NodesFailedRemotePrepareTest extends BuddyReplicationTestsBase
+{
+ boolean optimistic = false;
+
+ @CacheListener
+ public static class FailureListener
+ {
+ private boolean rejected;
+
+ @NodeModified
+ public void nodeModified(NodeModifiedEvent event)
+ {
+ if (!rejected && !event.isOriginLocal() &&
event.getFqn().hasElement("0"))
+ {
+ rejected = true;
+ throw new RuntimeException("rejected");
+ }
+ }
+ }
+
+ @Test (invocationCount = 100)
+ public void testFailedPrepare() throws Exception
+ {
+ List<CacheSPI<Object, Object>> caches = createCaches(2, 3, false,
false, optimistic, false);
+ cachesTL.set(caches);
+
+ int cacheNumber = 0;
+ for (CacheSPI<Object, Object> c : caches)
+ {
+ c.getConfiguration().setFetchInMemoryState(false);
+
c.getConfiguration().setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ c.start();
+ c.put("/" + cacheNumber++, "k", "v");
+ }
+
+ waitForBuddy(caches.get(0), caches.get(1), false);
+ waitForBuddy(caches.get(0), caches.get(2), false);
+ waitForBuddy(caches.get(1), caches.get(2), false);
+ waitForBuddy(caches.get(1), caches.get(0), false);
+ waitForBuddy(caches.get(2), caches.get(0), false);
+ waitForBuddy(caches.get(2), caches.get(1), false);
+ Thread.sleep(2000);//wait for state transfer
+
+ caches.get(0).put("/0", "k", "v");
+ Fqn backup = fqnTransformer.getBackupFqn(caches.get(0).getLocalAddress(),
Fqn.fromString("/0"));
+ assert (caches.get(1).exists(backup));
+ assert (caches.get(2).exists(backup));
+
+ caches.get(2).addCacheListener(new FailureListener());
+
+ TransactionManager tm = caches.get(0).getTransactionManager();
+ tm.begin();
+ caches.get(0).put("/0", "k", "v1");
+
+ try
+ {
+ tm.commit();
+ assert false : "Put should have thrown an exception";
+ }
+ catch (RollbackException expected)
+ {
+ expected.printStackTrace(System.out);
+ }
+
+ Object val = caches.get(0).get("/0", "k");
+ assert "v".equals(val) : "cache 0 had " + val;
+
+
caches.get(2).getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
+ val = caches.get(2).get("/0", "k");
+ TestingUtil.sleepThread(100);
+ assert "v".equals(val) : "cache 2 had " + val;
+
+
caches.get(1).getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
+ val = caches.get(1).get("/0", "k");
+ TestingUtil.sleepThread(100);
+ assert "v".equals(val) : "cache 1 had " + val;
+ }
+}
Property changes on:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/Buddy3NodesFailedRemotePrepareTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc/Buddy3NodesFailedRemotePrepareTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc/Buddy3NodesFailedRemotePrepareTest.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc/Buddy3NodesFailedRemotePrepareTest.java 2009-08-05
12:23:47 UTC (rev 8152)
@@ -0,0 +1,15 @@
+package org.jboss.cache.buddyreplication.mvcc;
+
+import org.jboss.cache.config.Configuration;
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", testName =
"buddyreplication.mvcc.Buddy3NodesFailedRemotePrepareTest")
+public class Buddy3NodesFailedRemotePrepareTest extends
org.jboss.cache.buddyreplication.Buddy3NodesFailedRemotePrepareTest
+{
+ @Override
+ protected Configuration.NodeLockingScheme getNonOptimisticLockingScheme()
+ {
+ return Configuration.NodeLockingScheme.MVCC;
+ }
+
+}
Property changes on:
core/trunk/src/test/java/org/jboss/cache/buddyreplication/mvcc/Buddy3NodesFailedRemotePrepareTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF