You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2020/09/24 09:34:43 UTC

svn commit: r1881975 - /jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java

Author: mreutegg
Date: Thu Sep 24 09:34:43 2020
New Revision: 1881975

URL: http://svn.apache.org/viewvc?rev=1881975&view=rev
Log:
OAK-9229: CountingDocumentStore returns documents with incorrect store reference

Modified:
    jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java

Modified: jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java?rev=1881975&r1=1881974&r2=1881975&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java (original)
+++ jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/CountingDocumentStore.java Thu Sep 24 09:34:43 2020
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.document;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -82,7 +83,7 @@ public class CountingDocumentStore imple
         if (printStacks) {
             new Exception("find [" + getStats(collection).numFindCalls + "] (" + collection + ") " + key).printStackTrace();
         }
-        return delegate.find(collection, key);
+        return rewrap(collection, delegate.find(collection, key));
     }
 
     @Override
@@ -93,7 +94,7 @@ public class CountingDocumentStore imple
         if (printStacks) {
             new Exception("find [" + getStats(collection).numFindCalls + "] (" + collection + ") " + key + " [max: " + maxCacheAge + "]").printStackTrace();
         }
-        return delegate.find(collection, key, maxCacheAge);
+        return rewrap(collection, delegate.find(collection, key, maxCacheAge));
     }
 
     @NotNull
@@ -106,7 +107,7 @@ public class CountingDocumentStore imple
         if (printStacks) {
             new Exception("query1 [" + getStats(collection).numQueryCalls + "] (" + collection + ") " + fromKey + ", to " + toKey + ". limit " + limit).printStackTrace();
         }
-        return delegate.query(collection, fromKey, toKey, limit);
+        return rewrap(collection, delegate.query(collection, fromKey, toKey, limit));
     }
 
     @NotNull
@@ -121,7 +122,7 @@ public class CountingDocumentStore imple
         if (printStacks) {
             new Exception("query2 [" + getStats(collection).numQueryCalls + "] (" + collection + ") " + fromKey + ", to " + toKey + ". limit " + limit).printStackTrace();
         }
-        return delegate.query(collection, fromKey, toKey, indexedProperty, startValue, limit);
+        return rewrap(collection, delegate.query(collection, fromKey, toKey, indexedProperty, startValue, limit));
     }
 
     @Override
@@ -164,21 +165,21 @@ public class CountingDocumentStore imple
     public <T extends Document> T createOrUpdate(Collection<T> collection,
                                                  UpdateOp update) {
         getStats(collection).numCreateOrUpdateCalls++;
-        return delegate.createOrUpdate(collection, update);
+        return rewrap(collection, delegate.createOrUpdate(collection, update));
     }
 
     @Override
     public <T extends Document> List<T> createOrUpdate(Collection<T> collection,
                                                        List<UpdateOp> updateOps) {
         getStats(collection).numCreateOrUpdateCalls++;
-        return delegate.createOrUpdate(collection, updateOps);
+        return rewrap(collection, delegate.createOrUpdate(collection, updateOps));
     }
 
     @Override
     public <T extends Document> T findAndUpdate(Collection<T> collection,
                                                 UpdateOp update) {
         getStats(collection).numCreateOrUpdateCalls++;
-        return delegate.findAndUpdate(collection, update);
+        return rewrap(collection, delegate.findAndUpdate(collection, update));
     }
 
     @Override
@@ -205,7 +206,7 @@ public class CountingDocumentStore imple
     @Override
     public <T extends Document> T getIfCached(Collection<T> collection,
                                               String key) {
-        return delegate.getIfCached(collection, key);
+        return rewrap(collection, delegate.getIfCached(collection, key));
     }
 
     @Override
@@ -233,4 +234,22 @@ public class CountingDocumentStore imple
     public long determineServerTimeDifferenceMillis() {
         return delegate.determineServerTimeDifferenceMillis();
     }
+
+    private <T extends Document> T rewrap(Collection<T> collection, T doc) {
+        if (doc == null) {
+            return null;
+        }
+        T d = collection.newDocument(this);
+        doc.deepCopy(d);
+        return d;
+    }
+
+    private <T extends Document> List<T> rewrap(Collection<T> collection,
+                                                List<T> docs) {
+        List<T> docList = new ArrayList<>(docs.size());
+        for (T d : docs) {
+            docList.add(rewrap(collection, d));
+        }
+        return docList;
+    }
 }