karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject karaf git commit: [KARAF-3752] Check that resolver does not mandate required services to be present
Date Mon, 01 Jun 2015 13:15:36 GMT
Repository: karaf
Updated Branches:
  refs/heads/master 28a197b20 -> a773dc5ff


[KARAF-3752] Check that resolver does not mandate required services to be present


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/a773dc5f
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/a773dc5f
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/a773dc5f

Branch: refs/heads/master
Commit: a773dc5ffa950feaf857d6c0ee91eb91cb777c57
Parents: 28a197b
Author: Christian Schneider <chris@die-schneider.net>
Authored: Mon Jun 1 15:15:15 2015 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Mon Jun 1 15:15:15 2015 +0200

----------------------------------------------------------------------
 .../apache/karaf/itests/ImportServiceTest.java  | 67 ++++++++++++++++++++
 .../apache/karaf/itests/KarafTestSupport.java   | 20 +++++-
 2 files changed, 86 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/a773dc5f/itests/src/test/java/org/apache/karaf/itests/ImportServiceTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/ImportServiceTest.java b/itests/src/test/java/org/apache/karaf/itests/ImportServiceTest.java
new file mode 100644
index 0000000..c7cde9f
--- /dev/null
+++ b/itests/src/test/java/org/apache/karaf/itests/ImportServiceTest.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed 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.karaf.itests;
+
+import static org.ops4j.pax.tinybundles.core.TinyBundles.bundle;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.framework.Bundle;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class ImportServiceTest extends KarafTestSupport {
+
+    private static final String BUNDLE2_NAME = "testbundle.require.service";
+    private static final String BUNDLE1_NAME = "testbundle.import.service";
+
+    @Configuration
+    public Option[] config() {
+        List<Option> options = new ArrayList<Option>(Arrays.asList(super.config()));
+        InputStream testBundleImportService = bundle()
+            .set("Import-Service", "FooService")
+            .set("Bundle-SymbolicName", BUNDLE1_NAME)
+            .set("Bundle-Version", "1.0.0")
+            .build();
+        options.add(CoreOptions.streamBundle(testBundleImportService));
+        InputStream testBundleRequireService = bundle()
+            .set("Require-Capability", "osgi.service;effective:=active;filter:=\"(objectClass=FooService)\"")
+            .set("Bundle-SymbolicName", BUNDLE2_NAME)
+            .set("Bundle-Version", "1.0.0")
+            .build();
+        options.add(CoreOptions.streamBundle(testBundleRequireService));
+        return options.toArray(new Option[] {});
+    }
+
+    /**
+     * Checks that the resolver does not mandate specified required services to be present.
+     * This is done for backwards compatibility as not all bundles define capabilities for
services they start.
+     */
+    @Test
+    public void checkBundleStarted() throws InterruptedException {
+        waitBundleState(BUNDLE1_NAME, Bundle.ACTIVE);
+        waitBundleState(BUNDLE2_NAME, Bundle.ACTIVE);
+    }
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/a773dc5f/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
index 4db1af7..729b897 100644
--- a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
+++ b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
@@ -85,6 +85,7 @@ public class KarafTestSupport {
 
     static final Long COMMAND_TIMEOUT = 30000L;
     static final Long SERVICE_TIMEOUT = 30000L;
+    static final long BUNDLE_TIMEOUT = 30000L;
 
     private static Logger LOG = LoggerFactory.getLogger(KarafTestSupport.class);
 
@@ -131,7 +132,7 @@ public class KarafTestSupport {
             // enable JMX RBAC security, thanks to the KarafMBeanServerBuilder
             configureSecurity().disableKarafMBeanServerBuilder(),
             keepRuntimeFolder(),
-				logLevel(LogLevel.INFO),
+            logLevel(LogLevel.INFO),
             replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", getConfigFile("/etc/org.ops4j.pax.logging.cfg")),
             editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port",
HTTP_PORT),
             editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort",
RMI_REG_PORT),
@@ -316,6 +317,23 @@ public class KarafTestSupport {
             st.close();
         }
     }
+    
+    protected Bundle waitBundleState(String symbolicName, int state) {
+        long endTime = System.currentTimeMillis() + BUNDLE_TIMEOUT;
+        while (System.currentTimeMillis() < endTime) {
+            Bundle bundle = findBundleByName(symbolicName);
+            if (bundle != null && bundle.getState() == state) {
+                return bundle;
+            }
+            try {
+                Thread.sleep(500);
+            } catch (InterruptedException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+        Assert.fail("Manadatory bundle " + symbolicName + " not found.");
+        throw new IllegalStateException("Should not be reached");
+    }
 
     /*
     * Explode the dictionary into a ,-delimited list of key=value pairs


Mime
View raw message