camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lburgazz...@apache.org
Subject [camel] branch master updated: Fix camel-zookeeper-starter test and duplicated classes
Date Fri, 15 Jun 2018 14:58:59 GMT
This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new f3315d20 Fix camel-zookeeper-starter test and duplicated classes
f3315d20 is described below

commit f3315d206889a164ee0f7336c7441462d0f09f6c
Author: lburgazzoli <lburgazzoli@gmail.com>
AuthorDate: Fri Jun 15 16:58:28 2018 +0200

    Fix camel-zookeeper-starter test and duplicated classes
---
 .../camel-zookeeper-starter/pom.xml                |  12 +++
 .../ZooKeeperClusterServiceAutoConfiguration.java  |  53 ----------
 .../ZooKeeperClusterServiceConfiguration.java      |  77 ---------------
 .../cloud/ZooKeeperServiceRegistryTest.java        | 110 ++-------------------
 .../cluster/ZooKeeperClusterServiceTest.java       |  89 +++++++++++++++++
 platforms/spring-boot/spring-boot-dm/pom.xml       |   3 +
 6 files changed, 111 insertions(+), 233 deletions(-)

diff --git a/platforms/spring-boot/components-starter/camel-zookeeper-starter/pom.xml b/platforms/spring-boot/components-starter/camel-zookeeper-starter/pom.xml
index 7c274d2..b6210ce 100644
--- a/platforms/spring-boot/components-starter/camel-zookeeper-starter/pom.xml
+++ b/platforms/spring-boot/components-starter/camel-zookeeper-starter/pom.xml
@@ -39,6 +39,18 @@
       <artifactId>camel-zookeeper</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.curator</groupId>
+      <artifactId>curator-test</artifactId>
+      <version>${curator-version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.zookeeper</groupId>
+          <artifactId>zookeeper</artifactId>
+        </exclusion>
+      </exclusions>
+      <scope>test</scope>
+    </dependency>
     <!--START OF GENERATED CODE-->
     <dependency>
       <groupId>org.apache.camel</groupId>
diff --git a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceAutoConfiguration.java
b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceAutoConfiguration.java
deleted file mode 100644
index c34d82e..0000000
--- a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceAutoConfiguration.java
+++ /dev/null
@@ -1,53 +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.zookeeper.cluster.springboot;
-
-import org.apache.camel.cluster.CamelClusterService;
-import org.apache.camel.component.zookeeper.cluster.ZooKeeperClusterService;
-import org.apache.camel.spring.boot.CamelAutoConfiguration;
-import org.apache.camel.spring.boot.cluster.ClusteredRouteControllerAutoConfiguration;
-import org.apache.camel.util.IntrospectionSupport;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;
-import org.springframework.boot.autoconfigure.AutoConfigureBefore;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Scope;
-
-@Configuration
-@AutoConfigureBefore({ ClusteredRouteControllerAutoConfiguration.class, CamelAutoConfiguration.class
})
-@ConditionalOnProperty(prefix = "camel.component.zookeeper.cluster.service", name = "enabled")
-@EnableConfigurationProperties(ZooKeeperClusterServiceConfiguration.class)
-public class ZooKeeperClusterServiceAutoConfiguration {
-    @Autowired
-    private ZooKeeperClusterServiceConfiguration configuration;
-
-    @Bean(name = "zookeeper-cluster-service")
-    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
-    public CamelClusterService zookeeperClusterService() throws Exception {
-        ZooKeeperClusterService service = new ZooKeeperClusterService();
-
-        IntrospectionSupport.setProperties(
-            service,
-            IntrospectionSupport.getNonNullProperties(configuration)
-        );
-
-        return service;
-    }
-}
diff --git a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceConfiguration.java
b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceConfiguration.java
deleted file mode 100644
index 1feb5af..0000000
--- a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/main/java/org/apache/camel/component/zookeeper/cluster/springboot/ZooKeeperClusterServiceConfiguration.java
+++ /dev/null
@@ -1,77 +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.zookeeper.cluster.springboot;
-
-import java.util.Map;
-
-import org.apache.camel.component.zookeeper.ZooKeeperCuratorConfiguration;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-@ConfigurationProperties(prefix = "camel.component.zookeeper.cluster.service")
-public class ZooKeeperClusterServiceConfiguration extends ZooKeeperCuratorConfiguration {
-    /**
-     * Sets if the zookeeper cluster service should be enabled or not, default is false.
-     */
-    private boolean enabled;
-
-    /**
-     * Cluster Service ID
-     */
-    private String id;
-
-    /**
-     * Custom service attributes.
-     */
-    private Map<String, Object> attributes;
-    
-    /**
-     * Service lookup order/priority.
-     */
-    private Integer order;
-
-    public boolean isEnabled() {
-        return enabled;
-    }
-
-    public void setEnabled(boolean enabled) {
-        this.enabled = enabled;
-    }
-
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public Map<String, Object> getAttributes() {
-        return attributes;
-    }
-
-    public void setAttributes(Map<String, Object> attributes) {
-        this.attributes = attributes;
-    }
-
-    public Integer getOrder() {
-        return order;
-    }
-
-    public void setOrder(Integer order) {
-        this.order = order;
-    }
-}
diff --git a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/test/java/org/apache/camel/component/zookeeper/springboot/cloud/ZooKeeperServiceRegistryTest.java
b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/test/java/org/apache/camel/component/zookeeper/springboot/cloud/ZooKeeperServiceRegistryTest.java
index 7243d61..76a6e87 100644
--- a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/test/java/org/apache/camel/component/zookeeper/springboot/cloud/ZooKeeperServiceRegistryTest.java
+++ b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/test/java/org/apache/camel/component/zookeeper/springboot/cloud/ZooKeeperServiceRegistryTest.java
@@ -16,13 +16,7 @@
  */
 package org.apache.camel.component.zookeeper.springboot.cloud;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.InetSocketAddress;
-import java.net.Socket;
 import java.util.Collection;
 import java.util.UUID;
 
@@ -31,18 +25,15 @@ import org.apache.camel.cloud.ServiceRegistry;
 import org.apache.camel.component.zookeeper.cloud.ZooKeeperServiceRegistry;
 import org.apache.camel.impl.cloud.DefaultServiceDefinition;
 import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.util.IOHelper;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.retry.ExponentialBackoffRetry;
+import org.apache.curator.test.TestingServer;
 import org.apache.curator.utils.CloseableUtils;
 import org.apache.curator.x.discovery.ServiceDiscovery;
 import org.apache.curator.x.discovery.ServiceDiscoveryBuilder;
 import org.apache.curator.x.discovery.ServiceInstance;
 import org.apache.curator.x.discovery.details.JsonInstanceSerializer;
-import org.apache.zookeeper.server.NIOServerCnxnFactory;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.apache.zookeeper.server.persistence.FileTxnSnapLog;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -72,10 +63,13 @@ public class ZooKeeperServiceRegistryTest {
 
     @Test
     public void testServiceRegistry() throws Exception {
-        final ZooKeeperTestServer zkServer = new ZooKeeperTestServer(temporaryFolder.newFolder());
+        final int zkPort =  AvailablePortFinder.getNextAvailable();
+        final File zkDir =  temporaryFolder.newFolder();
+
+        final TestingServer zkServer = new TestingServer(zkPort, zkDir);
         zkServer.start();
 
-        final ZooKeeperTestClient zkClient = new ZooKeeperTestClient(zkServer.serverList());
+        final ZooKeeperTestClient zkClient = new ZooKeeperTestClient("localhost:" + zkPort);
         zkClient.start();
 
         try {
@@ -86,7 +80,7 @@ public class ZooKeeperServiceRegistryTest {
                     "spring.main.banner-mode=OFF",
                     "spring.application.name=" + UUID.randomUUID().toString(),
                     "camel.component.zookeeper.service-registry.enabled=true",
-                    "camel.component.zookeeper.service-registry.nodes=" + zkServer.serverList(),
+                    "camel.component.zookeeper.service-registry.nodes=localhost:" + zkPort,
                     "camel.component.zookeeper.service-registry.id=" + UUID.randomUUID().toString(),
                     "camel.component.zookeeper.service-registry.base-path=" + SERVICE_PATH,
                     "camel.component.zookeeper.service-registry.service-host=localhost")
@@ -137,96 +131,6 @@ public class ZooKeeperServiceRegistryTest {
     // Helpers
     // *************************************
 
-    public static class ZooKeeperTestServer {
-        private NIOServerCnxnFactory connectionFactory;
-        private ZooKeeperServer zkServer;
-
-        public ZooKeeperTestServer(File root) throws Exception {
-            zkServer = new ZooKeeperServer();
-
-            File dataDir = new File(root, "log");
-            File snapDir = new File(root, "data");
-            FileTxnSnapLog ftxn = new FileTxnSnapLog(dataDir, snapDir);
-
-            zkServer.setTxnLogFactory(ftxn);
-            zkServer.setTickTime(1000);
-
-            connectionFactory = new NIOServerCnxnFactory();
-            connectionFactory.configure(new InetSocketAddress("localhost", AvailablePortFinder.getNextAvailable()),
0);
-            connectionFactory.startup(zkServer);
-        }
-
-        public String serverList() {
-            return "localhost:" + connectionFactory.getLocalPort();
-        }
-
-        private String send4LetterWord(String hp, String cmd) throws IOException {
-            String split[] = hp.split(":");
-            String host = split[0];
-            int port;
-            try {
-                port = Integer.parseInt(split[1]);
-            } catch (RuntimeException e) {
-                throw new RuntimeException("Problem parsing " + hp + e.toString());
-            }
-
-            Socket sock = new Socket(host, port);
-            BufferedReader reader = null;
-            try {
-                OutputStream outstream = sock.getOutputStream();
-                outstream.write(cmd.getBytes());
-                outstream.flush();
-
-                reader = IOHelper.buffered(new InputStreamReader(sock.getInputStream()));
-                StringBuilder sb = new StringBuilder();
-                String line;
-                while ((line = reader.readLine()) != null) {
-                    sb.append(line + "\n");
-                }
-                return sb.toString();
-            } finally {
-                sock.close();
-                if (reader != null) {
-                    reader.close();
-                }
-            }
-        }
-
-        public void start() throws Exception {
-            long start = System.currentTimeMillis();
-            while (true) {
-                try {
-                    String result = send4LetterWord(serverList(), "stat");
-                    if (result.startsWith("Zookeeper version:")) {
-                        return;
-                    }
-                } catch (IOException e) {
-                    LOGGER.info("server {} not up {}", LOGGER, e);
-                }
-
-                if (System.currentTimeMillis() > start + 1000) {
-                    break;
-                }
-                try {
-                    Thread.sleep(250);
-                } catch (InterruptedException e) {
-                    // ignore
-                }
-            }
-        }
-
-        public void stop() throws Exception {
-            connectionFactory.shutdown();
-            connectionFactory.join();
-            zkServer.shutdown();
-
-            while (zkServer.isRunning()) {
-                zkServer.shutdown();
-                Thread.sleep(100);
-            }
-        }
-    }
-
     public static class ZooKeeperTestClient {
         private final CuratorFramework curator;
         private final ServiceDiscovery<ZooKeeperServiceRegistry.MetaData> discovery;
diff --git a/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/test/java/org/apache/camel/component/zookeeper/springboot/cluster/ZooKeeperClusterServiceTest.java
b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/test/java/org/apache/camel/component/zookeeper/springboot/cluster/ZooKeeperClusterServiceTest.java
new file mode 100644
index 0000000..be031a3
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-zookeeper-starter/src/test/java/org/apache/camel/component/zookeeper/springboot/cluster/ZooKeeperClusterServiceTest.java
@@ -0,0 +1,89 @@
+/**
+ * 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.zookeeper.springboot.cluster;
+
+import java.io.File;
+import java.util.UUID;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cluster.CamelClusterService;
+import org.apache.camel.component.zookeeper.cluster.ZooKeeperClusterService;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.curator.test.TestingServer;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.runner.ApplicationContextRunner;
+import org.springframework.context.annotation.Configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ZooKeeperClusterServiceTest {
+    private static final String SERVICE_PATH = "/camel";
+
+    @Rule
+    public final TestName testName = new TestName();
+    @Rule
+    public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+    @Test
+    public void testClusterService() throws Exception {
+        final int zkPort =  AvailablePortFinder.getNextAvailable();
+        final File zkDir =  temporaryFolder.newFolder();
+
+        final TestingServer zkServer = new TestingServer(zkPort, zkDir);
+        zkServer.start();
+
+        try {
+            new ApplicationContextRunner()
+                .withUserConfiguration(TestConfiguration.class)
+                .withPropertyValues(
+                    "debug=false",
+                    "spring.main.banner-mode=OFF",
+                    "spring.application.name=" + UUID.randomUUID().toString(),
+                    "camel.component.zookeeper.cluster.service.enabled=true",
+                    "camel.component.zookeeper.cluster.service.nodes=localhost:" + zkPort,
+                    "camel.component.zookeeper.cluster.service.id=" + UUID.randomUUID().toString(),
+                    "camel.component.zookeeper.cluster.service.base-path=" + SERVICE_PATH)
+                .run(
+                    context -> {
+                        assertThat(context).hasSingleBean(CamelContext.class);
+                        assertThat(context).hasSingleBean(CamelClusterService.class);
+
+                        final CamelContext camelContext = context.getBean(CamelContext.class);
+                        final CamelClusterService clusterService = camelContext.hasService(CamelClusterService.class);
+
+                        assertThat(clusterService).isNotNull();
+                        assertThat(clusterService).isInstanceOf(ZooKeeperClusterService.class);
+                    }
+                );
+        } finally {
+            zkServer.stop();
+        }
+    }
+
+    // *************************************
+    // Config
+    // *************************************
+
+    @EnableAutoConfiguration
+    @Configuration
+    public static class TestConfiguration {
+    }
+}
diff --git a/platforms/spring-boot/spring-boot-dm/pom.xml b/platforms/spring-boot/spring-boot-dm/pom.xml
index 2c03911..634ca47 100644
--- a/platforms/spring-boot/spring-boot-dm/pom.xml
+++ b/platforms/spring-boot/spring-boot-dm/pom.xml
@@ -49,6 +49,9 @@
     <jackson-version>1.9.12</jackson-version>
     <testcontainers-version>1.7.3</testcontainers-version>
 
+    <!-- needed for testing -->
+    <curator-version>2.12.0</curator-version>
+
     <!-- Needed by starters -->
     <egit-github-core-version>2.1.5</egit-github-core-version>
     <google-guava-version>19.0</google-guava-version>

-- 
To stop receiving notification emails like this one, please contact
lburgazzoli@apache.org.

Mime
View raw message