You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ch...@apache.org on 2017/01/20 09:37:51 UTC

svn commit: r1779592 - in /felix/trunk/jaas: pom.xml src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java

Author: chetanm
Date: Fri Jan 20 09:37:51 2017
New Revision: 1779592

URL: http://svn.apache.org/viewvc?rev=1779592&view=rev
Log:
FELIX-5505 - ConfigSpiOSGi may miss out on registering some LoginModuleFactory due to race condition

Adding ignored testcase

Added:
    felix/trunk/jaas/src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java   (with props)
Modified:
    felix/trunk/jaas/pom.xml

Modified: felix/trunk/jaas/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/jaas/pom.xml?rev=1779592&r1=1779591&r2=1779592&view=diff
==============================================================================
--- felix/trunk/jaas/pom.xml (original)
+++ felix/trunk/jaas/pom.xml Fri Jan 20 09:37:51 2017
@@ -240,9 +240,16 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
+      <version>4.12</version>
       <scope>test</scope>
-      <version>4.10</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.sling</groupId>
+      <artifactId>org.apache.sling.testing.osgi-mock</artifactId>
+      <version>2.1.0</version>
+      <scope>test</scope>
+    </dependency>
+
     <!-- Pax Exam Dependencies -->
     <dependency>
       <groupId>org.ops4j.pax.exam</groupId>
@@ -292,6 +299,11 @@
       <version>2.2.0</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-all</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <profiles>

Added: 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=1779592&view=auto
==============================================================================
--- felix/trunk/jaas/src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java (added)
+++ felix/trunk/jaas/src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java Fri Jan 20 09:37:51 2017
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.felix.jaas.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.CountDownLatch;
+
+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;
+import org.junit.runners.Parameterized;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+@Ignore("FELIX-5502")
+@RunWith(Parameterized.class)
+public class ITConcurrentLoginModuleFactoryTest
+{
+    private static final String TEST_REALM_NAME = "FELIX";
+    @Rule
+    public OsgiContext context = new OsgiContext();
+
+    @Parameterized.Parameters
+    public static List<Object[]> data()
+    {
+        return Arrays.asList(new Object[25][0]);
+    }
+
+    @Test
+    public void concurrentLoginFactoryRegs() throws Exception
+    {
+        Logger log = new Logger(context.bundleContext());
+
+        BundleContext mock = spy(context.bundleContext());
+        doReturn(mock(LoginModuleFactory.class)).when(mock).getService(
+            any(ServiceReference.class));
+
+        ConfigSpiOsgi spi = new ConfigSpiOsgi(mock, log);
+
+        int numOfServices = 20;
+        Queue<ServiceReference> references = new ArrayBlockingQueue<ServiceReference>(numOfServices);
+        for (int i = 0; i < numOfServices; i++)
+        {
+            references.add(newReference());
+        }
+
+        CountDownLatch latch = new CountDownLatch(1);
+        List<Thread> threads = new ArrayList<Thread>();
+        for (int i = 0; i < 3; i++)
+        {
+            Thread t = new Thread(new ServiceAdder(latch, references, spi));
+            threads.add(t);
+            t.start();
+        }
+
+        latch.countDown();
+
+        for (Thread t : threads)
+        {
+            t.join();
+        }
+
+        assertEquals(numOfServices,
+            spi.engineGetAppConfigurationEntry(TEST_REALM_NAME).length);
+    }
+
+    private static class ServiceAdder implements Runnable
+    {
+        private final CountDownLatch latch;
+        private final Queue<ServiceReference> references;
+        private final ConfigSpiOsgi spi;
+
+        ServiceAdder(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())
+            {
+                ServiceReference reference = references.poll();
+                if (reference != null)
+                {
+                    spi.addingService(reference);
+                }
+            }
+        }
+    }
+
+    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>()
+        {
+            @SuppressWarnings("SuspiciousMethodCalls")
+            @Override
+            public Object answer(InvocationOnMock i) throws Throwable
+            {
+                return props.get(i.getArguments()[0]);
+            }
+        });
+        return sr;
+    }
+}

Propchange: felix/trunk/jaas/src/test/java/org/apache/felix/jaas/internal/ITConcurrentLoginModuleFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native