jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1486941 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
Date Tue, 28 May 2013 14:43:19 GMT
Author: mreutegg
Date: Tue May 28 14:43:19 2013
New Revision: 1486941

URL: http://svn.apache.org/r1486941
Log:
OAK-847: Condition check broken in MemoryDocumentStore

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java?rev=1486941&r1=1486940&r2=1486941&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
Tue May 28 14:43:19 2013
@@ -178,14 +178,14 @@ public class MemoryDocumentStore impleme
                         return false;
                     }
                 } else {
-                    if (value instanceof java.util.Collection) {
-                        java.util.Collection<?> col = (java.util.Collection<?>)
value;
+                    if (value instanceof Map) {
+                        Map map = (Map) value;
                         if (Boolean.TRUE.equals(op.value)) {
-                            if (!col.contains(kv[1])) {
+                            if (!map.containsKey(kv[1])) {
                                 return false;
                             }
                         } else {
-                            if (col.contains(kv[1])) {
+                            if (map.containsKey(kv[1])) {
                                 return false;
                             }
                         }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java?rev=1486941&r1=1486940&r2=1486941&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
Tue May 28 14:43:19 2013
@@ -17,6 +17,8 @@
 package org.apache.jackrabbit.mongomk;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
@@ -141,6 +143,46 @@ public class MongoDocumentStoreTest {
     }
 
     @Test
+    public void containsMapEntry() {
+        dropCollections();
+
+        DocumentStore docStore = openDocumentStore();
+        UpdateOp op = new UpdateOp("/node", "/node", true);
+        op.setMapEntry("map", "key", "value");
+        docStore.createOrUpdate(Collection.NODES, op);
+
+        op = new UpdateOp("/node", "/node", false);
+        op.set("prop", "value");
+        op.containsMapEntry("map", "unknown-key", true);
+        // update if unknown-key exists -> must not succeed
+        assertNull(docStore.findAndUpdate(Collection.NODES, op));
+
+        op = new UpdateOp("/node", "/node", false);
+        op.set("prop", "value");
+        op.containsMapEntry("map", "key", true);
+        // update if key exists -> must succeed
+        Map doc = docStore.findAndUpdate(Collection.NODES, op);
+        assertNotNull(doc);
+
+        doc = docStore.find(Collection.NODES, "/node");
+        assertTrue(doc.containsKey("prop"));
+        assertEquals("value", doc.get("prop"));
+
+        op = new UpdateOp("/node", "/node", false);
+        op.set("prop", "other");
+        op.containsMapEntry("map", "key", false);
+        // update if key does not exist -> must not succeed
+        assertNull(docStore.findAndUpdate(Collection.NODES, op));
+
+        // value must still be the same
+        doc = docStore.find(Collection.NODES, "/node");
+        assertTrue(doc.containsKey("prop"));
+        assertEquals("value", doc.get("prop"));
+
+        dropCollections();
+    }
+
+    @Test
     @Ignore
     public void batchInsert() throws Exception {
         doInsert(NODE_COUNT, true);



Mime
View raw message