Author: angela
Date: Tue Jul 16 14:51:04 2013
New Revision: 1503739
URL: http://svn.apache.org/r1503739
Log:
OAK-527: permissions (benchmark tests from jr)
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractDeepTreeTest.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/XmlImportTest.java
jackrabbit/oak/trunk/oak-run/src/main/resources/deepTree.xml
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/FlatTreeWithAceForSamePrincipalTest.java
jackrabbit/oak/trunk/oak-run/src/main/resources/org/apache/jackrabbit/oak/fixture/repository.xml
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractDeepTreeTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractDeepTreeTest.java?rev=1503739&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractDeepTreeTest.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractDeepTreeTest.java
Tue Jul 16 14:51:04 2013
@@ -0,0 +1,111 @@
+/*
+ * 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.benchmark;
+
+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();
+
+ long start = System.currentTimeMillis();
+ 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);
+ }
+ System.out.println("Import deep tree: " +
(System.currentTimeMillis()-start));
+
+ 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 {
+ try {
+ testRoot.remove();
+ adminSession.save();
+ adminSession.logout();
+ } finally {
+ super.afterSuite();
+ }
+ }
+
+ protected static void randomRead(Session testSession, List<String>
allPaths, int cnt, boolean doReport) 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();
+ if (doReport) {
+ System.out.println("Session " + testSession.getUserID() + "
reading " + (cnt-noAccess) + " (Nodes: "+ nodeCnt +"; Properties:
"+propertyCnt+") completed in " + (end - start));
+ }
+ }
+}
\ No newline at end of file
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java?rev=1503739&r1=1503738&r2=1503739&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java
Tue Jul 16 14:51:04 2013
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.jcr.Credentials;
+import javax.jcr.GuestCredentials;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
@@ -228,14 +229,8 @@ abstract class AbstractTest extends Benc
*
* @return reader session
*/
- protected Session loginReader() {
- try {
- Session session = repository.login();
- sessions.add(session);
- return session;
- } catch (RepositoryException e) {
- throw new RuntimeException(e);
- }
+ protected Session loginAnonymous() {
+ return login(new GuestCredentials());
}
/**
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java?rev=1503739&r1=1503738&r2=1503739&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/BenchmarkRunner.java
Tue Jul 16 14:51:04 2013
@@ -85,7 +85,11 @@ public class BenchmarkRunner {
new CreateNodesBenchmark(),
new ManyNodes(),
new ObservationTest(),
+ new XmlImportTest(),
new FlatTreeWithAceForSamePrincipalTest(),
+ new ReadDeepTreeTest(),
+ new ConcurrentReadAccessControlledTreeTest(),
+ new ConcurrentReadDeepTreeTest(),
ReadManyTest.linear("LinearReadEmpty", 1, ReadManyTest.EMPTY),
ReadManyTest.linear("LinearReadFiles", 1, ReadManyTest.FILES),
ReadManyTest.linear("LinearReadNodes", 1, ReadManyTest.NODES),
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java?rev=1503739&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
Tue Jul 16 14:51:04 2013
@@ -0,0 +1,109 @@
+/*
+ * 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.benchmark;
+
+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 = 20;
+ 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(loginAnonymous(), false));
+ }
+ }
+
+ @Override
+ protected void runTest() throws Exception {
+ Session testSession = loginAnonymous();
+ RandomRead randomRead = new RandomRead(testSession, true);
+ randomRead.run();
+ testSession.logout();
+ }
+
+ private class RandomRead implements Runnable {
+
+ private final Session testSession;
+ private final boolean doReport;
+
+ private RandomRead(Session testSession, boolean doReport) {
+ this.testSession = testSession;
+ this.doReport = doReport;
+ }
+ public void run() {
+ try {
+ randomRead(testSession, allPaths, cnt, doReport);
+ } catch (RepositoryException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java?rev=1503739&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
Tue Jul 16 14:51:04 2013
@@ -0,0 +1,63 @@
+/*
+ * 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.benchmark;
+
+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(loginAnonymous()));
+ }
+ }
+
+ @Override
+ protected void runTest() throws Exception {
+ Session testSession = loginAnonymous();
+ RandomRead randomRead = new RandomRead(testSession);
+ randomRead.run();
+ testSession.logout();
+ }
+
+ private class RandomRead implements Runnable {
+
+ private final Session testSession;
+
+ private RandomRead(Session testSession) {
+ this.testSession = testSession;
+ }
+
+ public void run() {
+ try {
+ randomRead(testSession, allPaths, cnt, true);
+ } catch (RepositoryException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/FlatTreeWithAceForSamePrincipalTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/FlatTreeWithAceForSamePrincipalTest.java?rev=1503739&r1=1503738&r2=1503739&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/FlatTreeWithAceForSamePrincipalTest.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/FlatTreeWithAceForSamePrincipalTest.java
Tue Jul 16 14:51:04 2013
@@ -63,7 +63,7 @@ public class FlatTreeWithAceForSamePrinc
reader = login(new SimpleCredentials(TEST_USER_ID,
TEST_USER_ID.toCharArray()));
long end = System.currentTimeMillis();
- System.out.println("time "+(end - start));
+ System.out.println("setup time "+(end - start));
}
@Override
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java?rev=1503739&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java
Tue Jul 16 14:51:04 2013
@@ -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.oak.benchmark;
+
+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 = loginAnonymous();
+ }
+
+ @Override
+ protected void runTest() throws Exception {
+ randomRead(testSession, allPaths, cnt, true);
+ }
+
+ @Override
+ protected void afterSuite() throws Exception {
+ testSession.logout();
+ }
+}
\ No newline at end of file
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/XmlImportTest.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/XmlImportTest.java?rev=1503739&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/XmlImportTest.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/XmlImportTest.java
Tue Jul 16 14:51:04 2013
@@ -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.oak.benchmark;
+
+import java.io.InputStream;
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+public class XmlImportTest extends AbstractTest {
+
+ private Session adminSession;
+ private Node testRoot;
+
+ @Override
+ protected void runTest() throws Exception {
+ InputStream in =
getClass().getClassLoader().getResourceAsStream("deepTree.xml");
+ adminSession.importXML(testRoot.getPath(), in,
ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+ adminSession.save();
+}
+
+ @Override
+ protected void beforeTest() throws Exception {
+ adminSession = loginWriter();
+ String name = getClass().getSimpleName();
+ testRoot = adminSession.getRootNode().addNode(name, "nt:unstructured");
+ adminSession.save();
+ }
+
+ @Override
+ protected void afterTest() throws Exception {
+ testRoot.remove();
+ adminSession.save();
+ }
+}
\ No newline at end of file
Added: jackrabbit/oak/trunk/oak-run/src/main/resources/deepTree.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/resources/deepTree.xml?rev=1503739&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/resources/deepTree.xml (added)
+++ jackrabbit/oak/trunk/oak-run/src/main/resources/deepTree.xml Tue Jul 16
14:51:04 2013
@@ -0,0 +1 @@
[... 3 lines stripped ...]
Modified:
jackrabbit/oak/trunk/oak-run/src/main/resources/org/apache/jackrabbit/oak/fixture/repository.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/resources/org/apache/jackrabbit/oak/fixture/repository.xml?rev=1503739&r1=1503738&r2=1503739&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/resources/org/apache/jackrabbit/oak/fixture/repository.xml
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/resources/org/apache/jackrabbit/oak/fixture/repository.xml
Tue Jul 16 14:51:04 2013
@@ -109,6 +109,17 @@
<param name="path" value="${wsp.home}/index"/>
<param name="supportHighlighting" value="true"/>
</SearchIndex>
+
+ <!--
+ XML Import configuration of the workspace
+ -->
+ <Import>
+ <ProtectedItemImporter
class="org.apache.jackrabbit.core.xml.AccessControlImporter">
+ </ProtectedItemImporter>
+ <ProtectedItemImporter
class="org.apache.jackrabbit.core.security.user.UserImporter">
+ <param name="importBehavior" value="besteffort"/>
+ </ProtectedItemImporter>
+ </Import>
</Workspace>
<!--