Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D06FF920C for ; Wed, 13 Jun 2012 09:53:55 +0000 (UTC) Received: (qmail 34473 invoked by uid 500); 13 Jun 2012 09:53:54 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 34359 invoked by uid 500); 13 Jun 2012 09:53:52 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 34332 invoked by uid 99); 13 Jun 2012 09:53:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jun 2012 09:53:51 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Jun 2012 09:53:48 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 564AB238890B for ; Wed, 13 Jun 2012 09:53:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@activemq.apache.org From: dejanb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120613095314.564AB238890B@eris.apache.org> 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 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