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 2016/06/22 10:09:52 UTC

svn commit: r1749645 - /jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java

Author: mreutegg
Date: Wed Jun 22 10:09:52 2016
New Revision: 1749645

URL: http://svn.apache.org/viewvc?rev=1749645&view=rev
Log:
OAK-4494: Tests for revision GC in cluster

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java   (with props)

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java?rev=1749645&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java Wed Jun 22 10:09:52 2016
@@ -0,0 +1,195 @@
+/*
+ * 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 java.util.concurrent.TimeUnit;
+
+import com.google.common.collect.Lists;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats;
+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.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.stats.Clock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+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.assertNull;
+import static org.junit.Assert.assertTrue;
+
+@Ignore
+public class ResurrectNodeAfterRevisionGCTest
+        extends AbstractMultiDocumentStoreTest {
+
+    private Clock c;
+    private DocumentNodeStore ns1;
+    private DocumentNodeStore ns2;
+
+    public ResurrectNodeAfterRevisionGCTest(DocumentStoreFixture dsf) {
+        super(dsf);
+    }
+
+    @Before
+    public void prepare() throws Exception {
+        removeMe.add(getIdFromPath("/"));
+        removeMe.add(getIdFromPath("/foo"));
+        removeMe.add(getIdFromPath("/baz"));
+        removeMe.add(getIdFromPath("/foo/bar"));
+        for (String id : removeMe) {
+            ds.remove(Collection.NODES, id);
+        }
+        for (ClusterNodeInfoDocument doc : ClusterNodeInfoDocument.all(ds)) {
+            ds.remove(Collection.CLUSTER_NODES, doc.getId());
+        }
+        c = new Clock.Virtual();
+        c.waitUntil(System.currentTimeMillis());
+        ns1 = new DocumentMK.Builder().setAsyncDelay(0)
+                .clock(c).setClusterId(1).setDocumentStore(ds1).getNodeStore();
+        ns2 = new DocumentMK.Builder().setAsyncDelay(0)
+                .clock(c).setClusterId(2).setDocumentStore(ds2).getNodeStore();
+    }
+
+    @After
+    public void disposeNodeStores() {
+        ns1.dispose();
+        ns2.dispose();
+    }
+
+    @Test
+    public void resurrectAfterGC() throws Exception {
+        NodeBuilder builder = ns1.getRoot().builder();
+        builder.child("foo").child("bar");
+        builder.child("baz");
+        merge(ns1, builder);
+        builder = ns1.getRoot().builder();
+        builder.child("foo").child("bar").setProperty("p", 0);
+        merge(ns1, builder);
+        ns1.runBackgroundOperations();
+
+        ns2.runBackgroundOperations();
+        assertTrue(ns2.getRoot().getChildNode("foo").exists());
+        assertTrue(ns2.getRoot().getChildNode("foo").getChildNode("bar").exists());
+        assertEquals(0, ns2.getRoot().getChildNode("foo").getChildNode("bar").getLong("p"));
+
+        builder = ns1.getRoot().builder();
+        // removing both will result in a commit root on 0:/
+        builder.child("foo").remove();
+        builder.child("baz").remove();
+        merge(ns1, builder);
+        ns1.runBackgroundOperations();
+
+        ns2.runBackgroundOperations();
+        assertFalse(ns2.getRoot().getChildNode("foo").exists());
+        NodeDocument doc = ds2.find(Collection.NODES, getIdFromPath("/foo/bar"));
+        assertNotNull(doc);
+        NodeState state = doc.getNodeAtRevision(ns2, ns2.getHeadRevision(), null);
+        assertNull(state);
+
+        c.waitUntil(c.getTime() + TimeUnit.MINUTES.toMillis(5));
+        VersionGarbageCollector gc = ns1.getVersionGarbageCollector();
+        VersionGCStats stats = gc.gc(1, TimeUnit.MINUTES);
+        assertEquals(3, stats.deletedDocGCCount);
+
+        builder = ns1.getRoot().builder();
+        builder.child("foo").child("bar");
+        merge(ns1, builder);
+        builder = ns1.getRoot().builder();
+        // setting 'x' puts the commit root on /foo
+        builder.child("foo").setProperty("x", 0);
+        builder.child("foo").child("bar").setProperty("p", 1);
+        merge(ns1, builder);
+        builder = ns1.getRoot().builder();
+        builder.child("foo").child("bar").setProperty("p", 2);
+        merge(ns1, builder);
+        ns1.runBackgroundOperations();
+
+        ns2.runBackgroundOperations();
+        assertTrue(ns2.getRoot().getChildNode("foo").exists());
+        assertTrue(ns2.getRoot().getChildNode("foo").getChildNode("bar").exists());
+        assertEquals(2, ns2.getRoot().getChildNode("foo").getChildNode("bar").getLong("p"));
+    }
+
+    @Test
+    public void resurrectInvalidate() throws Exception {
+        resurrectInvalidate(new Invalidate() {
+            @Override
+            public void perform(DocumentStore store, Iterable<String> ids) {
+                store.invalidateCache(ids);
+            }
+        });
+    }
+
+    @Test
+    public void resurrectInvalidateAll() throws Exception {
+        resurrectInvalidate(new Invalidate() {
+            @Override
+            public void perform(DocumentStore store, Iterable<String> ids) {
+                store.invalidateCache();
+            }
+        });
+    }
+
+    @Test
+    public void resurrectInvalidateIndividual() throws Exception {
+        resurrectInvalidate(new Invalidate() {
+            @Override
+            public void perform(DocumentStore store, Iterable<String> ids) {
+                for (String id : ids) {
+                    store.invalidateCache(Collection.NODES, id);
+                }
+            }
+        });
+    }
+
+    private void resurrectInvalidate(Invalidate inv) throws Exception {
+        UpdateOp op = new UpdateOp(getIdFromPath("/foo"), true);
+        op.set(Document.ID, op.getId());
+        op.set("p", 0);
+        assertTrue(ds1.create(Collection.NODES, Lists.newArrayList(op)));
+        NodeDocument doc = ds2.find(Collection.NODES, op.getId());
+        assertNotNull(doc);
+        assertEquals(0L, doc.get("p"));
+
+        ds1.remove(Collection.NODES, op.getId());
+        // recreate with different value for 'p'
+        op.set("p", 1);
+        assertTrue(ds1.create(Collection.NODES, Lists.newArrayList(op)));
+
+        inv.perform(ds2, Lists.newArrayList(op.getId()));
+        doc = ds2.find(Collection.NODES, op.getId());
+        assertNotNull(doc);
+        assertEquals(1L, doc.get("p"));
+    }
+
+    interface Invalidate {
+        void perform(DocumentStore store, Iterable<String> ids);
+    }
+
+    private static void merge(NodeStore store, NodeBuilder builder)
+            throws CommitFailedException {
+        store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java
------------------------------------------------------------------------------
    svn:eol-style = native