mreutegg commented on code in PR #651:
URL: https://github.com/apache/jackrabbit-oak/pull/651#discussion_r981036817


##########
oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoVersionGCSupportDefaultNoBranchTest.java:
##########
@@ -0,0 +1,431 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.document;
+
+import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
+import static 
org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture.MONGO;
+import static 
org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.COMMIT_ROOT_ONLY;
+import static 
org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.DEFAULT_LEAF;
+import static 
org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType.DEFAULT_NO_BRANCH;
+import static 
org.apache.jackrabbit.oak.plugins.document.SplitOperations.forDocument;
+import static 
org.apache.jackrabbit.oak.plugins.document.util.Utils.getIdFromPath;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.plugins.document.DocumentMK.Builder;
+import 
org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture.MongoFixture;
+import org.apache.jackrabbit.oak.plugins.document.NodeDocument.SplitDocType;
+import 
org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoTestCollection;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoTestDatabase;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoTestUtils;
+import org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport;
+import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
+import org.apache.jackrabbit.oak.plugins.document.util.Utils;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+import com.mongodb.ReadPreference;
+import com.mongodb.client.MongoCollection;
+import com.mongodb.client.MongoDatabase;
+
+@RunWith(Parameterized.class)
+public class MongoVersionGCSupportDefaultNoBranchTest {
+
+    private static class Stats {
+        private final VersionGCStats versionGCStats;
+        private final int nodesDeleteMany;
+        Stats(VersionGCStats stats, int nodesDeleteMany) {
+            if (stats == null) {
+                throw new IllegalArgumentException("stats must not be null");
+            }
+            if (nodesDeleteMany < 0) {
+                throw new IllegalArgumentException("nodesDeleteMany must be 
positive");
+            }
+            this.versionGCStats = stats;
+            this.nodesDeleteMany = nodesDeleteMany;
+        }
+    }
+
+    private static Predicate<NodeDocument> splitDocsWithClusterId(final int 
clusterId) {
+        return new Predicate<NodeDocument>() {
+            @Override
+            public boolean apply(@Nullable NodeDocument doc) {
+                if (!Utils.isPreviousDocId(doc.getId())) {
+                    return false;
+                }
+                Path p = doc.getPath();
+                p = p.getAncestor(1);
+                Revision rev = Revision.fromString(p.getName());
+                return rev.getClusterId() == clusterId;
+            }
+        };
+    }
+
+    private static final Set<NodeDocument.SplitDocType> GC_TYPES = EnumSet.of(
+            DEFAULT_LEAF, COMMIT_ROOT_ONLY, DEFAULT_NO_BRANCH);
+
+    class MongoVersionGCSupportAccessor extends MongoVersionGCSupport {
+
+        public MongoVersionGCSupportAccessor(MongoDocumentStore store) {
+            super(store);
+        }
+
+        protected Iterable<NodeDocument> identifyGarbage(Set<SplitDocType> 
gcTypes,
+                RevisionVector sweepRevs, long oldestRevTimeStamp) {
+            return super.identifyGarbage(gcTypes, sweepRevs, 
oldestRevTimeStamp);
+        }
+    }
+    // using AbstractTwoNodeTest as a helper rather than subclassing to 
simplify things
+    private AbstractTwoNodeTest helper;
+    private DocumentStoreFixture fixture;
+    private DocumentStore store1;
+    private DocumentStore store2;
+    protected DocumentNodeStore ds1;
+    protected DocumentNodeStore ds2;
+    private VersionGCSupport gcSupport1;
+    private List<String> ids = Lists.newArrayList();
+
+    private Clock clock;
+    private AtomicInteger offset = new AtomicInteger(0);
+
+    private final static AtomicInteger nodesDeleteMany = new AtomicInteger(0);
+
+    @Parameterized.Parameters(name="{0}")
+    public static java.util.Collection<DocumentStoreFixture> fixtures() {
+        List<DocumentStoreFixture> fixtures = Lists.newArrayList();
+        if (MONGO.isAvailable()) {
+            fixtures.add(new MongoFixture() {
+                @Override
+                public DocumentStore createDocumentStore(Builder builder) {
+                    try {
+                        MongoConnection connection = 
MongoUtils.getConnection();
+                        connections.add(connection);
+                        MongoDatabase db = connection.getDatabase();
+                        final AtomicReference<String> noEx = new 
AtomicReference<>(null);
+                        MongoTestDatabase testDb = new MongoTestDatabase(db, 
noEx, noEx, noEx) {

Review Comment:
   Could this also go to `CountingMongoDatabase` and `CountingMongoCollection`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to