[CAMEL-8948] Add synchronous CamelBlueprintTestSupport test

(cherry picked from commit 7aa3b59dd7718a47c0f5e4417419b28772ba067b)


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

Branch: refs/heads/camel-2.15.x
Commit: 6998e85d746248cf27ab1d9ad7baf576957cdba2
Parents: 0285565
Author: Grzegorz Grzybek <gr.grzy...@gmail.com>
Authored: Mon Jul 20 11:12:30 2015 +0200
Committer: Grzegorz Grzybek <gr.grzy...@gmail.com>
Committed: Tue Jul 21 09:45:56 2015 +0200

----------------------------------------------------------------------
 .../test/blueprint/CamelBlueprintHelper.java    |  3 --
 .../blueprint/CamelBlueprintTestSupport.java    | 17 +++++++-
 ...intWithSynchronousBlueprintCreationTest.java | 45 ++++++++++++++++++++
 3 files changed, 61 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6998e85d/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
----------------------------------------------------------------------
diff --git 
a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
 
b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
index 497b065..f6f1b46 100644
--- 
a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
+++ 
b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java
@@ -113,9 +113,6 @@ public final class CamelBlueprintHelper {
         String uid = "" + System.currentTimeMillis();
         String tempDir = "target/bundles/" + uid;
         System.setProperty("org.osgi.framework.storage", tempDir);
-        // explicitly set this to "false" - we will not depend on the order of 
starting bundles,
-        // (and running their BP containers) but we will have to do more 
synchornization
-        System.setProperty("org.apache.aries.blueprint.synchronous", "false");
         createDirectory(tempDir);
 
         // use another directory for the jar of the bundle as it cannot be in 
the same directory

http://git-wip-us.apache.org/repos/asf/camel/blob/6998e85d/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
----------------------------------------------------------------------
diff --git 
a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
 
b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
index be721e4..1839789 100644
--- 
a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
+++ 
b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java
@@ -72,9 +72,24 @@ public abstract class CamelBlueprintTestSupport extends 
CamelTestSupport {
         return true;
     }
 
-   
+    /**
+     * <p>Override this method if you want to start Blueprint containers 
asynchronously using the thread
+     * that starts the bundles itself.
+     * By default this method returns <code>true</code> which means Blueprint 
Extender will use thread pool
+     * (threads named "<code>Blueprint Extender: N</code>") to startup 
Blueprint containers.</p>
+     * <p>Karaf and Fuse OSGi containers use synchronous startup.</p>
+     * <p>Asynchronous startup is more in the <em>spirit</em> of OSGi and 
usually means that if everything works fine
+     * asynchronously, it'll work synchronously as well. This isn't always 
true otherwise.</p>
+     * @return
+     */
+    protected boolean useAsynchronousBlueprintStartup() {
+        return true;
+    }
+
     @SuppressWarnings({"rawtypes", "unchecked"})
     protected BundleContext createBundleContext() throws Exception {
+        System.setProperty("org.apache.aries.blueprint.synchronous", 
Boolean.toString(!useAsynchronousBlueprintStartup()));
+
         final String symbolicName = getClass().getSimpleName();
         final BundleContext answer = 
CamelBlueprintHelper.createBundleContext(symbolicName, getBlueprintDescriptor(),
             includeTestBundle(), getBundleFilter(), getBundleVersion(), 
getBundleDirectives());

http://git-wip-us.apache.org/repos/asf/camel/blob/6998e85d/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminEndpointWithSynchronousBlueprintCreationTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminEndpointWithSynchronousBlueprintCreationTest.java
 
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminEndpointWithSynchronousBlueprintCreationTest.java
new file mode 100644
index 0000000..b07dc2a
--- /dev/null
+++ 
b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminEndpointWithSynchronousBlueprintCreationTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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.camel.test.blueprint;
+
+import org.junit.Test;
+
+/**
+ *
+ */
+public class ConfigAdminEndpointWithSynchronousBlueprintCreationTest extends 
CamelBlueprintTestSupport {
+
+    @Override
+    protected boolean useAsynchronousBlueprintStartup() {
+        return false;
+    }
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return "org/apache/camel/test/blueprint/configadmin-endpoint.xml";
+    }
+
+    @Test
+    public void testConfigAdmin() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        template.sendBody("direct:start", "World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}

Reply via email to