jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1165311 - /jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java
Date Mon, 05 Sep 2011 15:06:47 GMT
Author: thomasm
Date: Mon Sep  5 15:06:47 2011
New Revision: 1165311

URL: http://svn.apache.org/viewvc?rev=1165311&view=rev
Log:
New test case (creating and reading many nodes).

Added:
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java

Added: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java?rev=1165311&view=auto
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java
(added)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/large/CreateNodesTraverseTest.java
Mon Sep  5 15:06:47 2011
@@ -0,0 +1,135 @@
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.jackrabbit.mk.MicroKernelFactory;
+import org.apache.jackrabbit.mk.api.MicroKernel;
+
+/**
+ * Test creating nodes and traversing.
+ */
+public class CreateNodesTraverseTest extends TestCase {
+
+    private static final String URL = "mem:;clean";
+    // created 200000 nodes in 3 seconds (61633 nodes/sec)
+    // read 200000 nodes in 0 seconds (212539 nodes/sec)
+
+    // private static final String URL = "fs:target/temp;clean";
+    // created 200000 nodes in 22 seconds (8837 nodes/sec)
+    // created 1031180 nodes in 714 seconds (1442 nodes/sec)
+
+    // private static final String URL = "mem:fs:target/temp;clean";
+
+    // -Xmx512m -Dmk.fastDb=true
+    // private int totalCount = 100000;
+
+    private int totalCount = 200;
+
+    private int width = 30, count;
+    private MicroKernel mk;
+    private String head;
+
+    public void setUp() throws Exception {
+        mk = MicroKernelFactory.getInstance(URL);
+        head = mk.getHeadRevision();
+    }
+
+    public void tearDown() throws InterruptedException {
+        mk.dispose();
+    }
+
+    public void test1() throws Exception {
+        // Profiler p = new Profiler();
+         // p.interval = 1;
+         // p.startCollecting();
+         test();
+         // System.out.println(p.getTop(5));
+    }
+
+    private void log(String s) {
+        // System.out.println(s);
+    }
+
+    public void test() throws Exception {
+        int depth = (int) Math.ceil(Math.log(totalCount) / Math.log(width));
+        log("depth: " + depth);
+        head = mk.commit("/", "+\"test\":{}", head, "");
+        long time;
+        time = System.currentTimeMillis();
+        count = 0;
+        createNodes("test", depth);
+        time = System.currentTimeMillis() - time;
+        log("created " + count + " nodes in " + (time / 1000) +
+                " seconds (" + (count * 1000 / time) + " nodes/sec)");
+
+        for (int i = 0; i < 2; i++) {
+            time = System.currentTimeMillis();
+            count = 0;
+            traverse("test", depth);
+            time = System.currentTimeMillis() - time;
+            log("read " + count + " nodes in " + (time / 1000) +
+                    " seconds (" + (count * 1000 / time) + " nodes/sec)");
+        }
+
+    }
+
+    private void createNodes(String parent, int depth) {
+        if (count >= totalCount) {
+            return;
+        }
+        StringBuilder buff = new StringBuilder();
+        for (int i = 0; i < width; i++) {
+            if (count >= totalCount && depth == 0) {
+                break;
+            }
+            String p = parent + "/node" + depth + i;
+            buff.append("+ \"" + p + "\": {\"data\":\"Hello World " + count++ + "\"}\n");
+            if (count % 200000 == 0) {
+                log(count + " nodes");
+            }
+        }
+        head = mk.commit("/", buff.toString(), head, "");
+        if (depth > 0) {
+            for (int i = 0; i < width; i++) {
+                String p = parent + "/node" + depth + i;
+                createNodes(p, depth - 1);
+            }
+        }
+    }
+
+    private void traverse(String parent, int depth) throws Exception {
+        if (count >= totalCount) {
+            return;
+        }
+        for (int i = 0; i < width; i++) {
+            if (count >= totalCount && depth == 0) {
+                break;
+            }
+            String p = parent + "/node" + depth + i;
+            if (!mk.nodeExists("/" + p, head)) {
+                break;
+            }
+            mk.getNodes("/" + p, head);
+            count++;
+            if (count % 200000 == 0) {
+                log(count + " nodes");
+            }
+            if (depth > 0) {
+                traverse(p, depth - 1);
+            }
+        }
+    }
+
+}



Mime
View raw message