Added:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheKeyTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheKeyTest.java?rev=1857240&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheKeyTest.java
(added)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheKeyTest.java
Wed Apr 10 11:13:19 2019
@@ -0,0 +1,50 @@
+/*
+ * 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 org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class MemoryDiffCacheKeyTest {
+
+ @Test
+ public void asString() {
+ Path p = Path.fromString("/foo/bar");
+ RevisionVector from = RevisionVector.fromString("r3-0-1");
+ RevisionVector to = RevisionVector.fromString("r7-0-1");
+ MemoryDiffCache.Key key = new MemoryDiffCache.Key(p, from, to);
+ assertEquals("r3-0-1/foo/bar@r7-0-1", key.asString());
+ }
+
+ @Test
+ public void fromString() {
+ Path p = Path.fromString("/foo/bar");
+ RevisionVector from = RevisionVector.fromString("r3-0-1");
+ RevisionVector to = RevisionVector.fromString("r7-0-1");
+ MemoryDiffCache.Key expected = new MemoryDiffCache.Key(p, from, to);
+
+ String s = "r3-0-1/foo/bar@r7-0-1";
+ MemoryDiffCache.Key key = MemoryDiffCache.Key.fromString(s);
+ assertEquals(expected, key);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void fromStringIllegalArgumentException() {
+ MemoryDiffCache.Key.fromString("foo@r7-0-1");
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheKeyTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCacheTest.java
Wed Apr 10 11:13:19 2019
@@ -37,11 +37,11 @@ public class MemoryDiffCacheTest {
RevisionVector from = new RevisionVector(Revision.newRevision(1));
RevisionVector to = new RevisionVector(Revision.newRevision(1));
DiffCache.Entry entry = cache.newEntry(from, to, false);
- entry.append("/", "^\"foo\":{}");
- entry.append("/foo", changes(MemoryDiffCache.CACHE_VALUE_LIMIT));
+ entry.append(Path.ROOT, "^\"foo\":{}");
+ entry.append(Path.fromString("/foo"),
changes(MemoryDiffCache.CACHE_VALUE_LIMIT));
entry.done();
- assertNotNull(cache.getChanges(from, to, "/", null));
- assertNull(cache.getChanges(from, to, "/foo", null));
+ assertNotNull(cache.getChanges(from, to, Path.ROOT, null));
+ assertNull(cache.getChanges(from, to, Path.fromString("/foo"), null));
}
private static String changes(int minLength) {
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDocumentStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDocumentStoreTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDocumentStoreTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/MongoDocumentStoreTest.java
Wed Apr 10 11:13:19 2019
@@ -229,13 +229,13 @@ public class MongoDocumentStoreTest {
Revision rev = Revision.newRevision(0);
List<UpdateOp> inserts = new ArrayList<UpdateOp>();
for (int i = 0; i < DocumentMK.MANY_CHILDREN_THRESHOLD * 2; i++) {
- DocumentNodeState n = new DocumentNodeState(store, "/node-" + i,
+ DocumentNodeState n = new DocumentNodeState(store,
Path.fromString("/node-" + i),
new RevisionVector(rev));
inserts.add(n.asOperation(rev));
}
docStore.create(Collection.NODES, inserts);
List<NodeDocument> docs = docStore.query(Collection.NODES,
- Utils.getKeyLowerLimit("/"), Utils.getKeyUpperLimit("/"),
+ Utils.getKeyLowerLimit(Path.ROOT),
Utils.getKeyUpperLimit(Path.ROOT),
DocumentMK.MANY_CHILDREN_THRESHOLD);
assertEquals(DocumentMK.MANY_CHILDREN_THRESHOLD, docs.size());
store.dispose();
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentSweeperTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentSweeperTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentSweeperTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/NodeDocumentSweeperTest.java
Wed Apr 10 11:13:19 2019
@@ -198,7 +198,7 @@ public class NodeDocumentSweeperTest {
Iterable<NodeDocument> docs =
seeker.getCandidates(startRev.getTimestamp());
return sweeper.sweep(docs, new NodeDocumentSweepListener() {
@Override
- public void sweepUpdate(Map<String, UpdateOp> updates)
+ public void sweepUpdate(Map<Path, UpdateOp> updates)
throws DocumentStoreException {
ops.addAll(updates.values());
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathComparatorTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathComparatorTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathComparatorTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathComparatorTest.java
Wed Apr 10 11:13:19 2019
@@ -35,18 +35,22 @@ public class PathComparatorTest {
@Test
public void sort() {
- List<String> paths = new ArrayList<String>();
- paths.add("/foo");
- paths.add("/foo/bar");
- paths.add("/bar/qux");
- paths.add("/");
- paths.add("/bar");
+ List<Path> paths = new ArrayList<>();
+ paths.add(p("/foo"));
+ paths.add(p("/foo/bar"));
+ paths.add(p("/bar/qux"));
+ paths.add(p("/"));
+ paths.add(p("/bar"));
- Collections.sort(paths, PathComparator.INSTANCE);
+ paths.sort(PathComparator.INSTANCE);
- List<String> expected = Lists.newArrayList(
- "/bar/qux", "/foo/bar", "/bar", "/foo", "/");
+ List<Path> expected = Lists.newArrayList(
+ p("/bar/qux"), p("/foo/bar"), p("/bar"), p("/foo"), p("/"));
assertEquals(expected, paths);
}
+
+ private static Path p(String path) {
+ return Path.fromString(path);
+ }
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathRevTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathRevTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathRevTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathRevTest.java
Wed Apr 10 11:13:19 2019
@@ -25,11 +25,11 @@ import static org.junit.Assert.assertEqu
public class PathRevTest {
@Test
- public void roundTrip() {
- String path = "/this/is/a/test/path";
+ public void equals() {
+ Path path = Path.fromString("/this/is/a/test/path");
RevisionVector rv = new RevisionVector(
Revision.newRevision(1), Revision.newRevision(2));
- PathRev key = new PathRev(path, rv);
- assertEquals(key, PathRev.fromString(key.asString()));
+ PathRev expected = new PathRev(path, rv);
+ assertEquals(expected, new PathRev(path, rv));
}
}
Added:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathTest.java?rev=1857240&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathTest.java
(added)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathTest.java
Wed Apr 10 11:13:19 2019
@@ -0,0 +1,265 @@
+/*
+ * 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.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.junit.Test;
+
+import static org.apache.jackrabbit.oak.plugins.document.Path.ROOT;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.emptyIterable;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public class PathTest {
+
+ private final Path root = ROOT;
+ private final Path foo = new Path(root, "foo");
+ private final Path fooBar = new Path(foo, "bar");
+ private final Path fooBarQuux = new Path(fooBar, "quux");
+ private final Path relFoo = new Path("foo");
+ private final Path relFooBar = new Path(relFoo, "bar");
+ private final Path relFooBarQuux = new Path(relFooBar, "quux");
+
+ @Test
+ public void equals() {
+ assertEquals(ROOT, Path.fromString("/"));
+ assertEquals(foo, Path.fromString("/foo"));
+ assertEquals(fooBar, Path.fromString("/foo/bar"));
+ assertEquals(relFoo, Path.fromString("foo"));
+ assertEquals(relFooBar, Path.fromString("foo/bar"));
+ assertNotEquals(fooBar, Path.fromString("foo/bar"));
+ assertNotEquals(relFooBar, Path.fromString("/foo/bar"));
+ }
+
+ @Test
+ public void pathToString() {
+ assertEquals("/", root.toString());
+ assertEquals("/foo", foo.toString());
+ assertEquals("/foo/bar", fooBar.toString());
+ assertEquals("/foo/bar/quux", fooBarQuux.toString());
+ assertEquals("foo", relFoo.toString());
+ assertEquals("foo/bar", relFooBar.toString());
+ assertEquals("foo/bar/quux", relFooBarQuux.toString());
+ }
+
+ @Test
+ public void toStringBuilder() {
+ StringBuilder sb = new StringBuilder();
+ root.toStringBuilder(sb);
+ assertEquals(root.toString(), sb.toString());
+ sb.setLength(0);
+ foo.toStringBuilder(sb);
+ assertEquals(foo.toString(), sb.toString());
+ sb.setLength(0);
+ fooBar.toStringBuilder(sb);
+ assertEquals(fooBar.toString(), sb.toString());
+ sb.setLength(0);
+ fooBarQuux.toStringBuilder(sb);
+ assertEquals(fooBarQuux.toString(), sb.toString());
+ sb.setLength(0);
+ relFoo.toStringBuilder(sb);
+ assertEquals(relFoo.toString(), sb.toString());
+ sb.setLength(0);
+ relFooBar.toStringBuilder(sb);
+ assertEquals(relFooBar.toString(), sb.toString());
+ sb.setLength(0);
+ relFooBarQuux.toStringBuilder(sb);
+ assertEquals(relFooBarQuux.toString(), sb.toString());
+ }
+
+ @Test
+ public void fromString() {
+ assertEquals(root, Path.fromString(root.toString()));
+ assertEquals(foo, Path.fromString(foo.toString()));
+ assertEquals(fooBar, Path.fromString(fooBar.toString()));
+ assertEquals(fooBarQuux, Path.fromString(fooBarQuux.toString()));
+ assertEquals(relFoo, Path.fromString(relFoo.toString()));
+ assertEquals(relFooBar, Path.fromString(relFooBar.toString()));
+ assertEquals(relFooBarQuux, Path.fromString(relFooBarQuux.toString()));
+ }
+
+ @Test
+ public void length() {
+ assertEquals(root.toString().length(), root.length());
+ assertEquals(foo.toString().length(), foo.length());
+ assertEquals(fooBar.toString().length(), fooBar.length());
+ assertEquals(fooBarQuux.toString().length(), fooBarQuux.length());
+ assertEquals(relFoo.toString().length(), relFoo.length());
+ assertEquals(relFooBar.toString().length(), relFooBar.length());
+ assertEquals(relFooBarQuux.toString().length(),
relFooBarQuux.length());
+ }
+
+ @Test
+ public void isRoot() {
+ assertTrue(root.isRoot());
+ assertFalse(foo.isRoot());
+ assertFalse(fooBar.isRoot());
+ assertFalse(fooBarQuux.isRoot());
+ assertFalse(relFoo.isRoot());
+ assertFalse(relFooBar.isRoot());
+ assertFalse(relFooBarQuux.isRoot());
+ }
+
+ @Test
+ public void getParent() {
+ assertNull(root.getParent());
+ assertEquals(foo.getParent(), root);
+ assertEquals(fooBar.getParent(), foo);
+ assertEquals(fooBarQuux.getParent(), fooBar);
+ assertNull(relFoo.getParent());
+ assertEquals(relFooBar.getParent(), relFoo);
+ assertEquals(relFooBarQuux.getParent(), relFooBar);
+ }
+
+ @Test
+ public void getDepth() {
+ assertEquals(PathUtils.getDepth(root.toString()), root.getDepth());
+ assertEquals(PathUtils.getDepth(foo.toString()), foo.getDepth());
+ assertEquals(PathUtils.getDepth(fooBar.toString()), fooBar.getDepth());
+ assertEquals(PathUtils.getDepth(fooBarQuux.toString()),
fooBarQuux.getDepth());
+ assertEquals(PathUtils.getDepth(relFoo.toString()), relFoo.getDepth());
+ assertEquals(PathUtils.getDepth(relFooBar.toString()),
relFooBar.getDepth());
+ assertEquals(PathUtils.getDepth(relFooBarQuux.toString()),
relFooBarQuux.getDepth());
+ }
+
+ @Test
+ public void getAncestor() {
+ assertEquals(root, root.getAncestor(-1));
+ assertEquals(root, root.getAncestor(0));
+ assertEquals(root, root.getAncestor(1));
+ assertEquals(foo, foo.getAncestor(0));
+ assertEquals(root, foo.getAncestor(1));
+ assertEquals(root, foo.getAncestor(2));
+ assertEquals(fooBar, fooBar.getAncestor(0));
+ assertEquals(foo, fooBar.getAncestor(1));
+ assertEquals(root, fooBar.getAncestor(2));
+ assertEquals(root, fooBar.getAncestor(3));
+ assertEquals(fooBar, fooBarQuux.getAncestor(1));
+
+ assertEquals(relFoo, relFoo.getAncestor(-1));
+ assertEquals(relFoo, relFoo.getAncestor(0));
+ assertEquals(relFoo, relFoo.getAncestor(1));
+ assertEquals(relFooBar, relFooBar.getAncestor(0));
+ assertEquals(relFoo, relFooBar.getAncestor(1));
+ assertEquals(relFoo, relFooBar.getAncestor(2));
+ assertEquals(relFoo, relFooBar.getAncestor(3));
+ assertEquals(relFooBar, relFooBarQuux.getAncestor(1));
+ }
+
+ @Test
+ public void getName() {
+ assertEquals("", root.getName());
+ assertEquals("foo", foo.getName());
+ assertEquals("bar", fooBar.getName());
+ assertEquals("quux", fooBarQuux.getName());
+ assertEquals("foo", relFoo.getName());
+ assertEquals("bar", relFooBar.getName());
+ assertEquals("quux", relFooBarQuux.getName());
+ }
+
+ @Test
+ public void elements() {
+ assertThat(root.elements(), emptyIterable());
+ assertThat(foo.elements(), contains("foo"));
+ assertThat(fooBar.elements(), contains("foo", "bar"));
+ assertThat(fooBarQuux.elements(), contains("foo", "bar", "quux"));
+ assertThat(relFoo.elements(), contains("foo"));
+ assertThat(relFooBar.elements(), contains("foo", "bar"));
+ assertThat(relFooBarQuux.elements(), contains("foo", "bar", "quux"));
+ }
+
+ @Test
+ public void isAncestorOf() {
+ assertTrue(root.isAncestorOf(foo));
+ assertTrue(root.isAncestorOf(fooBar));
+ assertTrue(foo.isAncestorOf(fooBar));
+ assertTrue(fooBar.isAncestorOf(fooBarQuux));
+ assertFalse(root.isAncestorOf(root));
+ assertFalse(foo.isAncestorOf(root));
+ assertFalse(foo.isAncestorOf(foo));
+ assertFalse(fooBar.isAncestorOf(fooBar));
+ assertFalse(fooBar.isAncestorOf(foo));
+ assertFalse(fooBar.isAncestorOf(root));
+
+ assertFalse(root.isAncestorOf(relFoo));
+ assertFalse(root.isAncestorOf(relFooBar));
+ assertFalse(relFoo.isAncestorOf(relFoo));
+ assertFalse(relFooBar.isAncestorOf(relFoo));
+ assertFalse(relFooBar.isAncestorOf(relFooBar));
+ assertFalse(relFooBarQuux.isAncestorOf(relFooBar));
+ assertFalse(relFooBarQuux.isAncestorOf(relFooBarQuux));
+ assertTrue(relFoo.isAncestorOf(relFooBar));
+ assertTrue(relFooBar.isAncestorOf(relFooBarQuux));
+
+ assertFalse(foo.isAncestorOf(relFooBar));
+ assertFalse(foo.isAncestorOf(relFooBarQuux));
+ assertFalse(relFoo.isAncestorOf(fooBar));
+ assertFalse(relFoo.isAncestorOf(fooBarQuux));
+ }
+
+ @Test
+ public void isAbsolute() {
+ assertTrue(ROOT.isAbsolute());
+ assertTrue(foo.isAbsolute());
+ assertTrue(fooBar.isAbsolute());
+ assertTrue(fooBarQuux.isAbsolute());
+ assertFalse(relFoo.isAbsolute());
+ assertFalse(relFooBar.isAbsolute());
+ assertFalse(relFooBarQuux.isAbsolute());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void emptyName() {
+ new Path(ROOT, "");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void fromStringWithEmptyString() {
+ Path.fromString("");
+ }
+
+ @Test
+ public void compareTo() {
+ Path baz = Path.fromString("/baz");
+ Path fooBaz = Path.fromString("/foo/baz");
+ Path relFooBaz = Path.fromString("foo/baz");
+ List<Path> paths = new ArrayList<>();
+ paths.add(root);
+ paths.add(baz);
+ paths.add(foo);
+ paths.add(fooBar);
+ paths.add(fooBaz);
+ paths.add(fooBarQuux);
+ paths.add(relFoo);
+ paths.add(relFooBar);
+ paths.add(relFooBaz);
+ for (int i = 0; i < 20; i++) {
+ Collections.shuffle(paths);
+ Collections.sort(paths);
+ assertThat(paths, contains(root, baz, foo, fooBar, fooBarQuux,
fooBaz, relFoo, relFooBar, relFooBaz));
+ }
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/PathTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/SimpleTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/SimpleTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/SimpleTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/SimpleTest.java
Wed Apr 10 11:13:19 2019
@@ -72,6 +72,7 @@ public class SimpleTest {
assertEquals(2, Utils.pathDepth("/a/"));
assertEquals(2, Utils.pathDepth("/a/b"));
assertEquals(3, Utils.pathDepth("/a/b/c"));
+ assertEquals(2, Utils.pathDepth("a/b/c"));
}
@Test
@@ -80,13 +81,13 @@ public class SimpleTest {
DocumentStore s = mk.getDocumentStore();
DocumentNodeStore ns = mk.getNodeStore();
RevisionVector rev = RevisionVector.fromString(mk.getHeadRevision());
- DocumentNodeState n = new DocumentNodeState(ns, "/test", rev,
+ DocumentNodeState n = new DocumentNodeState(ns,
Path.fromString("/test"), rev,
Collections.singleton(ns.createPropertyState("name",
"\"Hello\"")), false, null);
UpdateOp op = n.asOperation(rev.getRevision(ns.getClusterId()));
// mark as commit root
NodeDocument.setRevision(op, rev.getRevision(ns.getClusterId()), "c");
assertTrue(s.create(Collection.NODES, Lists.newArrayList(op)));
- DocumentNodeState n2 = ns.getNode("/test", rev);
+ DocumentNodeState n2 = ns.getNode(Path.fromString("/test"), rev);
assertNotNull(n2);
PropertyState p = n2.getProperty("name");
assertNotNull(p);
@@ -249,13 +250,13 @@ public class SimpleTest {
String r0 = mk.commit("/test", "+\"a\":{\"name\": \"World\"}", null,
null);
String r1 = mk.commit("/test", "+\"b\":{\"name\": \"!\"}", null, null);
test = mk.getNodes("/test", r0, 0, 0, Integer.MAX_VALUE, null);
- DocumentNodeState n = ns.getNode("/", RevisionVector.fromString(r0));
+ DocumentNodeState n = ns.getNode(Path.ROOT,
RevisionVector.fromString(r0));
assertNotNull(n);
- Children c = ns.getChildren(n, null, Integer.MAX_VALUE);
+ Children c = ns.getChildren(n, "", Integer.MAX_VALUE);
assertEquals("[test]", c.toString());
- n = ns.getNode("/test", RevisionVector.fromString(r1));
+ n = ns.getNode(Path.fromString("/test"),
RevisionVector.fromString(r1));
assertNotNull(n);
- c = ns.getChildren(n, null, Integer.MAX_VALUE);
+ c = ns.getChildren(n, "", Integer.MAX_VALUE);
assertEquals("[a, b]", c.toString());
rev = mk.commit("", "^\"/test\":1", null, null);
@@ -275,19 +276,19 @@ public class SimpleTest {
mk.commit("/testDel", "+\"b\":{\"name\": \"!\"}", null, null);
String r1 = mk.commit("/testDel", "+\"c\":{\"name\": \"!\"}", null,
null);
- DocumentNodeState n = ns.getNode("/testDel",
RevisionVector.fromString(r1));
+ DocumentNodeState n = ns.getNode(Path.fromString("/testDel"),
RevisionVector.fromString(r1));
assertNotNull(n);
- Children c = ns.getChildren(n, null, Integer.MAX_VALUE);
+ Children c = ns.getChildren(n, "", Integer.MAX_VALUE);
assertEquals(3, c.children.size());
String r2 = mk.commit("/testDel", "-\"c\"", null, null);
- n = ns.getNode("/testDel", RevisionVector.fromString(r2));
+ n = ns.getNode(Path.fromString("/testDel"),
RevisionVector.fromString(r2));
assertNotNull(n);
- c = ns.getChildren(n, null, Integer.MAX_VALUE);
+ c = ns.getChildren(n, "", Integer.MAX_VALUE);
assertEquals(2, c.children.size());
String r3 = mk.commit("/", "-\"testDel\"", null, null);
- n = ns.getNode("/testDel", RevisionVector.fromString(r3));
+ n = ns.getNode(Path.fromString("/testDel"),
RevisionVector.fromString(r3));
assertNull(n);
}
@@ -412,7 +413,7 @@ public class SimpleTest {
NodeDocument foo = store.find(Collection.NODES, "2:/test/foo");
assertNotNull(foo);
assertFalse(foo.containsRevision(head));
- assertEquals("/", foo.getCommitRootPath(head));
+ assertEquals(Path.ROOT, foo.getCommitRootPath(head));
head = Revision.fromString(mk.commit("",
"+\"/bar\":{}+\"/test/foo/bar\":{}", head.toString(), null));
@@ -424,12 +425,12 @@ public class SimpleTest {
// /bar refers to root nodes a commit root
NodeDocument bar = store.find(Collection.NODES, "1:/bar");
assertNotNull(bar);
- assertEquals("/", bar.getCommitRootPath(head));
+ assertEquals(Path.ROOT, bar.getCommitRootPath(head));
// /test/foo/bar refers to root nodes a commit root
bar = store.find(Collection.NODES, "3:/test/foo/bar");
assertNotNull(bar);
- assertEquals("/", bar.getCommitRootPath(head));
+ assertEquals(Path.ROOT, bar.getCommitRootPath(head));
}
Added:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/StringCachePerformance.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/StringCachePerformance.java?rev=1857240&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/StringCachePerformance.java
(added)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/StringCachePerformance.java
Wed Apr 10 11:13:19 2019
@@ -0,0 +1,34 @@
+/*
+ * 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 org.junit.Test;
+
+public class StringCachePerformance {
+
+ @Test
+ public void get() {
+ long time = System.nanoTime();
+ for (int i = 0; i < 1000000; i++) {
+ StringCache.get("some string");
+ }
+ time = System.nanoTime() - time;
+ System.out.println("time: " + TimeUnit.NANOSECONDS.toMicros(time) + "
us.");
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/StringCachePerformance.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ValueMapTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ValueMapTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ValueMapTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/ValueMapTest.java
Wed Apr 10 11:13:19 2019
@@ -33,6 +33,7 @@ import com.google.common.collect.Iterato
import com.google.common.collect.Lists;
import static org.apache.jackrabbit.oak.plugins.document.Collection.NODES;
+import static org.apache.jackrabbit.oak.plugins.document.Path.ROOT;
import static
org.apache.jackrabbit.oak.plugins.document.TestUtils.persistToBranch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -45,18 +46,17 @@ public class ValueMapTest {
@Test
public void previousDocs1() {
- String rootPath = "/";
- String rootId = Utils.getIdFromPath(rootPath);
+ String rootId = Utils.getIdFromPath(ROOT);
Revision r0 = new Revision(0, 0, 1);
MemoryDocumentStore store = new MemoryDocumentStore();
// create previous docs
- UpdateOp op = new UpdateOp(Utils.getPreviousIdFor(rootPath, r0, 0),
true);
+ UpdateOp op = new UpdateOp(Utils.getPreviousIdFor(ROOT, r0, 0), true);
op.setMapEntry("prop", r0, "0");
NodeDocument.setRevision(op, r0, "c");
store.createOrUpdate(NODES, op);
Revision r1low = new Revision(1, 0, 1);
Revision r1high = new Revision(1, 10, 1);
- op = new UpdateOp(Utils.getPreviousIdFor(rootPath, r1high, 0), true);
+ op = new UpdateOp(Utils.getPreviousIdFor(ROOT, r1high, 0), true);
for (int i = r1low.getCounter(); i <= r1high.getCounter(); i++) {
Revision r = new Revision(1, i, 1);
op.setMapEntry("foo", r, String.valueOf(i));
@@ -88,8 +88,7 @@ public class ValueMapTest {
@Test
public void previousDocs2() {
MemoryDocumentStore store = new MemoryDocumentStore();
- String rootPath = "/";
- String rootId = Utils.getIdFromPath(rootPath);
+ String rootId = Utils.getIdFromPath(ROOT);
Revision r01 = new Revision(0, 0, 1);
Revision r12 = new Revision(1, 0, 2);
Revision r22 = new Revision(2, 0, 2);
@@ -97,14 +96,14 @@ public class ValueMapTest {
Revision r42 = new Revision(4, 0, 2);
Revision r51 = new Revision(5, 0, 1);
// create previous docs
- UpdateOp op = new UpdateOp(Utils.getPreviousIdFor(rootPath, r31, 0),
true);
+ UpdateOp op = new UpdateOp(Utils.getPreviousIdFor(ROOT, r31, 0), true);
op.setMapEntry("p0", r01, "0");
NodeDocument.setRevision(op, r01, "c");
op.setMapEntry("p1", r31, "1");
NodeDocument.setRevision(op, r31, "c");
store.createOrUpdate(NODES, op);
- op = new UpdateOp(Utils.getPreviousIdFor(rootPath, r42, 0), true);
+ op = new UpdateOp(Utils.getPreviousIdFor(ROOT, r42, 0), true);
op.setMapEntry("p1", r12, "0");
NodeDocument.setRevision(op, r12, "c");
op.setMapEntry("p1", r22, "1");
@@ -127,8 +126,8 @@ public class ValueMapTest {
List<NodeDocument> prevDocs = Lists.newArrayList(
doc.getPreviousDocs("p1", null));
assertEquals(2, prevDocs.size());
- assertEquals(Utils.getPreviousIdFor(rootPath, r31, 0),
prevDocs.get(0).getId());
- assertEquals(Utils.getPreviousIdFor(rootPath, r42, 0),
prevDocs.get(1).getId());
+ assertEquals(Utils.getPreviousIdFor(ROOT, r31, 0),
prevDocs.get(0).getId());
+ assertEquals(Utils.getPreviousIdFor(ROOT, r42, 0),
prevDocs.get(1).getId());
List<Revision> revs = new ArrayList<Revision>();
for (Revision r : doc.getValueMap("p1").keySet()) {
@@ -189,12 +188,12 @@ public class ValueMapTest {
Range range1 = new Range(r7, r5, 0);
Range range2 = new Range(r4, r1, 0);
- String prevId1 = Utils.getPreviousIdFor("/", range1.high, 0);
+ String prevId1 = Utils.getPreviousIdFor(ROOT, range1.high, 0);
UpdateOp prevOp1 = new UpdateOp(prevId1, true);
NodeDocument.setRevision(prevOp1, r5, "c");
NodeDocument.setRevision(prevOp1, r7, "c");
- String prevId2 = Utils.getPreviousIdFor("/", range2.high, 0);
+ String prevId2 = Utils.getPreviousIdFor(ROOT, range2.high, 0);
UpdateOp prevOp2 = new UpdateOp(prevId2, true);
NodeDocument.setRevision(prevOp2, r1, "c");
NodeDocument.setRevision(prevOp2, r2, "c");
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCDeletionTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCDeletionTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCDeletionTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGCDeletionTest.java
Wed Apr 10 11:13:19 2019
@@ -428,7 +428,7 @@ public class VersionGCDeletionTest {
* /x /x/y /x/y/z
*/
private static class NodeDocComparator implements Comparator<NodeDocument>
{
- private static Comparator<String> reverse =
Collections.reverseOrder(PathComparator.INSTANCE);
+ private static Comparator<Path> reverse =
Collections.reverseOrder(PathComparator.INSTANCE);
@Override
public int compare(NodeDocument o1, NodeDocument o2) {
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/VersionGarbageCollectorIT.java
Wed Apr 10 11:13:19 2019
@@ -510,7 +510,7 @@ public class VersionGarbageCollectorIT {
});
NodeDocument doc = docs.take();
- String name = PathUtils.getName(doc.getPath());
+ String name = doc.getPath().getName();
// recreate node, which hasn't been removed yet
name = name.equals("foo") ? "bar" : "foo";
builder = store.getRoot().builder();
@@ -523,7 +523,7 @@ public class VersionGarbageCollectorIT {
}
// invalidate cached DocumentNodeState
DocumentNodeState state = (DocumentNodeState)
store.getRoot().getChildNode(name);
- store.invalidateNodeCache(state.getPath(),
store.getRoot().getLastRevision());
+ store.invalidateNodeCache(state.getPath().toString(),
store.getRoot().getLastRevision());
while (!f.isDone()) {
docs.poll();
@@ -892,8 +892,11 @@ public class VersionGarbageCollectorIT {
store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
}
- private NodeDocument getDoc(String path){
- return store.getDocumentStore().find(NODES, Utils.getIdFromPath(path),
0);
+ private NodeDocument getDoc(String path) {
+ return getDoc(Path.fromString(path));
}
+ private NodeDocument getDoc(Path path) {
+ return store.getDocumentStore().find(NODES, Utils.getIdFromPath(path),
0);
+ }
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandlerTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandlerTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandlerTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/BundlingHandlerTest.java
Wed Apr 10 11:13:19 2019
@@ -20,6 +20,7 @@
package org.apache.jackrabbit.oak.plugins.document.bundlor;
import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.junit.Test;
@@ -42,17 +43,17 @@ public class BundlingHandlerTest {
childBuilder(builder, "/x/y/z");
NodeState state = builder.getNodeState();
- assertEquals("/", handler.getRootBundlePath());
+ assertEquals(Path.ROOT, handler.getRootBundlePath());
assertTrue(handler.isBundlingRoot());
assertEquals("foo", handler.getPropertyPath("foo"));
BundlingHandler xh = childHandler(handler, state, "/x");
- assertEquals("/x", xh.getRootBundlePath());
+ assertEquals(Path.fromString("/x"), xh.getRootBundlePath());
assertTrue(xh.isBundlingRoot());
assertEquals("foo", xh.getPropertyPath("foo"));
BundlingHandler xz = childHandler(handler, state, "/x/y/z");
- assertEquals("/x/y/z", xz.getRootBundlePath());
+ assertEquals(Path.fromString("/x/y/z"), xz.getRootBundlePath());
assertTrue(xz.isBundlingRoot());
assertEquals("foo", xz.getPropertyPath("foo"));
}
@@ -70,26 +71,26 @@ public class BundlingHandlerTest {
BundlingHandler handler = new BundlingHandler(registry);
BundlingHandler fileHandler = childHandler(handler, state,
"/sunrise.jpg");
- assertEquals("/sunrise.jpg", fileHandler.getRootBundlePath());
+ assertEquals(Path.fromString("/sunrise.jpg"),
fileHandler.getRootBundlePath());
assertTrue(fileHandler.isBundlingRoot());
assertFalse(fileHandler.isBundledNode());
assertEquals("foo", fileHandler.getPropertyPath("foo"));
BundlingHandler jcrContentHandler = childHandler(handler, state,
"/sunrise.jpg/jcr:content");
- assertEquals("/sunrise.jpg", jcrContentHandler.getRootBundlePath());
+ assertEquals(Path.fromString("/sunrise.jpg"),
jcrContentHandler.getRootBundlePath());
assertFalse(jcrContentHandler.isBundlingRoot());
assertTrue(jcrContentHandler.isBundledNode());
assertEquals("jcr:content/foo",
jcrContentHandler.getPropertyPath("foo"));
BundlingHandler metadataHandler = childHandler(handler, state,
"/sunrise.jpg/metadata");
- assertEquals("/sunrise.jpg/metadata",
metadataHandler.getRootBundlePath());
+ assertEquals(Path.fromString("/sunrise.jpg/metadata"),
metadataHandler.getRootBundlePath());
assertTrue(metadataHandler.isBundlingRoot());
assertFalse(metadataHandler.isBundledNode());
assertEquals("foo", metadataHandler.getPropertyPath("foo"));
// /sunrise.jpg/jcr:content/bar should have bundle root reset
BundlingHandler barHandler = childHandler(handler, state,
"/sunrise.jpg/jcr:content/bar");
- assertEquals("/sunrise.jpg/jcr:content/bar",
barHandler.getRootBundlePath());
+ assertEquals(Path.fromString("/sunrise.jpg/jcr:content/bar"),
barHandler.getRootBundlePath());
assertTrue(barHandler.isBundlingRoot());
assertEquals("foo", barHandler.getPropertyPath("foo"));
}
@@ -104,7 +105,7 @@ public class BundlingHandlerTest {
NodeState state = builder.getNodeState();
BundlingHandler fileHandler = handler.childAdded("sunrise.jpg",
state.getChildNode("sunrise.jpg"));
- assertEquals("/sunrise.jpg", fileHandler.getRootBundlePath());
+ assertEquals(Path.fromString("/sunrise.jpg"),
fileHandler.getRootBundlePath());
assertTrue(fileHandler.isBundlingRoot());
assertEquals("foo", fileHandler.getPropertyPath("foo"));
assertEquals(1, fileHandler.getMetaProps().size());
@@ -118,7 +119,7 @@ public class BundlingHandlerTest {
NodeState state = builder.getNodeState();
BundlingHandler fileHandler = handler.childAdded("sunrise.jpg",
state.getChildNode("sunrise.jpg"));
- assertEquals("/sunrise.jpg", fileHandler.getRootBundlePath());
+ assertEquals(Path.fromString("/sunrise.jpg"),
fileHandler.getRootBundlePath());
assertTrue(fileHandler.isBundlingRoot());
assertEquals("foo", fileHandler.getPropertyPath("foo"));
assertEquals(0, fileHandler.getMetaProps().size());
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/bundlor/DocumentBundlingTest.java
Wed Apr 10 11:13:19 2019
@@ -19,6 +19,7 @@
package org.apache.jackrabbit.oak.plugins.document.bundlor;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -38,11 +39,12 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.NamePathRev;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
-import org.apache.jackrabbit.oak.plugins.document.PathRev;
import org.apache.jackrabbit.oak.plugins.document.RandomStream;
import org.apache.jackrabbit.oak.plugins.document.TestNodeObserver;
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.persistentCache.CacheType;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.oak.InitialContent;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
@@ -57,6 +59,7 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
+import org.h2.mvstore.WriteBuffer;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Before;
@@ -186,7 +189,7 @@ public class DocumentBundlingTest {
int nonBundledMem = nonBundledFile.getMemory() +
nonBundledContent.getMemory();
int bundledMem = bundledFile.getMemory();
- assertEquals(1410, bundledMem);
+ assertEquals(1510, bundledMem);
assertThat(bundledMem, is(greaterThan(nonBundledMem)));
}
@@ -274,7 +277,7 @@ public class DocumentBundlingTest {
List<String> bundledPaths = new ArrayList<>();
for (DocumentNodeState bs : appNode.getAllBundledNodesStates()) {
- bundledPaths.add(bs.getPath());
+ bundledPaths.add(bs.getPath().toString());
}
assertThat(bundledPaths, containsInAnyOrder(
"/test/book.jpg/jcr:content",
@@ -613,7 +616,7 @@ public class DocumentBundlingTest {
}
@Test
- public void jsonSerialization() throws Exception{
+ public void bufferSerialization() throws Exception {
NodeBuilder builder = store.getRoot().builder();
NodeBuilder appNB = newNode("app:Asset");
createChild(appNB,
@@ -629,8 +632,11 @@ public class DocumentBundlingTest {
merge(builder);
DocumentNodeState appNode = (DocumentNodeState)
getNode(store.getRoot(), "test/book.jpg");
- String json = appNode.asString();
- NodeState appNode2 = DocumentNodeState.fromString(store, json);
+ WriteBuffer wb = new WriteBuffer(1024);
+ CacheType.NODE.writeValue(wb, appNode);
+ ByteBuffer rb = wb.getBuffer();
+ rb.rewind();
+ NodeState appNode2 = CacheType.NODE.readValue(store, ds, rb);
AssertingDiff.assertEquals(appNode, appNode2);
}
@@ -723,9 +729,9 @@ public class DocumentBundlingTest {
merge(builder);
- Set<PathRev> cachedPaths =
store.getNodeChildrenCache().asMap().keySet();
- for (PathRev pr : cachedPaths){
- assertFalse(pr.getPath().contains("jcr:content/renditions"));
+ Set<NamePathRev> cachedPaths =
store.getNodeChildrenCache().asMap().keySet();
+ for (NamePathRev pr : cachedPaths){
+
assertFalse(pr.getPath().toString().contains("jcr:content/renditions"));
}
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/cache/CacheChangesTrackerTest.java
Wed Apr 10 11:13:19 2019
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.oak.cache.C
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.locks.NodeDocumentLocks;
import
org.apache.jackrabbit.oak.plugins.document.locks.StripedNodeDocumentLocks;
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
@@ -82,7 +83,8 @@ public class CacheChangesTrackerTest {
@Test
public void testRegisterChildrenTracker() {
NodeDocumentCache cache = createCache();
- CacheChangesTracker tracker =
cache.registerTracker(getKeyLowerLimit("/parent"), getKeyUpperLimit("/parent"));
+ Path parent = Path.fromString("/parent");
+ CacheChangesTracker tracker =
cache.registerTracker(getKeyLowerLimit(parent), getKeyUpperLimit(parent));
assertFalse(tracker.mightBeenAffected("2:/parent/xyz"));
assertFalse(tracker.mightBeenAffected("2:/parent/abc"));
@@ -105,7 +107,8 @@ public class CacheChangesTrackerTest {
@Test
public void testGetLoaderAffectsTracker() throws ExecutionException {
NodeDocumentCache cache = createCache();
- CacheChangesTracker tracker =
cache.registerTracker(getKeyLowerLimit("/parent"), getKeyUpperLimit("/parent"));
+ Path parent = Path.fromString("/parent");
+ CacheChangesTracker tracker =
cache.registerTracker(getKeyLowerLimit(parent), getKeyUpperLimit(parent));
assertFalse(tracker.mightBeenAffected("2:/parent/xyz"));
@@ -149,7 +152,8 @@ public class CacheChangesTrackerTest {
@Test
public void testOnlyExternalChanges() {
NodeDocumentCache cache = createCache();
- CacheChangesTracker tracker =
cache.registerTracker(getKeyLowerLimit("/parent"), getKeyUpperLimit("/parent"));
+ Path parent = Path.fromString("/parent");
+ CacheChangesTracker tracker =
cache.registerTracker(getKeyLowerLimit(parent), getKeyUpperLimit(parent));
cache.putNonConflictingDocs(tracker,
ImmutableSet.of(createDoc("2:/parent/local")));
assertFalse(tracker.mightBeenAffected("2:/parent/local"));
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDBExceptionTest.java
Wed Apr 10 11:13:19 2019
@@ -21,6 +21,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
import org.apache.jackrabbit.oak.plugins.document.MongoUtils;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.Revision;
import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
@@ -114,8 +115,9 @@ public class MongoDBExceptionTest {
e.getMessage().contains(id));
}
- String fromKey = Utils.getKeyLowerLimit("/foo");
- String toKey = Utils.getKeyUpperLimit("/foo");
+ Path foo = Path.fromString("/foo");
+ String fromKey = Utils.getKeyLowerLimit(foo);
+ String toKey = Utils.getKeyUpperLimit(foo);
exceptionMsg = "query failed";
setExceptionMsg();
try {
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoMissingLastRevSeekerTest.java
Wed Apr 10 11:13:19 2019
@@ -103,7 +103,7 @@ public class MongoMissingLastRevSeekerTe
assertNotNull(store.findAndUpdate(NODES, op));
updated = true;
}
- if (doc.getPath().startsWith("/node-")) {
+ if (doc.getPath().toString().startsWith("/node-")) {
ids.add(doc.getId());
}
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/QueryHintTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/QueryHintTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/QueryHintTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/QueryHintTest.java
Wed Apr 10 11:13:19 2019
@@ -32,6 +32,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.Collection;
import org.apache.jackrabbit.oak.plugins.document.DocumentMK;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.oak.stats.Clock;
import org.junit.After;
@@ -75,8 +76,8 @@ public class QueryHintTest extends Abstr
assertTrue(mongoDS.canUseModifiedTimeIdx(10));
mongoDS.query(Collection.NODES,
- Utils.getKeyLowerLimit("/"),
- Utils.getKeyUpperLimit("/"),
+ Utils.getKeyLowerLimit(Path.ROOT),
+ Utils.getKeyUpperLimit(Path.ROOT),
NodeDocument.MODIFIED_IN_SECS,
50,
10);
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/mongo/RetryReadIT.java
Wed Apr 10 11:13:19 2019
@@ -25,6 +25,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreException;
import org.apache.jackrabbit.oak.plugins.document.MongoUtils;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
@@ -78,15 +79,17 @@ public class RetryReadIT extends Abstrac
@Test
public void retryQuery() {
- String fromKey = Utils.getKeyLowerLimit("/foo");
- String toKey = Utils.getKeyUpperLimit("/foo");
+ Path foo = Path.fromString("/foo");
+ String fromKey = Utils.getKeyLowerLimit(foo);
+ String toKey = Utils.getKeyUpperLimit(foo);
// must survive two consecutive failures. -> 2 retries
store.failRead = 2;
List<NodeDocument> docs = store.query(NODES, fromKey, toKey, 100);
assertThat(docs, is(empty()));
- fromKey = Utils.getKeyLowerLimit("/bar");
- toKey = Utils.getKeyUpperLimit("/bar");
+ Path bar = Path.fromString("/bar");
+ fromKey = Utils.getKeyLowerLimit(bar);
+ toKey = Utils.getKeyUpperLimit(bar);
// must fail with three consecutive failures
store.failRead = 3;
try {
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/AsyncQueueTest.java
Wed Apr 10 11:13:19 2019
@@ -22,6 +22,7 @@ import com.google.common.cache.RemovalCa
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.PathRev;
import org.apache.jackrabbit.oak.plugins.document.Revision;
import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
@@ -124,7 +125,7 @@ public class AsyncQueueTest {
}
private PathRev generatePathRev() {
- return new PathRev("/" + id++, new RevisionVector(new Revision(0, 0,
0)));
+ return new PathRev(Path.fromString("/" + id++), new RevisionVector(new
Revision(0, 0, 0)));
}
private void flush() {
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BroadcastTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BroadcastTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BroadcastTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/BroadcastTest.java
Wed Apr 10 11:13:19 2019
@@ -30,8 +30,8 @@ import java.util.concurrent.Callable;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
-import org.apache.jackrabbit.oak.plugins.document.PathRev;
-import org.apache.jackrabbit.oak.plugins.document.Revision;
+import org.apache.jackrabbit.oak.plugins.document.MemoryDiffCache.Key;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
import
org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.Broadcaster;
import
org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.TCPBroadcaster;
@@ -63,9 +63,11 @@ public class BroadcastTest {
ArrayList<PersistentCache> nodeList = new ArrayList<PersistentCache>();
for (int nodes = 1; nodes < 20; nodes++) {
PersistentCache pc = new PersistentCache("target/broadcastTest/p"
+ nodes + ",broadcast=" + type);
- Cache<PathRev, StringValue> cache = openCache(pc);
- String key = "/test" + Math.random();
- PathRev k = new PathRev(key, new RevisionVector(new Revision(0, 0,
0)));
+ Cache<Key, StringValue> cache = openCache(pc);
+ Path key = Path.fromString("/test" + Math.random());
+ RevisionVector from = RevisionVector.fromString("r1-0-1");
+ RevisionVector to = RevisionVector.fromString("r2-0-1");
+ Key k = new Key(key, from, to);
long time = System.currentTimeMillis();
for (int i = 0; i < 2000; i++) {
cache.put(k, new StringValue("Hello World " + i));
@@ -204,10 +206,12 @@ public class BroadcastTest {
new File("target/broadcastTest").mkdirs();
PersistentCache p1 = new
PersistentCache("target/broadcastTest/p1,broadcast=" + type);
PersistentCache p2 = new
PersistentCache("target/broadcastTest/p2,broadcast=" + type);
- Cache<PathRev, StringValue> c1 = openCache(p1);
- Cache<PathRev, StringValue> c2 = openCache(p2);
- String key = "/test" + Math.random();
- PathRev k = new PathRev(key, new RevisionVector(new Revision(0, 0,
0)));
+ Cache<Key, StringValue> c1 = openCache(p1);
+ Cache<Key, StringValue> c2 = openCache(p2);
+ Path key = Path.fromString("/test" + Math.random());
+ RevisionVector from = RevisionVector.fromString("r1-0-1");
+ RevisionVector to = RevisionVector.fromString("r2-0-1");
+ Key k = new Key(key, from, to);
int correct = 0;
for (int i = 0; i < 50; i++) {
c1.put(k, new StringValue("Hello World " + i));
@@ -280,8 +284,8 @@ public class BroadcastTest {
}, timeoutInMilliseconds);
}
- private static Cache<PathRev, StringValue> openCache(PersistentCache p) {
- CacheLIRS<PathRev, StringValue> cache = new CacheLIRS.Builder<PathRev,
StringValue>().
+ private static Cache<Key, StringValue> openCache(PersistentCache p) {
+ CacheLIRS<Key, StringValue> cache = new CacheLIRS.Builder<Key,
StringValue>().
maximumSize(1).build();
return p.wrap(null, null, cache, CacheType.DIFF);
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheTest.java
Wed Apr 10 11:13:19 2019
@@ -30,6 +30,7 @@ import com.google.common.cache.Cache;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
import org.apache.jackrabbit.oak.commons.junit.LogCustomizer;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.PathRev;
import org.apache.jackrabbit.oak.plugins.document.Revision;
import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
@@ -63,7 +64,7 @@ public class CacheTest {
Thread.yield();
}
for (int i = 0; i < 100; i++) {
- PathRev k = new PathRev("/" + counter, new
RevisionVector(new Revision(0, 0, i)));
+ PathRev k = new PathRev(Path.fromString("/" + counter),
new RevisionVector(new Revision(0, 0, i)));
map.getIfPresent(k);
map.put(k, new StringValue(largeString));
}
Added:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/DataTypeUtilTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/DataTypeUtilTest.java?rev=1857240&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/DataTypeUtilTest.java
(added)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/DataTypeUtilTest.java
Wed Apr 10 11:13:19 2019
@@ -0,0 +1,167 @@
+/*
+ * 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.persistentCache;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+
+import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState;
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
+import org.apache.jackrabbit.oak.plugins.document.Path;
+import org.apache.jackrabbit.oak.plugins.document.NamePathRev;
+import org.apache.jackrabbit.oak.plugins.document.PathRev;
+import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
+import org.h2.mvstore.WriteBuffer;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class DataTypeUtilTest {
+
+ @Rule
+ public DocumentMKBuilderProvider builderProvider = new
DocumentMKBuilderProvider();
+
+ private WriteBuffer wb = new WriteBuffer(1024);
+
+ @Test
+ public void booleanToBufferTrue() {
+ DataTypeUtil.booleanToBuffer(true, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertTrue(DataTypeUtil.booleanFromBuffer(rb));
+ }
+
+ @Test
+ public void booleanToBufferFalse() {
+ DataTypeUtil.booleanToBuffer(false, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertFalse(DataTypeUtil.booleanFromBuffer(rb));
+ }
+
+ @Test
+ public void revisionVectorToBufferEmpty() {
+ RevisionVector empty = new RevisionVector();
+ DataTypeUtil.revisionVectorToBuffer(empty, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(empty, DataTypeUtil.revisionVectorFromBuffer(rb));
+ }
+
+ @Test
+ public void revisionVectorToBuffer() {
+ RevisionVector revisions = RevisionVector.fromString("r9-0-1,br7-0-2");
+ DataTypeUtil.revisionVectorToBuffer(revisions, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(revisions, DataTypeUtil.revisionVectorFromBuffer(rb));
+ }
+
+ @Test
+ public void pathToBufferRoot() {
+ Path p = Path.ROOT;
+ DataTypeUtil.pathToBuffer(p, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(p, DataTypeUtil.pathFromBuffer(rb));
+ }
+
+ @Test
+ public void pathToBuffer() {
+ Path p = Path.fromString("/foo/bar/quux");
+ DataTypeUtil.pathToBuffer(p, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(p, DataTypeUtil.pathFromBuffer(rb));
+ }
+
+ @Test
+ public void relPathToBuffer() {
+ Path p = Path.fromString("foo/bar/quux");
+ DataTypeUtil.pathToBuffer(p, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(p, DataTypeUtil.pathFromBuffer(rb));
+ }
+
+ @Test
+ public void relPathSingleElementToBuffer() {
+ Path p = Path.fromString("foo");
+ DataTypeUtil.pathToBuffer(p, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(p, DataTypeUtil.pathFromBuffer(rb));
+ }
+
+ @Test
+ public void relPathMultipleToBuffer() {
+ Path fooBar = Path.fromString("foo/bar");
+ Path barBaz = Path.fromString("bar/baz");
+ DataTypeUtil.pathToBuffer(fooBar, wb);
+ DataTypeUtil.pathToBuffer(barBaz, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(fooBar, DataTypeUtil.pathFromBuffer(rb));
+ assertEquals(barBaz, DataTypeUtil.pathFromBuffer(rb));
+ }
+
+ @Test
+ public void pathRevToBuffer() {
+ Path p = Path.fromString("/foo/bar/quux");
+ RevisionVector rv = RevisionVector.fromString("r3-4-1,br4-9-2");
+ PathRev expected = new PathRev(p, rv);
+ DataTypeUtil.pathRevToBuffer(expected, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(expected, DataTypeUtil.pathRevFromBuffer(rb));
+ }
+
+ @Test
+ public void pathNameRevToBuffer() {
+ Path p = Path.fromString("/foo/bar/quux");
+ String name = "baz";
+ RevisionVector rv = RevisionVector.fromString("r3-4-1,br4-9-2");
+ NamePathRev expected = new NamePathRev(name, p, rv);
+ DataTypeUtil.namePathRevToBuffer(expected, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(expected, DataTypeUtil.namePathRevFromBuffer(rb));
+ }
+
+ @Test
+ public void stateToBufferLastRevNull() {
+ DocumentNodeStore ns = builderProvider.newBuilder().build();
+ Path p = Path.fromString("/foo/bar");
+ RevisionVector rootRev = ns.getHeadRevision();
+ DocumentNodeState expected = new DocumentNodeState(ns, p, rootRev,
+ Collections.emptyMap(), true, 0, null, false);
+ DataTypeUtil.stateToBuffer(expected, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(expected, DataTypeUtil.stateFromBuffer(ns, rb));
+ }
+
+ @Test
+ public void stateToBuffer() {
+ DocumentNodeStore ns = builderProvider.newBuilder().build();
+ Path p = Path.fromString("/foo/bar");
+ RevisionVector rootRev = ns.getHeadRevision();
+ DocumentNodeState expected = new DocumentNodeState(ns, p, rootRev,
+ Collections.emptyMap(), true, 0, rootRev, false);
+ DataTypeUtil.stateToBuffer(expected, wb);
+ ByteBuffer rb = readBufferFrom(wb);
+ assertEquals(expected, DataTypeUtil.stateFromBuffer(ns, rb));
+ }
+
+ private static ByteBuffer readBufferFrom(WriteBuffer wb) {
+ ByteBuffer rb = wb.getBuffer();
+ rb.rewind();
+ return rb;
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/DataTypeUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/NodeCacheTest.java
Wed Apr 10 11:13:19 2019
@@ -25,7 +25,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Consumer;
-import com.google.common.base.Predicate;
import com.google.common.cache.RemovalCause;
import com.google.common.collect.Lists;
@@ -39,12 +38,13 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStateCache;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
+import org.apache.jackrabbit.oak.plugins.document.NamePathRev;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.PathRev;
import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
-import org.apache.jackrabbit.oak.spi.filter.PathFilter;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.jackrabbit.oak.stats.Counting;
@@ -57,9 +57,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import static java.util.Arrays.asList;
-import static java.util.Collections.emptyList;
-import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -74,7 +71,7 @@ public class NodeCacheTest {
private DocumentStore store;
private DocumentNodeStore ns;
private NodeCache<PathRev, DocumentNodeState> nodeCache;
- private NodeCache<PathRev, DocumentNodeState.Children> nodeChildren;
+ private NodeCache<NamePathRev, DocumentNodeState.Children> nodeChildren;
private ScheduledExecutorService executor =
Executors.newSingleThreadScheduledExecutor();
private StatisticsProvider statsProvider = new
DefaultStatisticsProvider(executor);
@@ -93,8 +90,8 @@ public class NodeCacheTest {
builder.child("c").child("d");
AbstractDocumentNodeState root = (AbstractDocumentNodeState)
ns.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
- PathRev prc = new PathRev("/c", root.getRootRevision());
- PathRev pra = new PathRev("/a", root.getRootRevision());
+ PathRev prc = new PathRev(Path.fromString("/c"),
root.getRootRevision());
+ PathRev pra = new PathRev(Path.fromString("/a"),
root.getRootRevision());
Counting counter =
nodeCache.getPersistentCacheStats().getPutRejectedAsCachedInSecCounter();
long count0 = counter.getCount();
@@ -121,7 +118,7 @@ public class NodeCacheTest {
assertContains(nodeCache, "/a/b");
assertContains(nodeCache, "/a");
- assertContains(nodeChildren, "/a");
+ assertPathNameRevs(nodeChildren, "/a", true);
ns.setNodeStateCache(new PathExcludingCache("/c"));
@@ -131,14 +128,15 @@ public class NodeCacheTest {
ns.getRoot().getChildNode("c").getChildNode("d");
assertNotContains(nodeCache, "/c/d");
assertNotContains(nodeCache, "/c");
- assertNotContains(nodeChildren, "/c");
+ assertPathNameRevs(nodeChildren, "/c", false);
}
@Test
public void cachePredicateSync() throws Exception{
- PathFilter pf = new PathFilter(asList("/a"), emptyList());
- Predicate<String> p = path -> pf.filter(path) ==
PathFilter.Result.INCLUDE;
- initializeNodeStore(false, b -> b.setNodeCachePredicate(p));
+ Path a = Path.fromString("/a");
+ initializeNodeStore(false, b -> b.setNodeCachePathPredicate(
+ path -> path != null && (a.equals(path) ||
a.isAncestorOf(path))
+ ));
NodeBuilder builder = ns.getRoot().builder();
builder.child("a").child("c1");
@@ -158,9 +156,10 @@ public class NodeCacheTest {
// OAK-7153
@Test
public void persistentCacheAccessForIncludedPathOnly() throws Exception {
- PathFilter pf = new PathFilter(singletonList("/a"), emptyList());
- Predicate<String> p = path -> pf.filter(path) ==
PathFilter.Result.INCLUDE;
- initializeNodeStore(false, b -> b.setNodeCachePredicate(p));
+ Path a = Path.fromString("/a");
+ initializeNodeStore(false, b -> b.setNodeCachePathPredicate(
+ path -> path != null && (a.equals(path) ||
a.isAncestorOf(path))
+ ));
NodeBuilder builder = ns.getRoot().builder();
builder.child("x");
@@ -234,7 +233,7 @@ public class NodeCacheTest {
ns = builder.getNodeStore();
nodeCache = (NodeCache<PathRev, DocumentNodeState>) ns.getNodeCache();
- nodeChildren = (NodeCache<PathRev, DocumentNodeState.Children>)
ns.getNodeChildrenCache();
+ nodeChildren = (NodeCache<NamePathRev, DocumentNodeState.Children>)
ns.getNodeChildrenCache();
}
@@ -264,10 +263,38 @@ public class NodeCacheTest {
}
}
+ private static <V extends CacheValue> void
assertPathNameRevs(NodeCache<NamePathRev, V> cache, String path, boolean
contains) {
+ List<NamePathRev> revs = getPathNameRevs(cache, path);
+ List<NamePathRev> matchingRevs = Lists.newArrayList();
+ for (NamePathRev pr : revs) {
+ if (cache.getGenerationalMap().containsKey(pr)) {
+ matchingRevs.add(pr);
+ }
+ }
+
+ if (contains && matchingRevs.isEmpty()) {
+ fail(String.format("Expecting entry for [%s]. Did not found in
%s", path, matchingRevs));
+ }
+
+ if (!contains && !matchingRevs.isEmpty()) {
+ fail(String.format("Expecting entry for [%s]. Found %s", path,
revs));
+ }
+ }
+
private static <V extends CacheValue> List<PathRev>
getPathRevs(NodeCache<PathRev, V> cache, String path) {
List<PathRev> revs = Lists.newArrayList();
for (PathRev pr : cache.asMap().keySet()) {
- if (pr.getPath().equals(path)) {
+ if (pr.getPath().toString().equals(path)) {
+ revs.add(pr);
+ }
+ }
+ return revs;
+ }
+
+ private static <V extends CacheValue> List<NamePathRev>
getPathNameRevs(NodeCache<NamePathRev, V> cache, String path) {
+ List<NamePathRev> revs = Lists.newArrayList();
+ for (NamePathRev pr : cache.asMap().keySet()) {
+ if (pr.getPath().toString().equals(path)) {
revs.add(pr);
}
}
@@ -282,14 +309,14 @@ public class NodeCacheTest {
}
@Override
- public AbstractDocumentNodeState getDocumentNodeState(String path,
RevisionVector rootRevision,
+ public AbstractDocumentNodeState getDocumentNodeState(Path path,
RevisionVector rootRevision,
RevisionVector
lastRev) {
return null;
}
@Override
- public boolean isCached(String path) {
- if (path.startsWith(excludeRoot)) {
+ public boolean isCached(Path path) {
+ if (path.toString().startsWith(excludeRoot)) {
return true;
}
return false;
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/rdb/RDBDocumentStoreTest.java
Wed Apr 10 11:13:19 2019
@@ -38,6 +38,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.DocumentStoreFixture;
import org.apache.jackrabbit.oak.plugins.document.MissingLastRevSeeker;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.Revision;
import org.apache.jackrabbit.oak.plugins.document.UpdateOp;
import
org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore.QueryCondition;
@@ -183,7 +184,8 @@ public class RDBDocumentStoreTest extend
super.ds.create(Collection.NODES,
Collections.singletonList(up2));
// query
- List<NodeDocument> results = super.ds.query(Collection.NODES,
Utils.getKeyLowerLimit("/testRDBJDBCPerfLog"),
Utils.getKeyUpperLimit("/testRDBJDBCPerfLog"), 10);
+ Path p = Path.fromString("/testRDBJDBCPerfLog");
+ List<NodeDocument> results = super.ds.query(Collection.NODES,
Utils.getKeyLowerLimit(p), Utils.getKeyUpperLimit(p), 10);
assertEquals(1, results.size());
assertEquals(2, logCustomizerQuery.getLogs().size());
} finally {
@@ -222,7 +224,7 @@ public class RDBDocumentStoreTest extend
assertNotNull(ds.findAndUpdate(NODES, op));
updated = true;
}
- if (doc.getPath().startsWith("/lastRevnode-")) {
+ if (doc.getPath().toString().startsWith("/lastRevnode-")) {
ids.add(doc.getId());
}
}
Modified:
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java?rev=1857240&r1=1857239&r2=1857240&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
(original)
+++
jackrabbit/oak/trunk/oak-store-document/src/test/java/org/apache/jackrabbit/oak/plugins/document/secondary/SecondaryStoreCacheTest.java
Wed Apr 10 11:13:19 2019
@@ -31,6 +31,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.DocumentMKBuilderProvider;
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStore;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
+import org.apache.jackrabbit.oak.plugins.document.Path;
import org.apache.jackrabbit.oak.plugins.document.Revision;
import org.apache.jackrabbit.oak.plugins.document.RevisionVector;
import org.apache.jackrabbit.oak.plugins.document.bundlor.BundledTypesRegistry;
@@ -85,8 +86,8 @@ public class SecondaryStoreCacheTest {
RevisionVector rv1 = new RevisionVector(new Revision(1,0,1));
RevisionVector rv2 = new RevisionVector(new Revision(1,0,3));
- assertNull(cache.getDocumentNodeState("/a/b", rv1, rv2));
- assertNull(cache.getDocumentNodeState("/x", rv1, rv2));
+ assertNull(cache.getDocumentNodeState(Path.fromString("/a/b"), rv1,
rv2));
+ assertNull(cache.getDocumentNodeState(Path.fromString("/x"), rv1,
rv2));
}
@Test
@@ -105,7 +106,7 @@ public class SecondaryStoreCacheTest {
//Lookup should work fine
AbstractDocumentNodeState a_r2 = documentState(r2, "/a/c");
AbstractDocumentNodeState result
- = cache.getDocumentNodeState("/a/c", r2.getRootRevision(),
a_r2.getLastRevision());
+ = cache.getDocumentNodeState(Path.fromString("/a/c"),
r2.getRootRevision(), a_r2.getLastRevision());
assertTrue(EqualsDiff.equals(a_r2, result));
//Child docs should only have lastRev and not root rev
@@ -121,7 +122,7 @@ public class SecondaryStoreCacheTest {
AbstractDocumentNodeState r3 = merge(nb);
//Now look from older revision
- result = cache.getDocumentNodeState("/a/c", r3.getRootRevision(),
a_r2.getLastRevision());
+ result = cache.getDocumentNodeState(Path.fromString("/a/c"),
r3.getRootRevision(), a_r2.getLastRevision());
//now as its not visible from head it would not be visible
assertNull(result);
@@ -143,11 +144,11 @@ public class SecondaryStoreCacheTest {
AbstractDocumentNodeState a_c_1 = documentState(primary.getRoot(),
"/a/c");
AbstractDocumentNodeState result
- = cache.getDocumentNodeState("/a/c", r1.getRootRevision(),
a_c_1.getLastRevision());
+ = cache.getDocumentNodeState(Path.fromString("/a/c"),
r1.getRootRevision(), a_c_1.getLastRevision());
assertTrue(EqualsDiff.equals(a_c_1, result));
//Read from older revision
- result = cache.getDocumentNodeState("/a/c", r0.getRootRevision(),
a_c_0.getLastRevision());
+ result = cache.getDocumentNodeState(Path.fromString("/a/c"),
r0.getRootRevision(), a_c_0.getLastRevision());
assertTrue(EqualsDiff.equals(a_c_0, result));
}
@@ -195,7 +196,7 @@ public class SecondaryStoreCacheTest {
observer.contentChanged(r0, CommitInfo.EMPTY);
- AbstractDocumentNodeState result = cache.getDocumentNodeState("/a/c",
r0.getRootRevision(), a_c_0
+ AbstractDocumentNodeState result =
cache.getDocumentNodeState(Path.fromString("/a/c"), r0.getRootRevision(), a_c_0
.getLastRevision());
assertTrue(EqualsDiff.equals(a_c_0, result));
@@ -206,13 +207,13 @@ public class SecondaryStoreCacheTest {
//Change is yet not pushed to secondary i.e. observer not invoked
//but lookup with latest root should still work fine if lastRev matches
- result = cache.getDocumentNodeState("/a/c", r1.getRootRevision(), a_c_0
+ result = cache.getDocumentNodeState(Path.fromString("/a/c"),
r1.getRootRevision(), a_c_0
.getLastRevision());
assertTrue(EqualsDiff.equals(a_c_0, result));
//Change which is not pushed would though not be visible
AbstractDocumentNodeState a_e_1 = documentState(primary.getRoot(),
"/a/e");
- result = cache.getDocumentNodeState("/a/e", r1.getRootRevision(), a_e_1
+ result = cache.getDocumentNodeState(Path.fromString("/a/e"),
r1.getRootRevision(), a_e_1
.getLastRevision());
assertNull(result);
}
@@ -221,9 +222,9 @@ public class SecondaryStoreCacheTest {
public void isCached() throws Exception{
SecondaryStoreCache cache = createCache(new PathFilter(of("/a"),
empty));
- assertTrue(cache.isCached("/a"));
- assertTrue(cache.isCached("/a/b"));
- assertFalse(cache.isCached("/x"));
+ assertTrue(cache.isCached(Path.fromString("/a")));
+ assertTrue(cache.isCached(Path.fromString("/a/b")));
+ assertFalse(cache.isCached(Path.fromString("/x")));
}
@Test