incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r776315 - in /incubator/sling/trunk/contrib/extensions/jcrinstall: it/src/test/java/org/apache/sling/jcr/jcrinstall/it/ osgi/src/main/java/org/apache/sling/osgi/installer/ osgi/src/main/java/org/apache/sling/osgi/installer/impl/ osgi/src/te...
Date Tue, 19 May 2009 13:50:42 GMT
Author: bdelacretaz
Date: Tue May 19 13:50:41 2009
New Revision: 776315

URL: http://svn.apache.org/viewvc?rev=776315&view=rev
Log:
SLING-904 - fix OsgiControllerTest.testDeferredConfigInstall

Added:
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java
      - copied, changed from r776243, incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ServiceProxy.java
Removed:
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ServiceProxy.java
Modified:
    incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessor.java
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiControllerImpl.java
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiResourceProcessorList.java
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessorTest.java

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java?rev=776315&r1=776314&r2=776315&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java
(original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java
Tue May 19 13:50:41 2009
@@ -34,6 +34,7 @@
 
 import org.apache.sling.osgi.installer.DictionaryInstallableData;
 import org.apache.sling.osgi.installer.OsgiController;
+import org.apache.sling.osgi.installer.OsgiControllerServices;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Inject;
@@ -44,14 +45,11 @@
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.startlevel.StartLevel;
 
 /** Test the OsgiController running in the OSGi framework */
 @RunWith(JUnit4TestRunner.class)
 public class OsgiControllerTest {
 	public final static String POM_VERSION = System.getProperty("jcrinstall.pom.version");
-	public final static int CONFIG_ADMIN_START_LEVEL = 100;
-	public final static int NO_CONFIG_ADMIN_START_LEVEL = CONFIG_ADMIN_START_LEVEL - 1;
 	
     @Inject
     protected BundleContext bundleContext;
@@ -93,23 +91,22 @@
     	return new File(System.getProperty("jcrinstall.base.dir"), bundleName);
     }
     
-    protected void setStartLevel(int level) throws InterruptedException {
-    	final StartLevel s = getService(StartLevel.class);
-    	s.setStartLevel(level);
+    protected void waitForConfigAdmin(boolean shouldBePresent) throws InterruptedException
{
+    	final OsgiControllerServices svc = getService(OsgiControllerServices.class);
     	final int timeout = 5;
     	final long waitUntil = System.currentTimeMillis() + (timeout * 1000L);
     	do {
-    		if(s.getStartLevel() == level) {
+    		boolean isPresent = svc.getConfigurationAdmin() != null;
+    		if(isPresent == shouldBePresent) {
     			return;
     		}
     		Thread.sleep(100L);
     	} while(System.currentTimeMillis() < waitUntil);
-    	fail("Start level did not change to " + level + " after waiting " + timeout + " seconds");
+    	fail("ConfigurationAdmin service not available after waiting " + timeout + " seconds");
     }
     
     @Test
     public void testInstallAndRemoveConfig() throws Exception {
-    	setStartLevel(CONFIG_ADMIN_START_LEVEL);
     	final OsgiController c = getService(OsgiController.class);
     	final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
     	cfgData.put("foo", "bar");
@@ -132,10 +129,19 @@
     	assertNull("Config " + cfgPid + " must be gone after executeScheduledOperations", findConfiguration(cfgPid));
     }
     
-    // TODO test fails due to SCR no rebinding the ConfigurationAdmin service
-    // to the OsgiController @Test
+    @Test
     public void testDeferredConfigInstall() throws Exception {
-    	setStartLevel(CONFIG_ADMIN_START_LEVEL);
+    	
+    	final String cfgName = "org.apache.felix.configadmin";
+    	Bundle configAdmin = null;
+    	for(Bundle b : bundleContext.getBundles()) {
+    		if(b.getSymbolicName().equals(cfgName)) {
+    			configAdmin = b;
+    			break;
+    		}
+    	}
+    	assertNotNull(cfgName + " bundle must be found", configAdmin);
+    	waitForConfigAdmin(true);
     	
     	final OsgiController c = getService(OsgiController.class);
     	final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
@@ -147,10 +153,11 @@
     	assertNull("Config " + cfgPid + " must not be found right after scheduleInstall", findConfiguration(cfgPid));
     	
     	// Config installs must be deferred if ConfigAdmin service is stopped
-    	setStartLevel(NO_CONFIG_ADMIN_START_LEVEL);
+    	configAdmin.stop();
+    	waitForConfigAdmin(false);
     	c.executeScheduledOperations();
-    	setStartLevel(CONFIG_ADMIN_START_LEVEL);
-    	getService(ConfigurationAdmin.class);
+    	configAdmin.start();
+    	waitForConfigAdmin(true);
     	assertNull("Config " + cfgPid + " must not be installed if ConfigAdmin was stopped",
findConfiguration(cfgPid));
     	
     	// with configadmin back, executeScheduledOperations must install deferred configs
@@ -248,8 +255,9 @@
                 vmOption(vmOpt),
                 waitForFrameworkStartup(),
         		provision(
-        	            mavenBundle("org.apache.felix", "org.apache.felix.scr", "1.0.6"),
-        	            mavenBundle("org.apache.felix", "org.apache.felix.configadmin").startLevel(CONFIG_ADMIN_START_LEVEL),
+        				// TODO use latest scr?
+        	            mavenBundle("org.apache.felix", "org.apache.felix.scr"),
+        	            mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
         	            mavenBundle("org.apache.sling", "org.apache.sling.commons.log"),
         	        	mavenBundle("org.apache.sling", "org.apache.sling.osgi.installer", POM_VERSION)
         		)

Copied: incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java
(from r776243, incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ServiceProxy.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java?p2=incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java&p1=incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ServiceProxy.java&r1=776243&r2=776315&rev=776315&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ServiceProxy.java
(original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/OsgiControllerServices.java
Tue May 19 13:50:41 2009
@@ -16,13 +16,15 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.osgi.installer.impl;
+package org.apache.sling.osgi.installer;
 
 import org.osgi.service.cm.ConfigurationAdmin;
 
 /** Proxy for services that might not be always available, allows
- * 	classes which are not OSGi services to access such services easily
+ * 	classes which are not OSGi services to access such services easily.
+ * 	Should normally be part of the implementation package, but it is
+ * 	used in tests to find out when the controller is ready.
  */
-interface ServiceProxy {
+public interface OsgiControllerServices {
 	ConfigurationAdmin getConfigurationAdmin();
 }

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessor.java?rev=776315&r1=776314&r2=776315&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessor.java
(original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessor.java
Tue May 19 13:50:41 2009
@@ -28,6 +28,7 @@
 
 import org.apache.sling.osgi.installer.InstallableData;
 import org.apache.sling.osgi.installer.JcrInstallException;
+import org.apache.sling.osgi.installer.OsgiControllerServices;
 import org.apache.sling.osgi.installer.OsgiResourceProcessor;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
@@ -43,9 +44,9 @@
     public static final String CONFIG_EXTENSION = ".cfg";
     private final Logger log = LoggerFactory.getLogger(this.getClass());
     private final DictionaryReader reader = new DictionaryReader();
-    private final ServiceProxy serviceProxy;
+    private final OsgiControllerServices serviceProxy;
     
-    ConfigResourceProcessor(ServiceProxy sp) {
+    ConfigResourceProcessor(OsgiControllerServices sp) {
         serviceProxy = sp;
     }
     

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiControllerImpl.java?rev=776315&r1=776314&r2=776315&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiControllerImpl.java
(original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiControllerImpl.java
Tue May 19 13:50:41 2009
@@ -28,10 +28,12 @@
 import org.apache.sling.osgi.installer.InstallableData;
 import org.apache.sling.osgi.installer.JcrInstallException;
 import org.apache.sling.osgi.installer.OsgiController;
+import org.apache.sling.osgi.installer.OsgiControllerServices;
 import org.apache.sling.osgi.installer.OsgiResourceProcessor;
 import org.apache.sling.osgi.installer.ResourceOverrideRules;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.SynchronousBundleListener;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.component.ComponentContext;
@@ -52,7 +54,7 @@
  *      name="service.vendor"
  *      value="The Apache Software Foundation"
 */
-public class OsgiControllerImpl implements OsgiController, SynchronousBundleListener, ServiceProxy
{
+public class OsgiControllerImpl implements OsgiController, SynchronousBundleListener, OsgiControllerServices
{
 
 	private BundleContext bundleContext;
     private Storage storage;
@@ -66,9 +68,6 @@
     /** Storage key: digest of an InstallableData */
     public static final String KEY_DIGEST = "data.digest";
 
-    /** @scr.reference cardinality="0..1" policy="dynamic" */
-    private ConfigurationAdmin configAdmin;
-
     /** @scr.reference */
     private PackageAdmin packageAdmin;
 
@@ -198,6 +197,14 @@
     }
 
 	public ConfigurationAdmin getConfigurationAdmin() {
-		return configAdmin;
+		// TODO ConfigurationAdmin should be bound/unbound rather than
+		// looking it up every time, but that caused problems in the it/OsgiControllerTest
+		if(bundleContext != null) {
+		   	final ServiceReference ref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
+		    if(ref != null) {
+		    	return (ConfigurationAdmin)bundleContext.getService(ref);
+		    }
+		}
+		return null;
 	}
 }
\ No newline at end of file

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiResourceProcessorList.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiResourceProcessorList.java?rev=776315&r1=776314&r2=776315&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiResourceProcessorList.java
(original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/OsgiResourceProcessorList.java
Tue May 19 13:50:41 2009
@@ -21,6 +21,7 @@
 import java.util.LinkedList;
 
 import org.apache.sling.osgi.installer.InstallableData;
+import org.apache.sling.osgi.installer.OsgiControllerServices;
 import org.apache.sling.osgi.installer.OsgiResourceProcessor;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.packageadmin.PackageAdmin;
@@ -35,7 +36,7 @@
 class OsgiResourceProcessorList extends LinkedList<OsgiResourceProcessor> {
     private final Logger log = LoggerFactory.getLogger(getClass());
     
-	OsgiResourceProcessorList(BundleContext ctx, PackageAdmin pa, StartLevel sa, ServiceProxy
sp) {
+	OsgiResourceProcessorList(BundleContext ctx, PackageAdmin pa, StartLevel sa, OsgiControllerServices
sp) {
         add(new BundleResourceProcessor(ctx, pa, sa));
         add(new ConfigResourceProcessor(sp));
 	}

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessorTest.java?rev=776315&r1=776314&r2=776315&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessorTest.java
(original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/ConfigResourceProcessorTest.java
Tue May 19 13:50:41 2009
@@ -20,6 +20,7 @@
 
 import java.util.Dictionary;
 
+import org.apache.sling.osgi.installer.OsgiControllerServices;
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
 import org.hamcrest.Matcher;
@@ -41,7 +42,7 @@
         final String data = "foo = bar";
         final MockInstallableData id = new MockInstallableData(path, data);
         final ConfigurationAdmin ca = mockery.mock(ConfigurationAdmin.class);
-        final ServiceProxy sp = new ServiceProxy() {
+        final OsgiControllerServices sp = new OsgiControllerServices() {
 			public ConfigurationAdmin getConfigurationAdmin() {
 				return ca;
 			}



Mime
View raw message