stefan-egli commented on code in PR #950: URL: https://github.com/apache/jackrabbit-oak/pull/950#discussion_r1202375474
########## oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/UnrecoveredRevisionTest.java: ########## @@ -0,0 +1,813 @@ +/* + * 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.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReadWriteLock; + +import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore; +import org.apache.jackrabbit.oak.plugins.document.util.LeaseCheckDocumentStoreWrapper; +import org.apache.jackrabbit.oak.spi.commit.CommitInfo; +import org.apache.jackrabbit.oak.spi.commit.EmptyHook; +import org.apache.jackrabbit.oak.spi.state.NodeBuilder; +import org.apache.jackrabbit.oak.spi.state.NodeState; +import org.apache.jackrabbit.oak.stats.Clock; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import junitx.util.PrivateAccessor; + +/** + * Tests unrecovered revisions on a document + */ +public class UnrecoveredRevisionTest { + + interface BreakpointCallback { + + void breakpointCallback(String contextMsg); + + } + + class ControllableMemoryDocumentStore extends MemoryDocumentStore { + + private final AtomicInteger remainingOps; + private BreakpointCallback callback; + private Set<Collection<?>> restrictedCollections = new HashSet<>(); + private List<UpdateOp> writtenUpdateOps = new LinkedList<>(); + + ControllableMemoryDocumentStore(int remainingOps, BreakpointCallback callback) { + this.remainingOps = new AtomicInteger(remainingOps); + this.callback = callback; + // restrict only NODES by default + this.restrictedCollections.add(Collection.NODES); + } + + public void clearOps() { + writtenUpdateOps.clear(); + } + + public void printOps() { + for (UpdateOp updateOp : writtenUpdateOps) { + System.out.println("written updateOp: " + updateOp.toString()); + } + } + + private void registerWrittenUpdateOp(Collection<?> collection, UpdateOp updateOp) { + if (restrictedCollections.contains(collection)) { + writtenUpdateOps.add(updateOp); + } + } + + private void registerWrittenUpdateOp(Collection<?> collection, List<UpdateOp> trimmedOps) { + if (restrictedCollections.contains(collection)) { + writtenUpdateOps.addAll(trimmedOps); + } + } + + private void setBreakpointCallback(BreakpointCallback callback) { + this.callback = callback; + } + + @SuppressWarnings("unused") + private void setRestrictedCollections(Collection<?>... collections) { Review Comment: I'd prefer to have it in for now? I was expecting (or let's say hoping) it to eventually be used, once we go more fancy with test coverage. -- 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]
