[infinispan-commits] Infinispan SVN: r318 - trunk/core/src/test/java/org/infinispan/replication.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon May 18 05:41:00 EDT 2009
Author: vblagojevic at jboss.com
Date: 2009-05-18 05:41:00 -0400 (Mon, 18 May 2009)
New Revision: 318
Modified:
trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
Log:
handle tx/non-tx cases from same/different node
Modified: trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java 2009-05-18 03:57:41 UTC (rev 317)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java 2009-05-18 09:41:00 UTC (rev 318)
@@ -1,26 +1,50 @@
/*
* JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
*
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.infinispan.replication;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import javax.transaction.TransactionManager;
+
import org.infinispan.Cache;
import org.infinispan.config.Configuration;
import org.infinispan.test.MultipleCacheManagersTest;
import org.infinispan.test.TestingUtil;
import org.infinispan.transaction.lookup.DummyTransactionManagerLookup;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
import org.testng.annotations.Test;
-import javax.transaction.TransactionManager;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
/**
+ * Tests for lock/unlock API
+ *
+ * Introduce lock() and unlock() API methods
+ * https://jira.jboss.org/jira/browse/ISPN-48
+ *
+ *
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
+ * @author <a href="mailto:vblagoje at redhat.com">Vladimir Blagojevic (vblagoje at redhat.com)</a>
*/
@Test(groups = "functional", testName = "replication.SyncReplLockingTest")
public class SyncReplLockingTest extends MultipleCacheManagersTest {
@@ -46,7 +70,17 @@
locksReleasedWithoutExplicitUnlockHelper(false);
locksReleasedWithoutExplicitUnlockHelper(true);
}
+
+ public void testConcurrentNonTxLocking() throws Exception {
+ concurrentLockingHelper(false, false);
+ concurrentLockingHelper(true, false);
+ }
+ public void testConcurrentTxLocking() throws Exception {
+ concurrentLockingHelper(false, true);
+ concurrentLockingHelper(true, true);
+ }
+
private void lockingWithExplicitUnlockHelper(boolean lockPriorToPut) throws Exception {
assertClusterSize("Should only be 2 caches in the cluster!!!", 2);
@@ -76,21 +110,37 @@
assert cache2.isEmpty();
}
- public void testConcurrentLocking() throws Exception {
+ private void concurrentLockingHelper(final boolean sameNode, final boolean useTx)
+ throws Exception {
assertClusterSize("Should only be 2 caches in the cluster!!!", 2);
assertNull("Should be null", cache1.get(k));
assertNull("Should be null", cache2.get(k));
final CountDownLatch latch = new CountDownLatch(1);
-
Thread t = new Thread() {
@Override
public void run() {
- log.info("Concurrent non-tx write started....");
+ log.info("Concurrent " + (useTx ? "tx" : "non-tx") + " write started "
+ + (sameNode ? "on same node..." : "on a different node..."));
+ TransactionManager mgr = null;
try {
- cache2.put(k, "JBC");
+ if (useTx) {
+ mgr = TestingUtil.getTransactionManager(sameNode ? cache1 : cache2);
+ mgr.begin();
+ }
+ if (sameNode) {
+ cache1.put(k, "JBC");
+ } else {
+ cache2.put(k, "JBC");
+ }
} catch (Exception e) {
+ if (useTx) {
+ try {
+ mgr.commit();
+ } catch (Exception e1) {
+ }
+ }
latch.countDown();
}
}
@@ -99,7 +149,7 @@
String name = "Infinispan";
TransactionManager mgr = TestingUtil.getTransactionManager(cache1);
mgr.begin();
- //lock node and start other thread whose write should now block
+ // lock node and start other thread whose write should now block
cache1.getAdvancedCache().lock(k);
t.start();
@@ -139,5 +189,4 @@
assert cache1.isEmpty();
assert cache2.isEmpty();
}
-
}
More information about the infinispan-commits
mailing list