Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java (revision 1404493) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java (working copy) @@ -18,6 +18,7 @@ import java.util.Iterator; import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; import javax.annotation.Nonnull; @@ -69,6 +70,8 @@ */ public class MemoryNodeBuilder implements NodeBuilder { + public static final AtomicLong SNAPSHOT_COUNTER = new AtomicLong(); + static final NodeState NULL_STATE = new MemoryNodeState( ImmutableMap.of(), ImmutableMap.of()); @@ -442,6 +445,7 @@ nodes.put(name, null); } } else { + SNAPSHOT_COUNTER.incrementAndGet(); NodeState after = node.snapshot(); if (after != before) { nodes.put(name, after); Index: oak-core/src/test/java/org/apache/jackrabbit/oak/api/TreeLocationTest.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/api/TreeLocationTest.java (revision 0) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/api/TreeLocationTest.java (revision 0) @@ -0,0 +1,110 @@ +/* + * 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.api; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.jackrabbit.oak.Oak; +import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * TreeLocationTest... + */ +public class TreeLocationTest { + + private ContentRepository repository; + + @Before + public void setUp() { + repository = new Oak().createContentRepository(); + } + + @After + public void tearDown() { + repository = null; + } + + @Test + public void getStatus() throws Exception { + ContentSession session = repository.login(null, null); + Root r = session.getLatestRoot(); + Tree t = r.getTree("/"); + createTree(t, 3, 10); + r.commit(); + + session = repository.login(null, null); + r = session.getLatestRoot(); + long c = MemoryNodeBuilder.SNAPSHOT_COUNTER.get(); + r.getTree("/").getChild("node0").getChild("node1").getChild("node2"); + c = MemoryNodeBuilder.SNAPSHOT_COUNTER.get() - c; + System.out.println("snapshots: " + c); + measureGetStatus(r); + + session = repository.login(null, null); + r = session.getLatestRoot(); + c = MemoryNodeBuilder.SNAPSHOT_COUNTER.get(); + read(r, r.getTree("/node0/node1/node2")); + c = MemoryNodeBuilder.SNAPSHOT_COUNTER.get() - c; + System.out.println("snapshots: " + c); + measureGetStatus(r); + + session = repository.login(null, null); + r = session.getLatestRoot(); + c = MemoryNodeBuilder.SNAPSHOT_COUNTER.get(); + read(r, r.getTree("/")); + c = MemoryNodeBuilder.SNAPSHOT_COUNTER.get() - c; + System.out.println("snapshots: " + c); + measureGetStatus(r); + } + + private void measureGetStatus(Root r) { + TreeLocation l = r.getTree("/").getLocation(); + long time = System.currentTimeMillis(); + List counts = new ArrayList(); + for (int i = 0; i < 10; i++) { + long c = MemoryNodeBuilder.SNAPSHOT_COUNTER.get(); + l.getStatus(); + c = MemoryNodeBuilder.SNAPSHOT_COUNTER.get() - c; + counts.add(c); + } + time = System.currentTimeMillis() - time; + System.out.println("" + time + " ms. (" + counts + ")"); + } + + private void read(Root r, Tree t) { + r.getTree(t.getPath()); + for (Tree child : t.getChildren()) { + read(r, child); + } + } + + private void createTree(Tree t, int numChildren, int level) { + if (level-- <= 0) { + return; + } + for (int i = 0; i < numChildren; i++) { + createTree(t.addChild("node" + i), numChildren, level); + } + } + +} Property changes on: oak-core\src\test\java\org\apache\jackrabbit\oak\api\TreeLocationTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Rev URL Added: svn:eol-style + native