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 th...@apache.org on 2012/07/24 12:12:42 UTC
svn commit: r1364960 - in
/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large:
CreateRandomNodesTraverseTest.java DescendantCountTest.java
NodeCreator.java RandomNodeCreator.java
Author: thomasm
Date: Tue Jul 24 10:12:42 2012
New Revision: 1364960
URL: http://svn.apache.org/viewvc?rev=1364960&view=rev
Log:
OAK-122 Performance test suite (RandomNodeCreator from Mete)
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/CreateRandomNodesTraverseTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/RandomNodeCreator.java
Modified:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/DescendantCountTest.java
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/NodeCreator.java
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/CreateRandomNodesTraverseTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/CreateRandomNodesTraverseTest.java?rev=1364960&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/CreateRandomNodesTraverseTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/CreateRandomNodesTraverseTest.java Tue Jul 24 10:12:42 2012
@@ -0,0 +1,49 @@
+/*
+ * 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.mk.large;
+
+import org.apache.jackrabbit.mk.MultiMkTestBase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/**
+ * Creates and then reads nodes distributed in a tree with random width at each
+ * level.
+ */
+@RunWith(Parameterized.class)
+public class CreateRandomNodesTraverseTest extends MultiMkTestBase {
+
+ public CreateRandomNodesTraverseTest(String url) {
+ super(url);
+ }
+
+ @Test
+ public void test() throws Exception {
+ RandomNodeCreator c = new RandomNodeCreator(mk, 1);
+ c.setTotalCount(200);
+ c.setMaxWidth(10);
+ // c.setLogToSystemOut(true);
+
+ // 1 million node test
+ // c.setLogToSystemOut(true);
+ // c.setTotalCount(1000000);
+
+ // 20 million node test
+ // c.setTotalCount(20000000);
+
+ c.create();
+ c.traverse();
+ }
+}
\ No newline at end of file
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/DescendantCountTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/DescendantCountTest.java?rev=1364960&r1=1364959&r2=1364960&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/DescendantCountTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/DescendantCountTest.java Tue Jul 24 10:12:42 2012
@@ -56,7 +56,7 @@ public class DescendantCountTest extends
NodeCreator c = new NodeCreator(mk);
for (int i = 1; i < 20; i++) {
- c.setNodeName("test" + i);
+ c.setTestRoot("test" + i);
c.setWidth(2);
c.setTotalCount(i);
c.setData(null);
Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/NodeCreator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/NodeCreator.java?rev=1364960&r1=1364959&r2=1364960&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/NodeCreator.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/NodeCreator.java Tue Jul 24 10:12:42 2012
@@ -23,11 +23,16 @@ import org.apache.jackrabbit.mk.api.Micr
*/
public class NodeCreator {
+ private static final String DEFAULT_TEST_ROOT = "test";
+ private static final int DEFAULT_COUNT = 200;
+ private static final int DEFAULT_WIDTH = 30;
+
private final MicroKernel mk;
+ private String testRoot = DEFAULT_TEST_ROOT;
+ private int totalCount = DEFAULT_COUNT;
+ private int width = DEFAULT_WIDTH;
private String head;
- private int totalCount = 200;
- private int width = 30, count;
- private String nodeName = "test";
+ private int count;
private String data = "Hello World";
private boolean logToSystemOut;
@@ -44,8 +49,8 @@ public class NodeCreator {
this.totalCount = totalCount;
}
- public void setNodeName(String nodeName) {
- this.nodeName = nodeName;
+ public void setTestRoot(String testRoot) {
+ this.testRoot = testRoot;
}
public void setData(String data) {
@@ -53,21 +58,21 @@ public class NodeCreator {
}
public void create() {
- log("implementation: " + mk);
- log("creating " + totalCount + " nodes");
- head = mk.commit("/", "+\"" + nodeName + "\":{}", head, "");
+ log("Implementation: " + mk);
+ log("Creating " + totalCount + " nodes under " + testRoot);
+ head = mk.commit("/", "+\"" + testRoot + "\":{}", head, "");
count = 0;
int depth = (int) Math.ceil(Math.log(totalCount) / Math.log(width));
- log("depth: " + depth);
- createNodes(nodeName, depth);
+ log("Depth: " + depth);
+ createNodes(testRoot, depth);
log("");
}
public void traverse() {
count = 0;
int depth = (int) Math.ceil(Math.log(totalCount) / Math.log(width));
- log("depth: " + depth);
- traverse(nodeName, depth);
+ log("Depth: " + depth);
+ traverse(testRoot, depth);
}
private void createNodes(String parent, int depth) {
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/RandomNodeCreator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/RandomNodeCreator.java?rev=1364960&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/RandomNodeCreator.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/large/RandomNodeCreator.java Tue Jul 24 10:12:42 2012
@@ -0,0 +1,150 @@
+/*
+ * 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.mk.large;
+
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.Random;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.json.JsopBuilder;
+import org.apache.jackrabbit.mk.simple.NodeImpl;
+
+/**
+ * A utility to create a number of nodes in a random tree structure. Each level
+ * has a random (but fixed for the level) number of nodes with at most maxWidth
+ * nodes.
+ */
+public class RandomNodeCreator {
+
+ private static final String DEFAULT_TEST_ROOT = "testRandom";
+ private static final int DEFAULT_COUNT = 200;
+ private static final int DEFAULT_WIDTH = 30;
+
+ private final MicroKernel mk;
+ private final Random random;
+
+ private String testRoot = DEFAULT_TEST_ROOT;
+ private int totalCount = DEFAULT_COUNT;
+ private int maxWidth = DEFAULT_WIDTH;
+ private boolean logToSystemOut;
+ private String head;
+ private int count;
+ private Queue<String> queue = new LinkedList<String>();
+
+ public RandomNodeCreator(MicroKernel mk, int seed) {
+ this.mk = mk;
+ head = mk.getHeadRevision();
+ random = new Random(seed);
+ }
+
+ public void setTestRoot(String testRoot) {
+ this.testRoot = testRoot;
+ }
+
+ public void setTotalCount(int totalCount) {
+ this.totalCount = totalCount;
+ }
+
+ public void setMaxWidth(int maxWidth) {
+ this.maxWidth = maxWidth;
+ }
+
+ public void setLogToSystemOut(boolean logToSystemOut) {
+ this.logToSystemOut = logToSystemOut;
+ }
+
+ public void create() {
+ log("Implementation: " + mk);
+ log("Creating " + totalCount + " nodes under " + testRoot);
+ head = mk.commit("/", "+\"" + testRoot + "\":{}", head, "");
+ count = 0;
+ createNodes(testRoot);
+ }
+
+ public void traverse() {
+ count = 0;
+ queue.clear();
+ log("Traversing " + totalCount + " nodes");
+ traverse(testRoot);
+ }
+
+ private void createNodes(String parent) {
+ if (count >= totalCount) {
+ return;
+ }
+
+ int width = random.nextInt(maxWidth) + 1;
+
+ head = mk.commit("/" + parent, "^ \"width\":" + width, head, null);
+
+ StringBuilder buff = new StringBuilder();
+ for (int i = 0; i < width; i++) {
+ if (count >= totalCount) {
+ break;
+ }
+
+ String p = parent + "/node" + count;
+ queue.add(p);
+ buff.append("+ \"" + p + "\": {");
+ buff.append("}\n");
+ count++;
+ }
+ head = mk.commit("/", buff.toString(), head, "");
+ log("Committed with width: " + width + "\n" + buff.toString());
+
+ while (!queue.isEmpty()) {
+ createNodes(queue.poll());
+ }
+ }
+
+ private void traverse(String parent) {
+ if (count >= totalCount) {
+ return;
+ }
+
+ String parentJson = JsopBuilder.prettyPrint(mk.getNodes("/" + parent, mk.getHeadRevision(), 1, 0, -1, null));
+ NodeImpl parentNode = NodeImpl.parse(parentJson);
+ int width = Integer.parseInt(parentNode.getProperty("width"));
+
+ for (int i = 0; i < width; i++) {
+ if (count >= totalCount) {
+ break;
+ }
+
+ String p = parent + "/node" + count;
+ log("Traversed: " + p);
+ if (!mk.nodeExists("/" + p, head)) {
+ break;
+ }
+ mk.getNodes("/" + p, head, 1, 0, -1, null);
+ queue.add(p);
+ count++;
+ }
+
+ while (!queue.isEmpty()) {
+ traverse(queue.poll());
+ }
+ }
+
+ private void log(String s) {
+ if (logToSystemOut) {
+ System.out.println(s);
+ }
+ }
+
+}
\ No newline at end of file