### Eclipse Workspace Patch 1.0 #P oak-run Index: src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java =================================================================== --- src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java (revision 1502156) +++ src/main/java/org/apache/jackrabbit/oak/benchmark/AbstractTest.java (working copy) @@ -239,6 +239,25 @@ throw new RuntimeException(e); } } + + /** + * Returns a new session for the given user + * that will be automatically closed once + * all the iterations of this test have been executed. + * + * @param credentials the user credentials + * @return user session + */ + protected Session login(Credentials credentials) { + try { + Session session = repository.login(credentials); + sessions.add(session); + return session; + } catch (RepositoryException e) { + throw new RuntimeException(e); + } + } + /** * Returns a new writer session that will be automatically closed once Index: src/main/java/org/apache/jackrabbit/oak/benchmark/TestManyACLs.java =================================================================== --- src/main/java/org/apache/jackrabbit/oak/benchmark/TestManyACLs.java (revision 0) +++ src/main/java/org/apache/jackrabbit/oak/benchmark/TestManyACLs.java (revision 0) @@ -0,0 +1,100 @@ +/* + * 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.security.Principal; + +import javax.jcr.Node; +import javax.jcr.Session; +import javax.jcr.SimpleCredentials; +import javax.jcr.security.AccessControlManager; +import org.apache.jackrabbit.api.JackrabbitSession; +import org.apache.jackrabbit.api.security.user.User; +import org.apache.jackrabbit.api.security.user.UserManager; +import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; +import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils; +import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants; +import org.h2.util.Profiler; + +public class TestManyACLs extends AbstractTest { + + private Session reader; + private String userId = "test"; + private Principal userPrincipal; + Profiler profiler = new Profiler(); + + Session writer; + + @Override + protected void beforeSuite() throws Exception { + + long start = System.currentTimeMillis(); + writer = loginWriter(); + + UserManager userManager = ((JackrabbitSession) writer).getUserManager(); + User user = userManager.createUser(userId, userId); + userPrincipal = user.getPrincipal(); + AccessControlManager acm = writer.getAccessControlManager(); + + + JackrabbitAccessControlList acl = AccessControlUtils + .getAccessControlList(acm, "/"); + acl.addEntry(userPrincipal, AccessControlUtils.privilegesFromNames(acm, + PrivilegeConstants.JCR_READ), true); + acl.addEntry(userPrincipal, AccessControlUtils.privilegesFromNames(acm, + PrivilegeConstants.JCR_READ_ACCESS_CONTROL), true); + acm.setPolicy("/", acl); + + Node a = writer.getRootNode().addNode("a"); + for (int i = 1; i < 10000; i++) { + + a.addNode("node" + i); + JackrabbitAccessControlList acl2 = AccessControlUtils + .getAccessControlList(acm, "/a/node"+i); + acl2.addEntry(userPrincipal, AccessControlUtils.privilegesFromNames(acm, + PrivilegeConstants.JCR_READ), true); + acm.setPolicy("/a/node"+i, acl2); + } + + writer.save(); + reader = login(new SimpleCredentials(userId, userId.toCharArray())); + + profiler.startCollecting(); + + long end = System.currentTimeMillis(); + System.out.println("time "+(end - start)); + + } + + @Override + protected void runTest() throws Exception { + + Node n = reader.getNode("/a"); + for (int i = 1; i < 10000; i++) { + n.getNode("node" + i); + } + } + + protected void afterTest() throws Exception { + + } + + protected void afterSuite() throws Exception { + + } + +}