[infinispan-commits] Infinispan SVN: r298 - trunk/core/src/test/java/org/infinispan/replication.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu May 14 09:36:58 EDT 2009
Author: manik.surtani at jboss.com
Date: 2009-05-14 09:36:58 -0400 (Thu, 14 May 2009)
New Revision: 298
Modified:
trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
Log:
Updated test
Modified: trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java 2009-05-14 13:36:13 UTC (rev 297)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java 2009-05-14 13:36:58 UTC (rev 298)
@@ -6,22 +6,19 @@
*/
package org.infinispan.replication;
-import static org.testng.AssertJUnit.assertEquals;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-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 org.infinispan.util.concurrent.locks.LockManager;
-import org.jgroups.util.Util;
+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;
+
/**
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
*/
@@ -32,6 +29,7 @@
protected void createCacheManagers() throws Throwable {
Configuration replSync = getDefaultClusteredConfig(Configuration.CacheMode.REPL_SYNC);
+ replSync.setLockAcquisitionTimeout(500);
replSync.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
createClusteredCaches(2, "replSync", replSync);
@@ -39,13 +37,13 @@
cache2 = manager(1).getCache("replSync");
}
- @Test(enabled=true)
+ @Test(enabled = true)
public void testLockingWithExplicitUnlock() throws Exception {
lockingWithExplicitUnlockHelper(false);
lockingWithExplicitUnlockHelper(true);
}
- @Test(enabled=true)
+ @Test(enabled = true)
public void testLocksReleasedWithoutExplicitUnlock() throws Exception {
locksReleasedWithoutExplicitUnlockHelper(false);
locksReleasedWithoutExplicitUnlockHelper(true);
@@ -79,24 +77,27 @@
assert cache1.isEmpty();
assert cache2.isEmpty();
}
-
- @Test(enabled=true)
+
+ @Test(enabled = true)
public void testConcurrentLocking() 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 AtomicBoolean writeBlocked = new AtomicBoolean(false);
-
- Thread t = new Thread(){@Override
+ final CountDownLatch latch = new CountDownLatch(1);
+
+
+ Thread t = new Thread() {
+ @Override
public void run() {
log.info("Concurrent non-tx write started....");
- long start = System.currentTimeMillis();
- cache2.put(k, "JBC");
- long duration = System.currentTimeMillis() - start;
- log.info("Concurrent non-tx write finished");
- writeBlocked.set(duration > 1000);
- }};
+ try {
+ cache2.put(k, "JBC");
+ } catch (Exception e) {
+ latch.countDown();
+ }
+ }
+ };
String name = "Infinispan";
TransactionManager mgr = TestingUtil.getTransactionManager(cache1);
@@ -104,16 +105,18 @@
//lock node and start other thread whose write should now block
cache1.getAdvancedCache().lock(k);
t.start();
-
- //hold lock
- TestingUtil.sleepThread(3000);
+
+ // wait till the put in thread t times out
+ assert latch.await(1, TimeUnit.SECONDS) : "Concurrent put didn't time out!";
+
cache1.put(k, name);
mgr.commit();
+ t.join();
+
cache2.remove(k);
assert cache1.isEmpty();
assert cache2.isEmpty();
- assert writeBlocked.get();
}
private void locksReleasedWithoutExplicitUnlockHelper(boolean lockPriorToPut) throws Exception {
More information about the infinispan-commits
mailing list