[infinispan-commits] Infinispan SVN: r2094 - 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 Jul 22 15:33:38 EDT 2010


Author: vblagojevic at jboss.com
Date: 2010-07-22 15:33:38 -0400 (Thu, 22 Jul 2010)
New Revision: 2094

Modified:
   trunk/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java
   trunk/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java
   trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
Log:
[ISPN-514] - replace(Async) with eager locking


Modified: trunk/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java	2010-07-22 19:22:34 UTC (rev 2093)
+++ trunk/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java	2010-07-22 19:33:38 UTC (rev 2094)
@@ -63,7 +63,8 @@
       MVCCEntry e = (MVCCEntry) ctx.lookupEntry(key);
       if (e != null) {
          if (ctx.isOriginLocal()) {
-            if (e.isNull()) return returnValue(null, false);
+        	 	//ISPN-514
+            if (e.isNull() || e.getValue() == null) return returnValue(null, false);    
 
             if (oldValue == null || oldValue.equals(e.getValue())) {
                Object old = e.setValue(newValue);

Modified: trunk/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java	2010-07-22 19:22:34 UTC (rev 2093)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java	2010-07-22 19:33:38 UTC (rev 2094)
@@ -84,7 +84,33 @@
       assertNoLocks(cache2);
       cache1.clear();cache2.clear();
    }
+   
+	public void testReplaceNonExistentKey() throws Exception {
+		assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
+		Cache cache1 = cache(0, "replication.SyncReplImplicitLockingTest");
+		Cache cache2 = cache(1, "replication.SyncReplImplicitLockingTest");
 
+		TransactionManager mgr = TestingUtil.getTransactionManager(cache1);
+		mgr.begin();
+
+		// do a replace on empty key
+		// https://jira.jboss.org/browse/ISPN-514
+		Object old = cache1.replace(k, "blah");
+
+		boolean replaced = cache1.replace(k, "Vladimir", "Blagojevic");
+		assert !replaced;
+
+		assertNull("Should be null", cache1.get(k));
+		assertNull("Should be null", cache2.get(k));
+
+		mgr.commit();
+
+		assertNoLocks(cache1);
+		assertNoLocks(cache2);
+		cache1.clear();
+		cache2.clear();
+	}  
+
    private void concurrentLockingHelper(final boolean sameNode, final boolean useTx)
          throws Exception {
       

Modified: trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java	2010-07-22 19:22:34 UTC (rev 2093)
+++ trunk/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java	2010-07-22 19:33:38 UTC (rev 2094)
@@ -98,6 +98,36 @@
       cache2.clear();
    }
    
+	public void testReplaceNonExistentKey() throws Exception {
+		Cache cache1 = cache(0, "replSync");
+		Cache cache2 = cache(1, "replSync");
+		assertClusterSize("Should only be 2  caches in the cluster!!!", 2);
+
+		TransactionManager mgr = TestingUtil.getTransactionManager(cache1);
+		mgr.begin();
+
+		cache1.getAdvancedCache().lock(k);
+
+		// do a replace on empty key
+		// https://jira.jboss.org/browse/ISPN-514
+		Object old = cache1.replace(k, "blah");
+		assertNull("Should be null", cache1.get(k));
+
+		boolean replaced = cache1.replace(k, "Vladimir", "Blagojevic");
+		assert !replaced;
+
+		assertNull("Should be null", cache1.get(k));
+		mgr.commit();
+
+		assertNoLocks(cache1);
+		assertNoLocks(cache2);
+
+		assert cache1.isEmpty();
+		assert cache2.isEmpty();
+		cache1.clear();
+		cache2.clear();
+	}
+   
    private void concurrentLockingHelper(final boolean sameNode, final boolean useTx)
          throws Exception {
       final Cache cache1 = cache(0, "replSync");



More information about the infinispan-commits mailing list