You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ba...@apache.org on 2013/05/08 16:19:48 UTC

svn commit: r1480287 - /jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java

Author: baedke
Date: Wed May  8 14:19:48 2013
New Revision: 1480287

URL: http://svn.apache.org/r1480287
Log:
OAK-516: added tests for concurrent LDAP login. Currently ignored because concurrent sync fails.

Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java?rev=1480287&r1=1480286&r2=1480287&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/authentication/ldap/LdapLoginTestBase.java Wed May  8 14:19:48 2013
@@ -16,7 +16,11 @@
  */
 package org.apache.jackrabbit.oak.security.authentication.ldap;
 
+import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
+import javax.jcr.RepositoryException;
 import javax.jcr.SimpleCredentials;
 import javax.security.auth.login.AppConfigurationEntry;
 import javax.security.auth.login.Configuration;
@@ -34,6 +38,7 @@ import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertNotNull;
@@ -56,8 +61,10 @@ public abstract class LdapLoginTestBase 
 
     protected static String GROUP_DN;
 
+    protected static int CONCURRENT_LOGINS = 10;
+
     //initialize LDAP server only once (fast, but might turn out to be not sufficiently flexible in the future)
-    protected static final boolean USE_COMMON_LDAP_FIXTURE = true;
+    protected static final boolean USE_COMMON_LDAP_FIXTURE = false;
 
     protected final HashMap<String, Object> options = new HashMap<String, Object>();
 
@@ -355,6 +362,60 @@ public abstract class LdapLoginTestBase 
         }
     }
 
+    @Ignore
+    @Test
+    public void testConcurrentLogin() throws Exception {
+
+        concurrentLogin(false);
+    }
+
+    @Ignore
+    @Test
+    public void testConcurrentLoginSameGroup() throws Exception {
+
+        concurrentLogin(true);
+    }
+
+    private void concurrentLogin(boolean sameGroup) throws Exception {
+
+        if (!USE_COMMON_LDAP_FIXTURE) {
+            createLdapFixture();
+        }
+
+        final List<Exception> exceptions = new ArrayList<Exception>();
+        List<Thread> workers = new ArrayList<Thread>();
+        for (int i = 0; i < CONCURRENT_LOGINS; i++) {
+            final String userId = "user-" + i;
+            final String pass = "secret";
+            String userDN = LDAP_SERVER.addUser(userId, "test", userId, pass);
+            if (sameGroup) {
+                LDAP_SERVER.addMember(GROUP_DN, userDN);
+            }
+            workers.add(new Thread(new Runnable() {
+                public void run() {
+                    try {
+                        login(new SimpleCredentials(
+                                userId, pass.toCharArray())).close();
+                    } catch (Exception e) {
+                        exceptions.add(e);
+                    }
+                }
+            }));
+        }
+        for (Thread t : workers) {
+            t.start();
+        }
+        for (Thread t : workers) {
+            t.join();
+        }
+        for (Exception e : exceptions) {
+            e.printStackTrace();
+        }
+        if (!exceptions.isEmpty()) {
+            throw exceptions.get(0);
+        }
+    }
+
     protected static void createLdapFixture() throws Exception {
         LDAP_SERVER.addMember(
                 GROUP_DN = LDAP_SERVER.addGroup(GROUP_NAME),