[infinispan-commits] Infinispan SVN: r2093 - in branches/4.1.x/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:22:35 EDT 2010


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

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


Modified: branches/4.1.x/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java	2010-07-21 17:27:13 UTC (rev 2092)
+++ branches/4.1.x/core/src/main/java/org/infinispan/commands/write/ReplaceCommand.java	2010-07-22 19:22:34 UTC (rev 2093)
@@ -63,8 +63,9 @@
       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);
                e.setLifespan(lifespanMillis);

Modified: branches/4.1.x/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java
===================================================================
--- branches/4.1.x/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java	2010-07-21 17:27:13 UTC (rev 2092)
+++ branches/4.1.x/core/src/test/java/org/infinispan/replication/SyncReplImplicitLockingTest.java	2010-07-22 19:22:34 UTC (rev 2093)
@@ -84,7 +84,32 @@
       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: branches/4.1.x/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java
===================================================================
--- branches/4.1.x/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java	2010-07-21 17:27:13 UTC (rev 2092)
+++ branches/4.1.x/core/src/test/java/org/infinispan/replication/SyncReplLockingTest.java	2010-07-22 19:22:34 UTC (rev 2093)
@@ -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