Author: mreutegg
Date: Tue Apr 12 13:30:42 2016
New Revision: 1738802

URL: http://svn.apache.org/viewvc?rev=1738802&view=rev
Log:
OAK-4191: Speed up LargeLdapProviderTest

Replace LdifPartition with in-memory AvlPartition and use a single call to add 
multiple group members.

Modified:
    
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java
    
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java
    
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java

Modified: 
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java?rev=1738802&r1=1738801&r2=1738802&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/AbstractServer.java
 Tue Apr 12 13:30:42 2016
@@ -55,7 +55,7 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.api.InstanceLayout;
 import org.apache.directory.server.core.api.schema.SchemaPartition;
 import org.apache.directory.server.core.jndi.CoreContextFactory;
-import org.apache.directory.server.core.partition.ldif.LdifPartition;
+import org.apache.directory.server.core.partition.impl.avl.AvlPartition;
 import org.apache.directory.server.core.shared.DefaultDnFactory;
 import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.server.ldap.handlers.extended.StartTlsHandler;
@@ -199,24 +199,21 @@ public abstract class AbstractServer {
         directoryService.setSchemaManager(schemaManager);
         directoryService.setDnFactory(new 
DefaultDnFactory(directoryService.getSchemaManager(), 
cache.getCache("dnCache")));
 
-        LdifPartition schLdifPart = new 
LdifPartition(directoryService.getSchemaManager(), 
directoryService.getDnFactory());
+        AvlPartition schLdifPart = new 
AvlPartition(directoryService.getSchemaManager(), 
directoryService.getDnFactory());
         schLdifPart.setId("schema");
-        schLdifPart.setPartitionPath(new 
File(directoryService.getInstanceLayout().getPartitionsDirectory(), 
"schema").toURI());
         
schLdifPart.setSuffixDn(directoryService.getDnFactory().create(ServerDNConstants.CN_SCHEMA_DN));
         SchemaPartition schPart = new 
SchemaPartition(directoryService.getSchemaManager());
         schPart.setWrappedPartition(schLdifPart);
         directoryService.setSchemaPartition(schPart);
 
 
-        LdifPartition sysPart = new 
LdifPartition(directoryService.getSchemaManager(), 
directoryService.getDnFactory());
+        AvlPartition sysPart = new 
AvlPartition(directoryService.getSchemaManager(), 
directoryService.getDnFactory());
         sysPart.setId(SystemSchemaConstants.SCHEMA_NAME);
-        sysPart.setPartitionPath(new 
File(directoryService.getInstanceLayout().getPartitionsDirectory(), 
SystemSchemaConstants.SCHEMA_NAME).toURI());
         
sysPart.setSuffixDn(directoryService.getDnFactory().create(ServerDNConstants.SYSTEM_DN));
         directoryService.setSystemPartition(sysPart);
 
-        LdifPartition examplePart = new 
LdifPartition(directoryService.getSchemaManager(), 
directoryService.getDnFactory());
+        AvlPartition examplePart = new 
AvlPartition(directoryService.getSchemaManager(), 
directoryService.getDnFactory());
         examplePart.setId("example");
-        examplePart.setPartitionPath(new 
File(directoryService.getInstanceLayout().getPartitionsDirectory(), 
"example").toURI());
         
examplePart.setSuffixDn(directoryService.getDnFactory().create(EXAMPLE_DN));
         examplePart.setCacheService(cache);
         directoryService.addPartition(examplePart);

Modified: 
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java?rev=1738802&r1=1738801&r2=1738802&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/InternalLdapServer.java
 Tue Apr 12 13:30:42 2016
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.security.authentication.ldap;
 
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 import javax.naming.ldap.LdapContext;
@@ -76,6 +78,17 @@ class InternalLdapServer extends Abstrac
         ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs);
     }
 
+    public void addMembers(String groupDN, Iterable<String> memberDNs) throws 
Exception {
+        LdapContext ctxt = getWiredContext();
+        Attribute attr = new BasicAttribute("member");
+        for (String dn : memberDNs) {
+            attr.add(dn);
+        }
+        BasicAttributes attrs = new BasicAttributes();
+        attrs.put(attr);
+        ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs);
+    }
+
     public void removeMember(String groupDN, String memberDN) throws Exception 
{
         LdapContext ctxt = getWiredContext();
         BasicAttributes attrs = new BasicAttributes();

Modified: 
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java?rev=1738802&r1=1738801&r2=1738802&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-auth-ldap/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LargeLdapProviderTest.java
 Tue Apr 12 13:30:42 2016
@@ -135,12 +135,14 @@ public class LargeLdapProviderTest {
         GROUP_DN = server.addGroup(GROUP_NAME, USER_DN);
         members.add(USER_DN);
 
+        List<String> userDNs = new ArrayList<String>();
         for (int i = 0; i < NUM_USERS; i++) {
             final String userId = "user-" + i;
             String userDN = server.addUser(userId, "test", userId, "test");
-            LDAP_SERVER.addMember(GROUP_DN, userDN);
+            userDNs.add(userDN);
             members.add(userDN);
         }
+        LDAP_SERVER.addMembers(GROUP_DN, userDNs);
         TEST_MEMBERS = members.toArray(new String[members.size()]);
     }
 


Reply via email to