Author: chetanm
Date: Fri Nov 27 11:30:42 2015
New Revision: 1716840

URL: http://svn.apache.org/viewvc?rev=1716840&view=rev
Log:
OAK-3689 - OakOSGiRepositoryFactory shutting down the repository twice

-- Ensure that shutdown is not called on repository instance from within 
OakOSGiRepositoryFactory
-- Add some timeout after service unregistration in couple of test otherwise 
test were failing due to timing issue

Added:
    
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/RepositoryShutdownTest.groovy
Modified:
    
jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java
    
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy
    
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/PropertyIndexReindexingTest.groovy

Modified: 
jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java?rev=1716840&r1=1716839&r2=1716840&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-pojosr/src/main/java/org/apache/jackrabbit/oak/run/osgi/OakOSGiRepositoryFactory.java
 Fri Nov 27 11:30:42 2015
@@ -466,13 +466,15 @@ public class OakOSGiRepositoryFactory im
                 return tracker.getRegistry();
             }
 
-            Object result = method.invoke(obj, args);
-
-            //If shutdown then close the framework *after* repository shutdown
+            //If shutdown then close the framework and return
+            //Repository would be shutdown by the owning OSGi
+            //component like RepositoryManager
             if ("shutdown".equals(name)) {
                 tracker.shutdownRepository();
+                return null;
             }
-            return result;
+
+            return method.invoke(obj, args);
         }
 
         public void clearInitialReference() {

Modified: 
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy?rev=1716840&r1=1716839&r2=1716840&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy
 (original)
+++ 
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/DocumentNodeStoreConfigTest.groovy
 Fri Nov 27 11:30:42 2015
@@ -34,6 +34,7 @@ import org.osgi.framework.ServiceRegistr
 import javax.sql.DataSource
 import java.sql.Connection
 import java.sql.ResultSet
+import java.util.concurrent.TimeUnit
 
 import static org.junit.Assume.assumeTrue
 
@@ -84,6 +85,7 @@ class DocumentNodeStoreConfigTest extend
 
         //3. Shut down ds
         srds.unregister();
+        TimeUnit.MILLISECONDS.sleep(500);
         assertNoService(NodeStore.class)
 
         //4. Restart ds, service should still be down

Modified: 
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/PropertyIndexReindexingTest.groovy
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/PropertyIndexReindexingTest.groovy?rev=1716840&r1=1716839&r2=1716840&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/PropertyIndexReindexingTest.groovy
 (original)
+++ 
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/PropertyIndexReindexingTest.groovy
 Fri Nov 27 11:30:42 2015
@@ -31,6 +31,7 @@ import org.junit.Test
 import javax.jcr.Node
 import javax.jcr.Repository
 import javax.jcr.Session
+import java.util.concurrent.TimeUnit
 
 import static 
org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory.REPOSITORY_CONFIG_FILE
 
@@ -70,7 +71,7 @@ class PropertyIndexReindexingTest extend
         assert c
 
         c[0].disable()
-
+        TimeUnit.SECONDS.sleep(1)
        assert registry.getServiceReference(Repository.class.name) == null : 
"Repository should be unregistered " +
                "if no property index editor found"
 

Added: 
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/RepositoryShutdownTest.groovy
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/RepositoryShutdownTest.groovy?rev=1716840&view=auto
==============================================================================
--- 
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/RepositoryShutdownTest.groovy
 (added)
+++ 
jackrabbit/oak/trunk/oak-pojosr/src/test/groovy/org/apache/jackrabbit/oak/run/osgi/RepositoryShutdownTest.groovy
 Fri Nov 27 11:30:42 2015
@@ -0,0 +1,69 @@
+/*
+ * 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.jackrabbit.oak.run.osgi
+
+import org.apache.jackrabbit.api.JackrabbitRepository
+import org.junit.Rule
+import org.junit.Test
+import org.junit.rules.TemporaryFolder
+import org.osgi.framework.BundleActivator
+import org.osgi.framework.BundleContext
+
+import javax.jcr.Repository
+
+import static 
org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory.REPOSITORY_HOME
+import static 
org.apache.jackrabbit.oak.run.osgi.OakOSGiRepositoryFactory.REPOSITORY_TIMEOUT_IN_SECS
+import static org.mockito.Mockito.mock
+import static org.mockito.Mockito.times
+import static org.mockito.Mockito.verify
+
+
+class RepositoryShutdownTest {
+
+    @Rule
+    public final TemporaryFolder tmpFolder = new TemporaryFolder()
+
+    @Test
+    public void multipleShutdown() throws Exception{
+        JackrabbitRepository repository = mock(JackrabbitRepository.class)
+        def config = [
+                (REPOSITORY_HOME): tmpFolder.root.absolutePath,
+                (REPOSITORY_TIMEOUT_IN_SECS) : 60,
+                (BundleActivator.class.name) : new BundleActivator(){
+                    @Override
+                    void start(BundleContext bundleContext) throws Exception {
+                        bundleContext.registerService(Repository.class.name, 
repository, null)
+                    }
+
+                    @Override
+                    void stop(BundleContext bundleContext) throws Exception {
+
+                    }
+                }
+        ]
+
+        Repository repo2 = new OakOSGiRepositoryFactory().getRepository(config)
+        assert repo2 instanceof JackrabbitRepository
+        repo2.shutdown()
+
+        verify(repository, times(0)).shutdown()
+
+    }
+}


Reply via email to