felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chet...@apache.org
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 GMT
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<String, ConfigSpiOsgi.Realm> 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<ServiceReference> references;
+        private final ConfigSpiOsgi spi;
+        volatile String realmName;
+        private int runCount;
+
+        ConfigModifier(CountDownLatch latch, Queue<ServiceReference> 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<String, Object> dict = new Hashtable<String, Object>();
+                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<String, Object> props = new HashMap<String, Object>();
         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<Object>()



Mime
View raw message