[infinispan-commits] Infinispan SVN: r290 - in trunk/core/src: test/java/org/infinispan/replication and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu May 14 06:20:10 EDT 2009
Author: vblagojevic at jboss.com
Date: 2009-05-14 06:20:10 -0400 (Thu, 14 May 2009)
New Revision: 290
Modified:
trunk/core/src/main/java/org/infinispan/interceptors/LockingInterceptor.java
trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
Log:
[ISPN-48] - Introduce lock() and unlock() API methods
handle cases with no explicit unlock call
Modified: trunk/core/src/main/java/org/infinispan/interceptors/LockingInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/LockingInterceptor.java 2009-05-14 10:17:09 UTC (rev 289)
+++ trunk/core/src/main/java/org/infinispan/interceptors/LockingInterceptor.java 2009-05-14 10:20:10 UTC (rev 290)
@@ -144,13 +144,7 @@
}
if (c.isLock()) {
for (Object key : c.getKeys()) {
- boolean needed = entryFactory.acquireLock(ctx, key);
- if (trace) {
- if (needed)
- log.trace("Key " + key + " was needed and acquired by " + ctx.getLockOwner());
- else
- log.trace("Key " + key + " was already held by " + ctx.getLockOwner());
- }
+ entryFactory.wrapEntryForWriting(ctx, key, false, false, false, false);
}
} else if (c.isUnlock()) {
for (Object key : c.getKeys()) {
Modified: trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java 2009-05-14 10:17:09 UTC (rev 289)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java 2009-05-14 10:20:10 UTC (rev 290)
@@ -16,6 +16,8 @@
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 org.testng.annotations.Test;
/**
@@ -23,7 +25,7 @@
*/
@Test(groups = "functional", testName = "replication.SyncReplLockingTest")
public class SyncReplLockingTest extends MultipleCacheManagersTest {
- Cache<String,String> cache1, cache2;
+ Cache<String, String> cache1, cache2;
String k = "key", v = "value";
protected void createCacheManagers() throws Throwable {
@@ -35,20 +37,34 @@
cache2 = manager(1).getCache("replSync");
}
- public void testBasicOperation() throws Exception {
+ public void testLockingWithExplicitUnlock() throws Exception {
+ lockingWithExplicitUnlockHelper(false);
+ lockingWithExplicitUnlockHelper(true);
+ }
+
+ public void testLocksReleasedWithoutExplicitUnlock() throws Exception {
+ locksReleasedWithoutExplicitUnlockHelper(false);
+ locksReleasedWithoutExplicitUnlockHelper(true);
+ }
+
+ private void lockingWithExplicitUnlockHelper(boolean lockPriorToPut) 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));
-
String name = "Vladimir";
TransactionManager mgr = TestingUtil.getTransactionManager(cache1);
mgr.begin();
-
+ if (lockPriorToPut)
+ cache1.getAdvancedCache().lock(k);
+
cache1.put(k, v);
- cache1.getAdvancedCache().lock(k);
+
cache1.put(k, name);
+ if (!lockPriorToPut)
+ cache1.getAdvancedCache().lock(k);
+
cache1.getAdvancedCache().unlock(k);
mgr.commit();
@@ -59,4 +75,29 @@
assert cache1.isEmpty();
assert cache2.isEmpty();
}
+
+ private void locksReleasedWithoutExplicitUnlockHelper(boolean lockPriorToPut) 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));
+
+ String name = "Infinispan";
+ TransactionManager mgr = TestingUtil.getTransactionManager(cache1);
+ mgr.begin();
+ if (lockPriorToPut)
+ cache1.getAdvancedCache().lock(k);
+ cache1.put(k, name);
+ if (!lockPriorToPut)
+ cache1.getAdvancedCache().lock(k);
+ mgr.commit();
+
+ assertEquals(name, cache1.get(k));
+ assertEquals("Should have replicated", name, cache2.get(k));
+
+ cache2.remove(k);
+ assert cache1.isEmpty();
+ assert cache2.isEmpty();
+ }
+
}
More information about the infinispan-commits
mailing list