You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/03/27 13:26:33 UTC

[5/5] camel git commit: CAMEL-9766: camel-itest-karaf to get working on karaf 4

CAMEL-9766: camel-itest-karaf to get working on karaf 4


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

Branch: refs/heads/master
Commit: ff1fb0e39cb38f5251b75702b6e232b25f1b2267
Parents: 9e7714a
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Mar 27 12:46:49 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Mar 27 12:46:49 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     | 17 +++++++++++++++++
 .../apache/camel/impl/DefaultCamelContext.java  | 20 ++++++++++++++++++--
 .../camel/impl/DefaultCamelContextTest.java     | 20 ++++++++++++++++++++
 .../camel/itest/karaf/AbstractFeatureTest.java  |  3 ++-
 .../camel/itest/karaf/CamelBindyTest.java       |  4 +++-
 5 files changed, 60 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ff1fb0e3/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 727a2b7..c7d212f 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -304,6 +304,9 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
 
     /**
      * Gets a component from the context by name.
+     * <p/>
+     * Notice the returned component will be auto-started. If you do not intend to do that
+     * then use {@link #getComponent(String, boolean, boolean)}.
      *
      * @param componentName the name of the component
      * @return the component
@@ -312,6 +315,9 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
 
     /**
      * Gets a component from the context by name.
+     * <p/>
+     * Notice the returned component will be auto-started. If you do not intend to do that
+     * then use {@link #getComponent(String, boolean, boolean)}.
      *
      * @param name                 the name of the component
      * @param autoCreateComponents whether or not the component should
@@ -321,6 +327,17 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
     Component getComponent(String name, boolean autoCreateComponents);
 
     /**
+     * Gets a component from the context by name.
+     *
+     * @param name                 the name of the component
+     * @param autoCreateComponents whether or not the component should
+     *                             be lazily created if it does not already exist
+     * @param autoStart            whether to auto start the component if {@link CamelContext} is already started.
+     * @return the component
+     */
+    Component getComponent(String name, boolean autoCreateComponents, boolean autoStart);
+
+    /**
      * Gets a component from the context by name and specifying the expected type of component.
      *
      * @param name          the name to lookup

http://git-wip-us.apache.org/repos/asf/camel/blob/ff1fb0e3/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 26ddea9..65deba6 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -383,10 +383,14 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
     }
 
     public Component getComponent(String name) {
-        return getComponent(name, autoCreateComponents);
+        return getComponent(name, autoCreateComponents, true);
     }
 
     public Component getComponent(String name, boolean autoCreateComponents) {
+        return getComponent(name, autoCreateComponents, true);
+    }
+
+    public Component getComponent(String name, boolean autoCreateComponents, boolean autoStart) {
         // synchronize the look up and auto create so that 2 threads can't
         // concurrently auto create the same component.
         synchronized (components) {
@@ -399,7 +403,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
                     component = getComponentResolver().resolveComponent(name, this);
                     if (component != null) {
                         addComponent(name, component);
-                        if (isStarted() || isStarting()) {
+                        if (autoStart && (isStarted() || isStarting())) {
                             // If the component is looked up after the context is started, lets start it up.
                             if (component instanceof Service) {
                                 startService((Service)component);
@@ -430,6 +434,18 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         }
     }
 
+    public Component resolveComponent(String name) {
+        Component answer = hasComponent(name);
+        if (answer == null) {
+            try {
+                answer = getComponentResolver().resolveComponent(name, this);
+            } catch (Exception e) {
+                throw new RuntimeCamelException("Cannot resolve component: " + name, e);
+            }
+        }
+        return answer;
+    }
+
     public Component removeComponent(String componentName) {
         synchronized (components) {
             Component oldComponent = components.remove(componentName);

http://git-wip-us.apache.org/repos/asf/camel/blob/ff1fb0e3/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java b/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
index 3403ae4..a8add11 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
@@ -58,6 +58,26 @@ public class DefaultCamelContextTest extends TestSupport {
         assertNull(component);
     }
     
+    public void testAutoStartComponentsOff() throws Exception {
+        DefaultCamelContext ctx = new DefaultCamelContext();
+        ctx.disableJMX();
+        ctx.start();
+
+        BeanComponent component = (BeanComponent) ctx.getComponent("bean", true, false);
+        // should be stopped
+        assertTrue(component.getStatus().isStopped());
+    }
+
+    public void testAutoStartComponentsOn() throws Exception {
+        DefaultCamelContext ctx = new DefaultCamelContext();
+        ctx.disableJMX();
+        ctx.start();
+
+        BeanComponent component = (BeanComponent) ctx.getComponent("bean", true, true);
+        // should be started
+        assertTrue(component.getStatus().isStarted());
+    }
+
     public void testCreateDefaultUuidGenerator() {
         DefaultCamelContext ctx = new DefaultCamelContext();
         ctx.disableJMX();

http://git-wip-us.apache.org/repos/asf/camel/blob/ff1fb0e3/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
index 609c479..adb4d00 100644
--- a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/AbstractFeatureTest.java
@@ -114,7 +114,8 @@ public abstract class AbstractFeatureTest {
         assertNotNull("Cannot find CamelContext with name myCamel", camelContext);
 
         LOG.info("Getting Camel component: {}", component);
-        Component comp = camelContext.getComponent(component);
+        // do not auto start the component as it may not have been configured properly and fail in its start method
+        Component comp = camelContext.getComponent(component, true, false);
         assertNotNull("Cannot get component with name: " + component, comp);
 
         LOG.info("Found Camel component: {} instance: {} with className: {}", component, comp, comp.getClass());

http://git-wip-us.apache.org/repos/asf/camel/blob/ff1fb0e3/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelBindyTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelBindyTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelBindyTest.java
index cb47be2..7e106a1 100644
--- a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelBindyTest.java
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelBindyTest.java
@@ -27,7 +27,9 @@ public class CamelBindyTest extends AbstractFeatureTest {
 
     @Test
     public void test() throws Exception {
-        testDataFormat(COMPONENT);
+        testDataFormat(COMPONENT, "bindy-csv");
+        testDataFormat(COMPONENT, "bindy-fixed");
+        testDataFormat(COMPONENT, "bindy-kvp");
     }
 
 }
\ No newline at end of file