camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lburgazz...@apache.org
Subject camel git commit: Add docker profile to execute integration test
Date Wed, 28 Jun 2017 06:09:33 GMT
Repository: camel
Updated Branches:
  refs/heads/master 7c37c2fcd -> 61ad97f02


Add docker profile to execute integration test

There is now a docker profile (not active by default) thats spins
up a consul instance using docker-maven-plugin in integration
tests phase.


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

Branch: refs/heads/master
Commit: 61ad97f02acdbec562a905d16da9686fba5a58b4
Parents: 7c37c2f
Author: lburgazzoli <lburgazzoli@gmail.com>
Authored: Wed Jun 28 08:06:22 2017 +0200
Committer: lburgazzoli <lburgazzoli@gmail.com>
Committed: Wed Jun 28 08:09:12 2017 +0200

----------------------------------------------------------------------
 components/camel-consul/pom.xml                 |  90 +++++++++++++++
 .../consul/policy/ConsulRoutePolicy.java        |   4 +
 .../component/consul/ConsulTestSupport.java     |  21 +++-
 .../consul/ha/ConsulClusteredRoutePolicyIT.java | 111 +++++++++++++++++++
 .../ha/ConsulClusteredRoutePolicyTest.java      | 105 ------------------
 parent/pom.xml                                  |   1 +
 6 files changed, 223 insertions(+), 109 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/61ad97f0/components/camel-consul/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-consul/pom.xml b/components/camel-consul/pom.xml
index 4ed84b8..2bee481 100644
--- a/components/camel-consul/pom.xml
+++ b/components/camel-consul/pom.xml
@@ -114,7 +114,9 @@
   </dependencies>
 
 
+
   <profiles>
+
     <profile>
       <id>consul-skip-tests</id>
       <activation>
@@ -148,6 +150,94 @@
       </build>
     </profile>
 
+    <profile>
+      <id>docker</id>
+      <activation>
+        <activeByDefault>false</activeByDefault>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>io.fabric8</groupId>
+            <artifactId>docker-maven-plugin</artifactId>
+            <version>${docker-maven-plugin-version}</version>
+            <executions>
+              <execution>
+                <id>start</id>
+                <phase>pre-integration-test</phase>
+                <goals>
+                  <goal>start</goal>
+                </goals>
+                <configuration>
+                  <showLogs>false</showLogs>
+                  <images>
+                    <image>
+                      <name>consul:latest</name>
+                      <alias>consul</alias>
+                      <run>
+                        <ports>
+                          <port>consul.port:8500</port>
+                        </ports>
+                        <wait>
+                          <log>agent: Synced service 'consul'</log>
+                          <time>20000</time>
+                        </wait>
+                        <cmd>
+                          <exec>
+                            <arg>agent</arg>
+                            <arg>-dev</arg>
+                            <arg>-server</arg>
+                            <arg>-bootstrap</arg>
+                            <arg>-client</arg>
+                            <arg>0.0.0.0</arg>
+                            <arg>-log-level</arg>
+                            <arg>trace</arg>
+                          </exec>
+                        </cmd>
+                      </run>
+                    </image>
+                  </images>
+                </configuration>
+              </execution>
+              <execution>
+                <id>stop</id>
+                <phase>post-integration-test</phase>
+                <goals>
+                  <goal>stop</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <skipTests>true</skipTests>
+            </configuration>
+          </plugin>
+
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-failsafe-plugin</artifactId>
+            <executions>
+              <execution>
+                <goals>
+                  <goal>integration-test</goal>
+                  <goal>verify</goal>
+                </goals>
+              </execution>
+            </executions>
+            <configuration>
+              <systemProperties>
+                <camel.consul.port>${consul.port}</camel.consul.port>
+                <camel.consul.host>127.0.0.1</camel.consul.host>
+              </systemProperties>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+
   </profiles>
 
 </project>

http://git-wip-us.apache.org/repos/asf/camel/blob/61ad97f0/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
index e7397a8..a40fd20 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
@@ -44,6 +44,10 @@ import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * @deprecated use {@link org.apache.camel.component.consul.ha.ConsulClusterService} and
{@link org.apache.camel.impl.ha.ClusteredRoutePolicy} instead.
+ */
+@Deprecated
 @ManagedResource(description = "Route policy using Consul as clustered lock")
 public final class ConsulRoutePolicy extends RoutePolicySupport implements CamelContextAware
{
     private static final Logger LOGGER = LoggerFactory.getLogger(ConsulRoutePolicy.class);

http://git-wip-us.apache.org/repos/asf/camel/blob/61ad97f0/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulTestSupport.java
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulTestSupport.java
index 6cf3683..d917933 100644
--- a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulTestSupport.java
+++ b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulTestSupport.java
@@ -22,21 +22,34 @@ import java.util.UUID;
 
 import com.orbitz.consul.Consul;
 import com.orbitz.consul.KeyValueClient;
+import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Rule;
 import org.junit.rules.TestName;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class ConsulTestSupport extends CamelTestSupport {
-    public static final Logger LOGGER = LoggerFactory.getLogger(ConsulTestSupport.class);
+    public static final String CONSUL_HOST = System.getProperty("camel.consul.host", Consul.DEFAULT_HTTP_HOST);
+    public static final int CONSUL_PORT = Integer.getInteger("camel.consul.port", Consul.DEFAULT_HTTP_PORT);
+    public static final String CONSUL_URL = String.format("http://%s:%d", CONSUL_HOST, CONSUL_PORT);
     public static final String KV_PREFIX = "/camel";
 
     @Rule
     public final TestName testName = new TestName();
 
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+
+        ConsulComponent component = new ConsulComponent();
+        component.setUrl(CONSUL_URL);
+
+        registry.bind("consul", component);
+
+        return registry;
+    }
+
     protected Consul getConsul() {
-        return Consul.builder().build();
+        return Consul.builder().withUrl(CONSUL_URL).build();
     }
 
     protected KeyValueClient getKeyValueClient() {

http://git-wip-us.apache.org/repos/asf/camel/blob/61ad97f0/components/camel-consul/src/test/java/org/apache/camel/component/consul/ha/ConsulClusteredRoutePolicyIT.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ha/ConsulClusteredRoutePolicyIT.java
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ha/ConsulClusteredRoutePolicyIT.java
new file mode 100644
index 0000000..effa2f3
--- /dev/null
+++ b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ha/ConsulClusteredRoutePolicyIT.java
@@ -0,0 +1,111 @@
+/**
+ * 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.component.consul.ha;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import com.orbitz.consul.Consul;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.ha.ClusteredRoutePolicyFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ConsulClusteredRoutePolicyIT {
+    private static final Logger LOGGER = LoggerFactory.getLogger(ConsulClusteredRoutePolicyIT.class);
+    private static final List<String> CLIENTS = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList());
+    private static final List<String> RESULTS = new ArrayList<>();
+    private static final ScheduledExecutorService SCHEDULER = Executors.newScheduledThreadPool(CLIENTS.size()
* 2);
+    private static final CountDownLatch LATCH = new CountDownLatch(CLIENTS.size());
+    private static final String CONSUL_HOST = System.getProperty("camel.consul.host", Consul.DEFAULT_HTTP_HOST);
+    private static final int CONSUL_PORT = Integer.getInteger("camel.consul.port", Consul.DEFAULT_HTTP_PORT);
+
+    // ************************************
+    // Test
+    // ************************************
+
+    @Test
+    public void test() throws Exception {
+        for (String id : CLIENTS) {
+            SCHEDULER.submit(() -> run(id));
+        }
+
+        LATCH.await(1, TimeUnit.MINUTES);
+        SCHEDULER.shutdownNow();
+
+        Assert.assertEquals(CLIENTS.size(), RESULTS.size());
+        Assert.assertTrue(RESULTS.containsAll(CLIENTS));
+    }
+
+    // ************************************
+    // Run a Camel node
+    // ************************************
+
+    private static void run(String id) {
+        try {
+            CountDownLatch contextLatch = new CountDownLatch(1);
+
+            ConsulClusterService service = new ConsulClusterService();
+            service.setId("node-" + id);
+            service.setUrl(String.format("http://%s:%d", CONSUL_HOST, CONSUL_PORT));
+
+            LOGGER.info("Consul URL {}", service.getUrl());
+
+            DefaultCamelContext context = new DefaultCamelContext();
+            context.disableJMX();
+            context.setName("context-" + id);
+            context.addService(service);
+            context.addRoutePolicyFactory(ClusteredRoutePolicyFactory.forNamespace("my-ns"));
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("timer:consul?delay=1s&period=1s&repeatCount=1")
+                        .routeId("route-" + id)
+                        .process(e -> {
+                            LOGGER.debug("Node {} done", id);
+                            RESULTS.add(id);
+                            // Shutdown the context later on to give a chance to
+                            // other members to catch-up
+                            SCHEDULER.schedule(contextLatch::countDown, 2 + ThreadLocalRandom.current().nextInt(3),
TimeUnit.SECONDS);
+                        });
+                }
+            });
+
+            // Start the context after some random time so the startup order
+            // changes for each test.
+            Thread.sleep(ThreadLocalRandom.current().nextInt(500));
+            context.start();
+
+            contextLatch.await();
+            context.stop();
+
+            LATCH.countDown();
+        } catch (Exception e) {
+            LOGGER.warn("", e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/61ad97f0/components/camel-consul/src/test/java/org/apache/camel/component/consul/ha/ConsulClusteredRoutePolicyTest.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ha/ConsulClusteredRoutePolicyTest.java
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ha/ConsulClusteredRoutePolicyTest.java
deleted file mode 100644
index cc6381c..0000000
--- a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ha/ConsulClusteredRoutePolicyTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * 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.component.consul.ha;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.impl.ha.ClusteredRoutePolicyFactory;
-import org.junit.Assert;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ConsulClusteredRoutePolicyTest {
-    private static final Logger LOGGER = LoggerFactory.getLogger(ConsulClusteredRoutePolicyTest.class);
-    private static final List<String> CLIENTS = IntStream.range(0, 3).mapToObj(Integer::toString).collect(Collectors.toList());
-    private static final List<String> RESULTS = new ArrayList<>();
-    private static final ScheduledExecutorService SCHEDULER = Executors.newScheduledThreadPool(CLIENTS.size()
* 2);
-    private static final CountDownLatch LATCH = new CountDownLatch(CLIENTS.size());
-
-    // ************************************
-    // Test
-    // ************************************
-
-    @Test
-    public void test() throws Exception {
-        for (String id : CLIENTS) {
-            SCHEDULER.submit(() -> run(id));
-        }
-
-        LATCH.await(1, TimeUnit.MINUTES);
-        SCHEDULER.shutdownNow();
-
-        Assert.assertEquals(CLIENTS.size(), RESULTS.size());
-        Assert.assertTrue(RESULTS.containsAll(CLIENTS));
-    }
-
-    // ************************************
-    // Run a Camel node
-    // ************************************
-
-    private static void run(String id) {
-        try {
-            CountDownLatch contextLatch = new CountDownLatch(1);
-
-            ConsulClusterService service = new ConsulClusterService();
-            service.setId("node-" + id);
-
-            DefaultCamelContext context = new DefaultCamelContext();
-            context.disableJMX();
-            context.setName("context-" + id);
-            context.addService(service);
-            context.addRoutePolicyFactory(ClusteredRoutePolicyFactory.forNamespace("my-ns"));
-            context.addRoutes(new RouteBuilder() {
-                @Override
-                public void configure() throws Exception {
-                    from("timer:consul?delay=1s&period=1s&repeatCount=1")
-                        .routeId("route-" + id)
-                        .process(e -> {
-                            LOGGER.debug("Node {} done", id);
-                            RESULTS.add(id);
-                            // Shutdown the context later on to give a chance to
-                            // other members to catch-up
-                            SCHEDULER.schedule(contextLatch::countDown, 2 + ThreadLocalRandom.current().nextInt(3),
TimeUnit.SECONDS);
-                        });
-                }
-            });
-
-            // Start the context after some random time so the startup order
-            // changes for each test.
-            Thread.sleep(ThreadLocalRandom.current().nextInt(500));
-            context.start();
-
-            contextLatch.await();
-            context.stop();
-
-            LATCH.countDown();
-        } catch (Exception e) {
-            LOGGER.warn("", e);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/61ad97f0/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index d7f65ad..6cd8784 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -182,6 +182,7 @@
     <dnsjava-bundle-version>2.1.8_1</dnsjava-bundle-version>
     <docker-java-version>3.0.10</docker-java-version>
     <docker-java-bundle-version>3.0.10_1</docker-java-bundle-version>
+    <docker-maven-plugin-version>0.21.0</docker-maven-plugin-version>
     <dom4j-bundle-version>1.6.1_5</dom4j-bundle-version>
     <dozer-version>6.0.0</dozer-version>
     <drools-version>6.5.0.Final</drools-version>


Mime
View raw message