jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1532341 - /jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/
Date Tue, 15 Oct 2013 14:00:42 GMT
Author: angela
Date: Tue Oct 15 14:00:42 2013
New Revision: 1532341

URL: http://svn.apache.org/r1532341
Log:
OAK-527: more benchmark tests

Added:
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadSinglePolicyTreeTest.java
Modified:
    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/ConcurrentReadAccessControlledTreeTest.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest2.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

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=1532341&r1=1532340&r2=1532341&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 Oct 15 14:00:42 2013
@@ -120,6 +120,11 @@ public class BenchmarkRunner {
                     itemsToRead.value(options),
                     bgReaders.value(options),
                     report.value(options)),
+            new ConcurrentReadSinglePolicyTreeTest(
+                    runAsAdmin.value(options),
+                    itemsToRead.value(options),
+                    bgReaders.value(options),
+                    report.value(options)),
             new ConcurrentReadAccessControlledTreeTest(
                     runAsAdmin.value(options),
                     itemsToRead.value(options),

Modified: 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=1532341&r1=1532340&r2=1532341&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest.java
Tue Oct 15 14:00:42 2013
@@ -16,16 +16,13 @@
  */
 package org.apache.jackrabbit.oak.benchmark;
 
-import javax.jcr.ItemVisitor;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
-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.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
 import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
 import org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants;
 import org.apache.jackrabbit.util.Text;
@@ -34,8 +31,9 @@ import org.apache.jackrabbit.util.Text;
  * Concurrently reads random items from the deep tree where every 10th node is
  * access controlled.
  */
-public class ConcurrentReadAccessControlledTreeTest
-        extends ConcurrentReadDeepTreeTest {
+public class ConcurrentReadAccessControlledTreeTest extends ConcurrentReadDeepTreeTest {
+
+    int counter = 0;
 
     public ConcurrentReadAccessControlledTreeTest(
             boolean runAsAdmin, int itemsToRead, int bgReaders, boolean doReport) {
@@ -43,53 +41,39 @@ public class ConcurrentReadAccessControl
     }
 
     @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);
-            }
+    protected void visitingNode(Node node, int i) throws RepositoryException {
+        if (++counter == 10) {
+            addPolicy(node);
+            counter = 0;
+        }
+        super.visitingNode(node, i);
+    }
 
-            private void addPolicy(Node node) throws RepositoryException {
-                AccessControlManager acMgr = node.getSession().getAccessControlManager();
-                String path = node.getPath();
-                int level = 0;
-                if (node.isNodeType(AccessControlConstants.NT_REP_POLICY)) {
-                    level = 1;
-                } else if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
-                    level = 2;
-                } else if (node.isNodeType(AccessControlConstants.NT_REP_RESTRICTIONS)) {
-                    level = 3;
-                }
-                if (level > 0) {
-                    path = Text.getRelativeParent(path, level);
-                }
-                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();
-                        }
-                    }
-                }
+    private void addPolicy(Node node) throws RepositoryException {
+        AccessControlManager acMgr = node.getSession().getAccessControlManager();
+        String path = node.getPath();
+        int level = 0;
+        if (node.isNodeType(AccessControlConstants.NT_REP_POLICY)) {
+            level = 1;
+        } else if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
+            level = 2;
+        } else if (node.isNodeType(AccessControlConstants.NT_REP_RESTRICTIONS)) {
+            level = 3;
+        }
+        if (level > 0) {
+            path = Text.getRelativeParent(path, level);
+        }
+        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(node.getSession(),
path);
+        if (acl != null) {
+            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);
+        }
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest2.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest2.java?rev=1532341&r1=1532340&r2=1532341&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest2.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadAccessControlledTreeTest2.java
Tue Oct 15 14:00:42 2013
@@ -19,19 +19,16 @@ package org.apache.jackrabbit.oak.benchm
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.List;
-import javax.jcr.ItemVisitor;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
-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.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
 import org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants;
 import org.apache.jackrabbit.util.Text;
 
@@ -42,17 +39,15 @@ import org.apache.jackrabbit.util.Text;
  */
 public class ConcurrentReadAccessControlledTreeTest2 extends ConcurrentReadDeepTreeTest {
 
-    List<Principal> principals = new ArrayList();
+    int counter = 0;
+    final List<Principal> principals = new ArrayList();
 
-    public ConcurrentReadAccessControlledTreeTest2(
-            boolean runAsAdmin, int itemsToRead, int bgReaders, boolean doReport) {
+    public ConcurrentReadAccessControlledTreeTest2(boolean runAsAdmin, int itemsToRead, int
bgReaders, boolean doReport) {
         super(runAsAdmin, itemsToRead, bgReaders, doReport);
     }
 
     @Override
-    protected void beforeSuite() throws Exception {
-        super.beforeSuite();
-
+    protected void createDeepTree() throws Exception {
         UserManager uMgr = ((JackrabbitSession) adminSession).getUserManager();
         for (int i = 0; i < 100; i++) {
             Authorizable a = uMgr.getAuthorizable("group" + i);
@@ -61,52 +56,43 @@ public class ConcurrentReadAccessControl
                 principals.add(a.getPrincipal());
             }
         }
+        super.createDeepTree();
+    }
 
-        ItemVisitor visitor = new TraversingItemVisitor.Default() {
-            int counter = 0;
-            @Override
-            protected void entering(Node node, int level) throws RepositoryException {
-                if (++counter == 100) {
-                    addPolicy(node);
-                    counter = 0;
-                }
-                super.entering(node, level);
-            }
+    @Override
+    protected void visitingNode(Node node, int i) throws RepositoryException {
+        if (++counter == 100) {
+            addPolicy(node);
+            counter = 0;
+        }
+        super.visitingNode(node, i);
+    }
 
-            private void addPolicy(Node node) throws RepositoryException {
-                AccessControlManager acMgr = node.getSession().getAccessControlManager();
-                String path = node.getPath();
-                int level = 0;
-                if (node.isNodeType(AccessControlConstants.NT_REP_POLICY)) {
-                    level = 1;
-                } else if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
-                    level = 2;
-                } else if (node.isNodeType(AccessControlConstants.NT_REP_RESTRICTIONS)) {
-                    level = 3;
-                }
-                if (level > 0) {
-                    path = Text.getRelativeParent(path, level);
-                }
-                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)
-                        };
-                        for (Principal principal : principals) {
-                            acl.addAccessControlEntry(principal, privileges);
-                        }
-                        acMgr.setPolicy(path, acl);
-                        adminSession.save();
-                    }
-                }
+    private void addPolicy(Node node) throws RepositoryException {
+        AccessControlManager acMgr = node.getSession().getAccessControlManager();
+        String path = node.getPath();
+        int level = 0;
+        if (node.isNodeType(AccessControlConstants.NT_REP_POLICY)) {
+            level = 1;
+        } else if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
+            level = 2;
+        } else if (node.isNodeType(AccessControlConstants.NT_REP_RESTRICTIONS)) {
+            level = 3;
+        }
+        if (level > 0) {
+            path = Text.getRelativeParent(path, level);
+        }
+        JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(node.getSession(),
path);
+        if (acl != null) {
+            Privilege[] privileges = new Privilege[] {
+                    acMgr.privilegeFromName(Privilege.JCR_READ),
+                    acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL)
+            };
+            for (Principal principal : principals) {
+                acl.addAccessControlEntry(principal, privileges);
             }
-        };
-
-        visitor.visit(testRoot);
+            acMgr.setPolicy(path, acl);
+            adminSession.save();
+        }
     }
-
 }

Modified: 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=1532341&r1=1532340&r2=1532341&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadDeepTreeTest.java
Tue Oct 15 14:00:42 2013
@@ -21,8 +21,7 @@ package org.apache.jackrabbit.oak.benchm
  */
 public class ConcurrentReadDeepTreeTest extends ReadDeepTreeTest {
 
-    public ConcurrentReadDeepTreeTest(
-            boolean runAsAdmin, int itemsToRead, int bgReaders, boolean doReport) {
+    public ConcurrentReadDeepTreeTest(boolean runAsAdmin, int itemsToRead, int bgReaders,
boolean doReport) {
         super(runAsAdmin, itemsToRead, bgReaders, doReport);
     }
 

Added: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadSinglePolicyTreeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadSinglePolicyTreeTest.java?rev=1532341&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadSinglePolicyTreeTest.java
(added)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ConcurrentReadSinglePolicyTreeTest.java
Tue Oct 15 14:00:42 2013
@@ -0,0 +1,60 @@
+/*
+ * 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.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.security.AccessControlManager;
+import javax.jcr.security.AccessControlPolicy;
+import javax.jcr.security.Privilege;
+
+import org.apache.jackrabbit.api.security.JackrabbitAccessControlList;
+import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
+import org.apache.jackrabbit.core.security.principal.EveryonePrincipal;
+
+/**
+ * Concurrently reads random items from the deep tree where only the root node is
+ * access controlled.
+ */
+public class ConcurrentReadSinglePolicyTreeTest extends ConcurrentReadDeepTreeTest {
+
+    public ConcurrentReadSinglePolicyTreeTest(
+            boolean runAsAdmin, int itemsToRead, int bgReaders, boolean doReport) {
+        super(runAsAdmin, itemsToRead, bgReaders, doReport);
+    }
+
+    @Override
+    protected void visitingNode(Node node, int i) throws RepositoryException {
+        String path = node.getPath();
+        AccessControlManager acMgr = node.getSession().getAccessControlManager();
+        if ("/".equals(path)) {
+            JackrabbitAccessControlList policy = AccessControlUtils.getAccessControlList(acMgr,
path);
+            if (policy != null) {
+                policy.addEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acMgr,
Privilege.JCR_READ), true);
+            }
+            acMgr.setPolicy(path, policy);
+        } else {
+            for (AccessControlPolicy policy : acMgr.getPolicies(path)) {
+                if (policy instanceof JackrabbitAccessControlList) {
+                    acMgr.removePolicy(path, policy);
+                }
+            }
+        }
+        node.getSession().save();
+        super.visitingNode(node, i);
+    }
+}

Modified: 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=1532341&r1=1532340&r2=1532341&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java
(original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/benchmark/ReadDeepTreeTest.java
Tue Oct 15 14:00:42 2013
@@ -44,71 +44,80 @@ public class ReadDeepTreeTest extends Ab
 
     private Session testSession;
 
-    protected List<String> allPaths;
+    protected List<String> allPaths = new ArrayList();
 
-    protected ReadDeepTreeTest(
-            boolean runAsAdmin, int itemsToRead, int bgReaders, boolean doReport) {
+    protected ReadDeepTreeTest(boolean runAsAdmin, int itemsToRead, int bgReaders, boolean
doReport) {
         this.runAsAdmin = runAsAdmin;
         this.itemsToRead = itemsToRead;
         this.bgReaders = bgReaders;
         this.doReport = doReport;
     }
 
-    public ReadDeepTreeTest(
-            boolean runAsAdmin, int itemsToRead, boolean doReport) {
+    public ReadDeepTreeTest(boolean runAsAdmin, int itemsToRead, boolean doReport) {
         this(runAsAdmin, itemsToRead, 0, doReport);
     }
 
     @Override
     protected void beforeSuite() throws Exception {
         adminSession = loginWriter();
-        String name = getClass().getSimpleName() + TEST_ID;
+
+        createDeepTree();
+
+        for (int i = 0; i < bgReaders; i++) {
+            final Session session = getTestSession();
+            addBackgroundJob(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        randomRead(session, allPaths, itemsToRead);
+                    } catch (RepositoryException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+            });
+        }
+        System.out.println("Threads started: " + bgReaders);
+
+        testSession = getTestSession();
+    }
+
+    protected void createDeepTree() throws Exception {
         Node rn = adminSession.getRootNode();
 
+        String testNodeName = getClass().getSimpleName() + TEST_ID;
         long start = System.currentTimeMillis();
-        if (!rn.hasNode(name)) {
-            testRoot = adminSession.getRootNode().addNode(name, "nt:unstructured");
+        if (!rn.hasNode(testNodeName)) {
+            testRoot = adminSession.getRootNode().addNode(testNodeName, "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);
+            testRoot = rn.getNode(testNodeName);
         }
         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());
+                visitingNode(node, i);
                 super.entering(node, i);
             }
             @Override
             protected void entering(Property prop, int i) throws RepositoryException {
-                paths.add(prop.getPath());
+                visitingProperty(prop, i);
                 super.entering(prop, i);
             }
         };
         v.visit(testRoot);
-        allPaths = paths;
-
         System.out.println("All paths: " + allPaths.size());
+    }
 
-        for (int i = 0; i < bgReaders; i++) {
-            final Session session = getTestSession();
-            addBackgroundJob(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        randomRead(session, allPaths, itemsToRead);
-                    } catch (RepositoryException e) {
-                        throw new RuntimeException(e);
-                    }
-                }
-            });
-        }
+    protected void visitingNode(Node node, int i) throws RepositoryException {
+        allPaths.add(node.getPath());
+    }
 
-        testSession = getTestSession();
+    protected void visitingProperty(Property property, int i) throws RepositoryException
{
+        allPaths.add(property.getPath());
     }
 
     @Override



Mime
View raw message