Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A41E9200C17 for ; Fri, 10 Feb 2017 19:45:39 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id A269F160B5C; Fri, 10 Feb 2017 18:45:39 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C7C21160B4E for ; Fri, 10 Feb 2017 19:45:38 +0100 (CET) Received: (qmail 74005 invoked by uid 500); 10 Feb 2017 18:45:37 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 73996 invoked by uid 99); 10 Feb 2017 18:45:37 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Feb 2017 18:45:37 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 34F083A20C3 for ; Fri, 10 Feb 2017 18:45:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1782497 - in /felix/trunk/jaas/src: main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java Date: Fri, 10 Feb 2017 18:45:37 -0000 To: commits@felix.apache.org From: chetanm@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170210184537.34F083A20C3@svn01-us-west.apache.org> archived-at: Fri, 10 Feb 2017 18:45:39 -0000 Author: chetanm Date: Fri Feb 10 18:45:36 2017 New Revision: 1782497 URL: http://svn.apache.org/viewvc?rev=1782497&view=rev Log: FELIX-5536 - ConfigSpiOSGi may end with incomplete realm due to race conditions Adding ignored test which sometimes fail in multiple runs Modified: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java felix/trunk/jaas/src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java Modified: felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java?rev=1782497&r1=1782496&r2=1782497&view=diff ============================================================================== --- felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java (original) +++ felix/trunk/jaas/src/main/java/org/apache/felix/jaas/internal/ConfigSpiOsgi.java Fri Feb 10 18:45:36 2017 @@ -78,7 +78,7 @@ public class ConfigSpiOsgi extends Confi * * In case it does not find any config it looks for config entry for an app named 'other' */ - private static final String DEFAULT_REALM_NAME = "other"; + static final String DEFAULT_REALM_NAME = "other"; @Property private static final String JAAS_DEFAULT_REALM_NAME = "jaas.defaultRealmName"; Modified: felix/trunk/jaas/src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java URL: http://svn.apache.org/viewvc/felix/trunk/jaas/src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java?rev=1782497&r1=1782496&r2=1782497&view=diff ============================================================================== --- felix/trunk/jaas/src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java (original) +++ felix/trunk/jaas/src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java Fri Feb 10 18:45:36 2017 @@ -20,6 +20,7 @@ package org.apache.felix.jaas.internal; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -28,7 +29,9 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Arrays; +import java.util.Dictionary; import java.util.HashMap; +import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Queue; @@ -39,6 +42,7 @@ import javax.security.auth.login.Configu import org.apache.felix.jaas.LoginModuleFactory; import org.apache.sling.testing.mock.osgi.junit.OsgiContext; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,11 +51,13 @@ import org.mockito.invocation.Invocation import org.mockito.stubbing.Answer; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.ConfigurationException; +@Ignore("FELIX-5536") @RunWith(Parameterized.class) public class ITConcurrentLoginModuleFactoryTest { - private static final String TEST_REALM_NAME = "FELIX"; + private static final String TEST_REALM_NAME = ConfigSpiOsgi.DEFAULT_REALM_NAME; @Rule public OsgiContext context = new OsgiContext(); @@ -89,6 +95,11 @@ public class ITConcurrentLoginModuleFact t.start(); } + ConfigModifier cm = new ConfigModifier(latch, references, spi); + Thread cmt = new Thread(cm); + threads.add(cmt); + cmt.start(); + latch.countDown(); for (Thread t : threads) @@ -96,8 +107,12 @@ public class ITConcurrentLoginModuleFact t.join(); } - assertEquals(numOfServices, - spi.engineGetAppConfigurationEntry(TEST_REALM_NAME).length); + Map configs = spi.getAllConfiguration(); + assertFalse(configs.isEmpty()); + for (ConfigSpiOsgi.Realm r : configs.values()) + { + assertEquals(numOfServices, r.engineGetAppConfigurationEntry().length); + } assertEquals(1, context.getServices(ConfigurationSpi.class, null).length); } @@ -136,11 +151,53 @@ public class ITConcurrentLoginModuleFact } } + private static class ConfigModifier implements Runnable + { + private final CountDownLatch latch; + private final Queue references; + private final ConfigSpiOsgi spi; + volatile String realmName; + private int runCount; + + ConfigModifier(CountDownLatch latch, Queue references, ConfigSpiOsgi spi) + { + this.latch = latch; + this.references = references; + this.spi = spi; + } + + @Override + public void run() + { + try + { + latch.await(); + } + catch (InterruptedException ignore) + { + return; + } + while (!references.isEmpty()) + { + Dictionary dict = new Hashtable(); + realmName = TEST_REALM_NAME + runCount++; + dict.put("jaas.defaultRealmName", realmName); + try + { + spi.updated(dict); + } catch (ConfigurationException e) + { + e.printStackTrace(); + } + } + } + } + + private static ServiceReference newReference() { final Map props = new HashMap(); props.put(LoginModuleFactory.JAAS_CONTROL_FLAG, "REQUIRED"); - props.put(LoginModuleFactory.JAAS_REALM_NAME, TEST_REALM_NAME); ServiceReference sr = mock(ServiceReference.class); when(sr.getProperty(any(String.class))).thenAnswer(new Answer()