You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2012/06/22 16:39:14 UTC
svn commit: r1352905 - in /jackrabbit/trunk/test/performance/base/src/main:
java/org/apache/jackrabbit/performance/ resources/
Author: angela
Date: Fri Jun 22 14:39:13 2012
New Revision: 1352905
URL: http://svn.apache.org/viewvc?rev=1352905&view=rev
Log:
JCR-3356 : performance tests
Added:
jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/AbstractDeepTreeTest.java
jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadAccessControlledTreeTest.java
jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadDeepTreeTest.java
jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ReadDeepTreeTest.java
jackrabbit/trunk/test/performance/base/src/main/resources/deepTree.xml
Added: jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/AbstractDeepTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/AbstractDeepTreeTest.java?rev=1352905&view=auto
==============================================================================
--- jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/AbstractDeepTreeTest.java (added)
+++ jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/AbstractDeepTreeTest.java Fri Jun 22 14:39:13 2012
@@ -0,0 +1,103 @@
+/*
+ * 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.performance;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.util.TraversingItemVisitor;
+
+public abstract class AbstractDeepTreeTest extends AbstractTest {
+
+ protected Session adminSession;
+ protected Node testRoot;
+
+ protected List<String> allPaths;
+
+ @Override
+ protected void beforeSuite() throws Exception {
+ adminSession = getRepository().login(getCredentials());
+ String name = getClass().getSimpleName();
+ Node rn = adminSession.getRootNode();
+
+ if (!rn.hasNode(name)) {
+ testRoot = adminSession.getRootNode().addNode(name, "nt:unstructured");
+ InputStream in = getClass().getClassLoader().getResourceAsStream("deepTree.xml");
+ adminSession.importXML(testRoot.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+ adminSession.save();
+ } else {
+ testRoot = rn.getNode(name);
+ }
+
+ final List<String> paths = new ArrayList<String>();
+ ItemVisitor v = new TraversingItemVisitor.Default() {
+ @Override
+ protected void entering(Node node, int i) throws RepositoryException {
+ paths.add(node.getPath());
+ super.entering(node, i);
+ }
+ @Override
+ protected void entering(Property prop, int i) throws RepositoryException {
+ paths.add(prop.getPath());
+ super.entering(prop, i);
+ }
+ };
+ v.visit(testRoot);
+ allPaths = paths;
+
+ System.out.println("All paths: " + allPaths.size());
+ }
+
+ @Override
+ protected void afterSuite() throws Exception {
+ testRoot.remove();
+ adminSession.save();
+ adminSession.logout();
+ }
+
+ protected static void randomRead(Session testSession, List<String> allPaths, int cnt) throws RepositoryException {
+ int nodeCnt = 0;
+ int propertyCnt = 0;
+ int noAccess = 0;
+ int size = allPaths.size();
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < cnt; i++) {
+ double rand = size * Math.random();
+ int index = (int) Math.floor(rand);
+ String path = allPaths.get(index);
+ if (testSession.itemExists(path)) {
+ Item item = testSession.getItem(path);
+ if (item.isNode()) {
+ nodeCnt++;
+ } else {
+ propertyCnt++;
+ }
+ } else {
+ noAccess++;
+ }
+ }
+ long end = System.currentTimeMillis();
+ System.out.println("Reading " + (cnt-noAccess) + " (Nodes: "+ nodeCnt +"; Properties: "+propertyCnt+") completed in " + (end - start));
+ }
+}
Added: jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadAccessControlledTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadAccessControlledTreeTest.java?rev=1352905&view=auto
==============================================================================
--- jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadAccessControlledTreeTest.java (added)
+++ jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadAccessControlledTreeTest.java Fri Jun 22 14:39:13 2012
@@ -0,0 +1,102 @@
+/*
+ * 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.performance;
+
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.security.AccessControlList;
+import javax.jcr.security.AccessControlManager;
+import javax.jcr.security.AccessControlPolicy;
+import javax.jcr.security.AccessControlPolicyIterator;
+import javax.jcr.security.Privilege;
+import javax.jcr.util.TraversingItemVisitor;
+
+import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
+
+/**
+ * Concurrently reads random items from the deep tree where every 10th node is
+ * access controlled.
+ */
+public class ConcurrentReadAccessControlledTreeTest extends AbstractDeepTreeTest {
+
+ private int bgReaders = 50;
+ private int cnt = 10000;
+
+ @Override
+ protected void beforeSuite() throws Exception {
+ super.beforeSuite();
+
+ ItemVisitor visitor = new TraversingItemVisitor.Default() {
+ int counter = 0;
+ @Override
+ protected void entering(Node node, int level) throws RepositoryException {
+ if (++counter == 10) {
+ addPolicy(node);
+ counter = 0;
+ }
+ super.entering(node, level);
+ }
+
+ private void addPolicy(Node node) throws RepositoryException {
+ AccessControlManager acMgr = node.getSession().getAccessControlManager();
+ String path = node.getPath();
+ AccessControlPolicyIterator acIterator = acMgr.getApplicablePolicies(path);
+ if (acIterator.hasNext()) {
+ AccessControlPolicy policy = acIterator.nextAccessControlPolicy();
+ if (policy instanceof AccessControlList) {
+ AccessControlList acl = (AccessControlList) policy;
+ Privilege[] privileges = new Privilege[] {
+ acMgr.privilegeFromName(Privilege.JCR_READ),
+ acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL)
+ };
+ if (acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privileges)) {
+ acMgr.setPolicy(path, acl);
+ node.getSession().save();
+ }
+ }
+ }
+ }
+ };
+
+ visitor.visit(testRoot);
+
+ for (int i = 0; i < bgReaders; i++) {
+ addBackgroundJob(new RandomRead());
+ }
+ }
+
+ @Override
+ protected void runTest() throws Exception {
+ RandomRead randomRead = new RandomRead();
+ randomRead.run();
+ }
+
+ private class RandomRead implements Runnable {
+
+ private final Session testSession = loginReader();
+
+ public void run() {
+ try {
+ randomRead(testSession, allPaths, cnt);
+ } catch (RepositoryException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadDeepTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadDeepTreeTest.java?rev=1352905&view=auto
==============================================================================
--- jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadDeepTreeTest.java (added)
+++ jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ConcurrentReadDeepTreeTest.java Fri Jun 22 14:39:13 2012
@@ -0,0 +1,57 @@
+/*
+ * 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.performance;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * Concurrently reads random items from the deep tree.
+ */
+public class ConcurrentReadDeepTreeTest extends AbstractDeepTreeTest {
+
+ private int bgReaders = 50;
+ private int cnt = 10000;
+
+ @Override
+ protected void beforeSuite() throws Exception {
+ super.beforeSuite();
+
+ for (int i = 0; i < bgReaders; i++) {
+ addBackgroundJob(new RandomRead());
+ }
+ }
+
+ @Override
+ protected void runTest() throws Exception {
+ RandomRead randomRead = new RandomRead();
+ randomRead.run();
+ }
+
+ private class RandomRead implements Runnable {
+
+ private final Session testSession = loginReader();
+
+ public void run() {
+ try {
+ randomRead(testSession, allPaths, cnt);
+ } catch (RepositoryException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ReadDeepTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ReadDeepTreeTest.java?rev=1352905&view=auto
==============================================================================
--- jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ReadDeepTreeTest.java (added)
+++ jackrabbit/trunk/test/performance/base/src/main/java/org/apache/jackrabbit/performance/ReadDeepTreeTest.java Fri Jun 22 14:39:13 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.performance;
+
+import javax.jcr.Session;
+
+/**
+ * Randomly read 100000 items from the deep tree.
+ */
+public class ReadDeepTreeTest extends AbstractDeepTreeTest {
+
+ private Session testSession;
+ private int cnt = 100000;
+
+ @Override
+ protected void beforeSuite() throws Exception {
+ super.beforeSuite();
+
+ testSession = getRepository().login();
+ }
+
+ @Override
+ protected void runTest() throws Exception {
+ randomRead(testSession, allPaths, cnt);
+ }
+
+ @Override
+ protected void afterSuite() throws Exception {
+ testSession.logout();
+ }
+}
\ No newline at end of file
Added: jackrabbit/trunk/test/performance/base/src/main/resources/deepTree.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/test/performance/base/src/main/resources/deepTree.xml?rev=1352905&view=auto
==============================================================================
--- jackrabbit/trunk/test/performance/base/src/main/resources/deepTree.xml (added)
+++ jackrabbit/trunk/test/performance/base/src/main/resources/deepTree.xml Fri Jun 22 14:39:13 2012
@@ -0,0 +1 @@
[... 3 lines stripped ...]