felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1138421 - in /felix/trunk/dependencymanager: core/src/main/java/org/apache/felix/dm/DependencyManager.java test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java
Date Wed, 22 Jun 2011 12:10:01 GMT
Author: marrs
Date: Wed Jun 22 12:10:01 2011
New Revision: 1138421

URL: http://svn.apache.org/viewvc?rev=1138421&view=rev
Log:
FELIX-3008 Added test and fix for this issue. If the dependency manager bundle was not yet
started when indices are defined and the first bundle starts to use them, that bundle will
then attempt to start the dependency manager automatically. If that fails, no indices will
be used.

Added:
    felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java
  (with props)
Modified:
    felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java

Modified: felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java?rev=1138421&r1=1138420&r2=1138421&view=diff
==============================================================================
--- felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
(original)
+++ felix/trunk/dependencymanager/core/src/main/java/org/apache/felix/dm/DependencyManager.java
Wed Jun 22 12:10:01 2011
@@ -42,7 +42,9 @@ import org.apache.felix.dm.impl.index.As
 import org.apache.felix.dm.impl.index.MultiPropertyExactFilter;
 import org.apache.felix.dm.impl.index.ServiceRegistryCache;
 import org.apache.felix.dm.impl.metatype.PropertyMetaDataImpl;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.FrameworkUtil;
 
 /**
@@ -89,18 +91,30 @@ public class DependencyManager {
     static {
         String index = System.getProperty(SERVICEREGISTRY_CACHE_INDICES);
         if (index != null) {
-            m_serviceRegistryCache = new ServiceRegistryCache(FrameworkUtil.getBundle(DependencyManager.class).getBundleContext());
-            m_serviceRegistryCache.open(); // TODO close it somewhere
-            String[] props = index.split(";");
-            for (int i = 0; i < props.length; i++) {
-                if (props[i].equals("*aspect*")) {
-                    m_serviceRegistryCache.addFilterIndex(new AspectFilterIndex());
+            Bundle bundle = FrameworkUtil.getBundle(DependencyManager.class);
+            try {
+                if (bundle.getState() != Bundle.ACTIVE) {
+                    bundle.start();
                 }
-                else {
-                    String[] propList = props[i].split(",");
-                    m_serviceRegistryCache.addFilterIndex(new MultiPropertyExactFilter(propList));
+                BundleContext bundleContext = bundle.getBundleContext();
+                
+                m_serviceRegistryCache = new ServiceRegistryCache(bundleContext);
+                m_serviceRegistryCache.open(); // TODO close it somewhere
+                String[] props = index.split(";");
+                for (int i = 0; i < props.length; i++) {
+                    if (props[i].equals("*aspect*")) {
+                        m_serviceRegistryCache.addFilterIndex(new AspectFilterIndex());
+                    }
+                    else {
+                        String[] propList = props[i].split(",");
+                        m_serviceRegistryCache.addFilterIndex(new MultiPropertyExactFilter(propList));
+                    }
                 }
             }
+            catch (BundleException e) {
+                // if we cannot start ourselves, we cannot use the indices
+                // TODO we might want to warn people about this
+            }
         }
     }
     

Added: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java?rev=1138421&view=auto
==============================================================================
--- felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java
(added)
+++ felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java
Wed Jun 22 12:10:01 2011
@@ -0,0 +1,108 @@
+/*
+ * 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.dm.test;
+//import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartupFor;
+//import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption;
+
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import junit.framework.Assert;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+
+@RunWith(JUnit4TestRunner.class)
+public class FELIX3008_FilterIndexStartupTest extends Base {
+    @Configuration
+    public static Option[] configuration() {
+        return options(
+            //vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" ),
+            //waitForFrameworkStartupFor(Long.MAX_VALUE),
+            provision(
+                mavenBundle().groupId("org.osgi").artifactId("org.osgi.compendium").version(Base.OSGI_SPEC_VERSION),
+                mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.dependencymanager").versionAsInProject().noStart()
+            )
+        );
+    }
+    
+    @Test
+    public void testNormalStart(BundleContext context) throws Exception {
+        System.setProperty("org.apache.felix.dependencymanager.filterindex", "objectClass");
+        DependencyManager m = new DependencyManager(context);
+        // helper class that ensures certain steps get executed in sequence
+        Ensure e = new Ensure();
+        // create a provider
+        Provider provider = new Provider();
+        // activate it
+        Component p = m.createComponent()
+            .setInterface(Service.class.getName(), null)
+            .setImplementation(provider);
+        
+        Consumer consumer = new Consumer(e);
+        Component c = m.createComponent()
+            .setImplementation(consumer)
+            .add(m.createServiceDependency()
+                .setService(Service.class)
+                .setRequired(true)
+                );
+        
+        m.add(p);
+        m.add(c);
+        e.waitForStep(1, 5000);
+        m.remove(p);
+        e.waitForStep(2, 5000);
+        m.remove(c);
+        
+        Assert.assertEquals("Dependency manager bundle should be active.", Bundle.ACTIVE,
context.getBundle().getState());
+    }
+
+    public static class Consumer {
+        volatile Service m_service;
+        private final Ensure m_ensure;
+        
+        public Consumer(Ensure e) {
+            m_ensure = e;
+        }
+
+        public void start() {
+            System.out.println("start");
+            m_ensure.step(1);
+        }
+        
+        public void stop() {
+            System.out.println("stop");
+            m_ensure.step(2);
+        }
+    }
+    
+    public static interface Service {
+    }
+    
+    public static class Provider implements Service {
+    }
+}

Propchange: felix/trunk/dependencymanager/test/src/test/java/org/apache/felix/dm/test/FELIX3008_FilterIndexStartupTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message