activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1349713 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/security/ test/java/org/apache/activemq/security/ test/resources/org/apache/activemq/security/
Date Wed, 13 Jun 2012 09:53:14 GMT
Author: dejanb
Date: Wed Jun 13 09:53:13 2012
New Revision: 1349713

URL: http://svn.apache.org/viewvc?rev=1349713&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3845 - make test (and map) work better on slow machines

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/CachedLDAPAuthorizationMap.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/AbstractCachedLDAPAuthorizationMapLegacyTest.java
  (contents, props changed)
    activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/activemq-apacheds.ldif

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/CachedLDAPAuthorizationMap.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/CachedLDAPAuthorizationMap.java?rev=1349713&r1=1349712&r2=1349713&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/CachedLDAPAuthorizationMap.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/security/CachedLDAPAuthorizationMap.java
Wed Jun 13 09:53:13 2012
@@ -88,7 +88,7 @@ public class CachedLDAPAuthorizationMap 
 
     private static String ANY_DESCENDANT = "\\$";
 
-    private DirContext context;
+    protected DirContext context;
     private EventDirContext eventContext;
     
     protected HashMap<ActiveMQDestination, AuthorizationEntry> entries = 
@@ -106,10 +106,20 @@ public class CachedLDAPAuthorizationMap 
         env.put(Context.SECURITY_PROTOCOL, connectionProtocol);
         env.put(Context.PROVIDER_URL, connectionURL);
         env.put(Context.SECURITY_AUTHENTICATION, authentication);
-        //env.put("com.sun.jndi.ldap.connect.pool", "true");
         return new InitialDirContext(env);
     }
 
+    protected boolean isContextAlive() {
+        boolean alive = false;
+        if (context != null) {
+            try {
+                context.getAttributes("");
+                alive = true;
+            } catch (Exception e) {}
+        }
+        return alive;
+    }
+
     /**
      * Returns the existing open context or creates a new one and registers listeners for
      * push notifications if such an update style is enabled.  This implementation should
not
@@ -120,17 +130,8 @@ public class CachedLDAPAuthorizationMap 
      * @throws NamingException if there is an error setting things up
      */
     protected DirContext open() throws NamingException {
-        if (context != null) {
-            boolean alive = true;
-            try {
-                context.getAttributes("");
-            } catch (Exception e) {
-               LOG.info("LDAP connection failed", e);
-               alive = false;
-            }
-            if (alive) {
-                return context;
-            }
+        if (isContextAlive()) {
+            return context;
         }
 
         try {
@@ -631,7 +632,7 @@ public class CachedLDAPAuthorizationMap 
      */
     protected void checkForUpdates() {
         if (context == null || (!refreshDisabled && (refreshInterval != -1 &&
System.currentTimeMillis() >= lastUpdated + refreshInterval))) {
-            if (context == null) {
+            if (!isContextAlive()) {
                 try {
                     context = createContext();
                 } catch (NamingException ne) {

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/AbstractCachedLDAPAuthorizationMapLegacyTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/AbstractCachedLDAPAuthorizationMapLegacyTest.java?rev=1349713&r1=1349712&r2=1349713&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/AbstractCachedLDAPAuthorizationMapLegacyTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/AbstractCachedLDAPAuthorizationMapLegacyTest.java
Wed Jun 13 09:53:13 2012
@@ -19,6 +19,7 @@ package org.apache.activemq.security;
 import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.activemq.command.ActiveMQTopic;
 import org.apache.activemq.jaas.GroupPrincipal;
+import org.apache.activemq.util.Wait;
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.shared.ldap.model.ldif.LdifEntry;
@@ -300,16 +301,20 @@ public abstract class AbstractCachedLDAP
 
         getLdapServer().stop();
 
-        Thread.sleep(1000);
+        // wait for the context to be closed
+        // as we can't rely on ldar server isStarted()
+        Wait.waitFor(new Wait.Condition() {
+            public boolean isSatisified() throws Exception {
+                return map.context == null;
+            }
+        });
 
-        if (!sync) {
-            failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
-            assertEquals("set size: " + failedACLs, 2, failedACLs.size());
-        }
+        failedACLs = map.getReadACLs(new ActiveMQQueue("TEST.FOO"));
+        assertEquals("set size: " + failedACLs, 2, failedACLs.size());
 
         getLdapServer().start();
 
-        Thread.sleep(1000);
+        Thread.sleep(2000);
 
         connection = getLdapConnection();
 

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/security/AbstractCachedLDAPAuthorizationMapLegacyTest.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/activemq-apacheds.ldif
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/activemq-apacheds.ldif?rev=1349713&r1=1349712&r2=1349713&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/activemq-apacheds.ldif
(original)
+++ activemq/trunk/activemq-core/src/test/resources/org/apache/activemq/security/activemq-apacheds.ldif
Wed Jun 13 09:53:13 2012
@@ -161,7 +161,6 @@ cn: read
 member: cn=users,ou=Group,ou=ActiveMQ,ou=system
 member: cn=admins,ou=Group,ou=ActiveMQ,ou=system
 member: uid=jdoe,ou=User,ou=ActiveMQ,ou=system
-member: cn=notthere,ou=Group,ou=ActiveMQ,ou=system
 objectClass: groupOfNames
 objectClass: top
 



Mime
View raw message