From df5bc8974fc4962f05d8e79fe4a3250ac3d8921d Mon Sep 17 00:00:00 2001 From: sahner Date: Mon, 6 Jul 2015 14:15:15 -0500 Subject: [PATCH] add ability to get configuration information from a file --- integration-tests/README.md | 37 +++++- integration-tests/pom.xml | 33 ++++++ .../testing/ConfigFileConfigProvider.java | 112 ++++++++++++++++++ .../druid/testing/DockerConfigProvider.java | 8 +- .../testing/IntegrationTestingConfig.java | 2 + .../IntegrationTestingConfigProvider.java | 3 +- .../testing/clients/ZookeeperTestClient.java | 38 ++++++ 7 files changed, 228 insertions(+), 5 deletions(-) create mode 100644 integration-tests/src/main/java/io/druid/testing/ConfigFileConfigProvider.java create mode 100644 integration-tests/src/main/java/io/druid/testing/clients/ZookeeperTestClient.java diff --git a/integration-tests/README.md b/integration-tests/README.md index 261f5908430..65aeb0a4263 100644 --- a/integration-tests/README.md +++ b/integration-tests/README.md @@ -31,18 +31,49 @@ docker info Running Integration tests ========================= -## Running tests using mvn +## Starting docker tests -To run all the tests using mvn run the following command - +To run all the tests using docker and mvn run the following command - ``` mvn verify -P integration-tests ``` -To run only a single test using mvn run following command - +To run only a single test using mvn run the following command - ``` mvn verify -P integration-tests -Dit.test= ``` +## Configure and run integration tests using existing cluster + +To run tests on any druid cluster that is already running, create a configuration file: + + { + "broker_host": "", + "broker_port": "", + "router_host": "", + "router_port": "", + "indexer_host": "", + "indexer_port": "", + "coordinator_host": "", + "coordinator_port": "", + "middle_manager_host": "", + "zookeeper_hosts": "", + } + +Set the environment variable CONFIG_FILE to the name of the configuration file - +``` +export CONFIG_FILE= +``` + +To run all the tests using mvn run the following command - +``` + mvn verify -P int-tests-config-file +``` + +To run only a single test using mvn run the following command - +``` + mvn verify -P int-tests-config-file -Dit.test= +``` Writing a New Test =============== diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 93d74314464..e60262fd3f5 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -147,6 +147,39 @@ + + int-tests-config-file + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + integration-tests + integration-test + + integration-test + verify + + + + + + -Duser.timezone=UTC + -Dfile.encoding=UTF-8 + -Dtestrunfactory=org.testng.DruidTestRunnerFactory + -Ddruid.test.config.type=configFile + -Ddruid.test.config.configFile=${env.CONFIG_FILE} + + + src/test/resources/testng.xml + + + + + + diff --git a/integration-tests/src/main/java/io/druid/testing/ConfigFileConfigProvider.java b/integration-tests/src/main/java/io/druid/testing/ConfigFileConfigProvider.java new file mode 100644 index 00000000000..e174c0471a4 --- /dev/null +++ b/integration-tests/src/main/java/io/druid/testing/ConfigFileConfigProvider.java @@ -0,0 +1,112 @@ +/* +* Licensed to Metamarkets Group Inc. (Metamarkets) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. Metamarkets 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 io.druid.testing; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.FileNotFoundException; +import java.io.File; +import java.io.IOException; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.Map; + +public class ConfigFileConfigProvider implements IntegrationTestingConfigProvider +{ + private String routerHost = ""; + private String brokerHost = ""; + private String coordinatorHost = ""; + private String indexerHost = ""; + private String middleManagerHost = ""; + private String zookeeperHosts = ""; + private Map props = null; + + @JsonCreator + ConfigFileConfigProvider(@JsonProperty("configFile") String configFile){ + loadProperties(configFile); + } + + private void loadProperties(String configFile) + { + ObjectMapper jsonMapper = new ObjectMapper(); + try { + props = jsonMapper.readValue( + new File(configFile), new TypeReference>() + { + } + ); + } + catch (IOException ex) { + throw new RuntimeException(ex); + } + routerHost = props.get("router_host") + ":" + props.get("router_port"); + brokerHost = props.get("broker_host") + ":" + props.get("broker_port"); + coordinatorHost = props.get("coordinator_host") + ":" + props.get("coordinator_port"); + indexerHost = props.get("indexer_host") + ":" + props.get("indexer_port"); + middleManagerHost = props.get("middle_manager_host"); + zookeeperHosts = props.get("zookeeper_hosts"); + } + + @Override + public IntegrationTestingConfig get() + { + return new IntegrationTestingConfig() + { + @Override + public String getCoordinatorHost() + { + return coordinatorHost; + } + + @Override + public String getIndexerHost() + { + return indexerHost; + } + + @Override + public String getRouterHost() + { + return routerHost; + } + + @Override + public String getBrokerHost() + { + return brokerHost; + } + + @Override + public String getMiddleManagerHost() + { + return middleManagerHost; + } + + @Override + public String getZookeeperHosts() + { + return zookeeperHosts; + } + }; + } +} diff --git a/integration-tests/src/main/java/io/druid/testing/DockerConfigProvider.java b/integration-tests/src/main/java/io/druid/testing/DockerConfigProvider.java index 362ac596b5e..f0a557ce8f0 100644 --- a/integration-tests/src/main/java/io/druid/testing/DockerConfigProvider.java +++ b/integration-tests/src/main/java/io/druid/testing/DockerConfigProvider.java @@ -22,7 +22,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import javax.validation.constraints.NotNull; -public class DockerConfigProvider implements IntegrationTestingConfigProvider +public class DockerConfigProvider implements IntegrationTestingConfigProvider { @JsonProperty @@ -63,6 +63,12 @@ public class DockerConfigProvider implements IntegrationTestingConfigProvider { return dockerIp; } + + @Override + public String getZookeeperHosts() + { + return dockerIp + ":2181"; + } }; } } diff --git a/integration-tests/src/main/java/io/druid/testing/IntegrationTestingConfig.java b/integration-tests/src/main/java/io/druid/testing/IntegrationTestingConfig.java index 9250ae1fcf9..85b9e0a7ba4 100644 --- a/integration-tests/src/main/java/io/druid/testing/IntegrationTestingConfig.java +++ b/integration-tests/src/main/java/io/druid/testing/IntegrationTestingConfig.java @@ -30,4 +30,6 @@ public interface IntegrationTestingConfig public String getBrokerHost(); public String getMiddleManagerHost(); + + public String getZookeeperHosts(); } diff --git a/integration-tests/src/main/java/io/druid/testing/IntegrationTestingConfigProvider.java b/integration-tests/src/main/java/io/druid/testing/IntegrationTestingConfigProvider.java index 0630f7fc4f2..18a5889a38b 100644 --- a/integration-tests/src/main/java/io/druid/testing/IntegrationTestingConfigProvider.java +++ b/integration-tests/src/main/java/io/druid/testing/IntegrationTestingConfigProvider.java @@ -23,7 +23,8 @@ import com.google.inject.Provider; @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = DockerConfigProvider.class) @JsonSubTypes(value = { - @JsonSubTypes.Type(name = "docker", value = DockerConfigProvider.class) + @JsonSubTypes.Type(name = "docker", value = DockerConfigProvider.class), + @JsonSubTypes.Type(name = "configFile", value = ConfigFileConfigProvider.class) }) public interface IntegrationTestingConfigProvider extends Provider { diff --git a/integration-tests/src/main/java/io/druid/testing/clients/ZookeeperTestClient.java b/integration-tests/src/main/java/io/druid/testing/clients/ZookeeperTestClient.java new file mode 100644 index 00000000000..6f232c14810 --- /dev/null +++ b/integration-tests/src/main/java/io/druid/testing/clients/ZookeeperTestClient.java @@ -0,0 +1,38 @@ +/* + * Druid - a distributed column store. + * + * 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 io.druid.testing.clients; + +import com.google.inject.Inject; +import io.druid.testing.IntegrationTestingConfig; + +public class ZookeeperTestClient +{ + private final String hosts; + + @Inject + ZookeeperTestClient( + IntegrationTestingConfig config + ) + { + this.hosts = config.getZookeeperHosts(); + } + + public String getZookeeperHosts() + { + return hosts; + } +}