From bdf3150bd5824d36fe7cc6076928045928bda97e Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Wed, 7 Apr 2021 01:35:58 +0800 Subject: [PATCH 01/17] try test container --- .../resources/conf/iotdb-cluster.properties | 6 +- .../iotdb/cluster/config/ClusterConfig.java | 24 +++- docker/src/main/Dockerfile-cluster | 43 +++++++ .../main/{Dockerfile => Dockerfile-single} | 2 +- pom.xml | 36 ++++++ .../test/resources/testcontainers.properties | 17 +++ test/e2e/base/docker-compose.yaml | 4 +- testcontainer/pom.xml | 118 ++++++++++++++++++ .../org/apache/iotdb/db/sql/ClusterE2E.java | 80 ++++++++++++ .../apache/iotdb/db/sql/SingleNodeE2E.java | 85 +++++++++++++ .../NoProjectNameDockerComposeContainer.java | 38 ++++++ .../test/resources/1node/docker-compose.yaml | 43 +++++++ .../resources/1node/iotdb-cluster.properties | 35 ++++++ .../test/resources/3nodes/docker-compose.yaml | 43 +++++++ .../resources/3nodes/iotdb-cluster.properties | 35 ++++++ .../test/resources/5nodes/docker-compose.yaml | 42 +++++++ .../resources/5nodes/iotdb-cluster.properties | 35 ++++++ .../test/resources/iotdb-engine.properties | 24 ++++ 18 files changed, 700 insertions(+), 10 deletions(-) create mode 100644 docker/src/main/Dockerfile-cluster rename docker/src/main/{Dockerfile => Dockerfile-single} (95%) create mode 100644 server/src/test/resources/testcontainers.properties create mode 100644 testcontainer/pom.xml create mode 100644 testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java create mode 100644 testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java create mode 100644 testcontainer/src/test/java/org/testcontainers/containers/NoProjectNameDockerComposeContainer.java create mode 100644 testcontainer/src/test/resources/1node/docker-compose.yaml create mode 100644 testcontainer/src/test/resources/1node/iotdb-cluster.properties create mode 100644 testcontainer/src/test/resources/3nodes/docker-compose.yaml create mode 100644 testcontainer/src/test/resources/3nodes/iotdb-cluster.properties create mode 100644 testcontainer/src/test/resources/5nodes/docker-compose.yaml create mode 100644 testcontainer/src/test/resources/5nodes/iotdb-cluster.properties create mode 100644 testcontainer/src/test/resources/iotdb-engine.properties diff --git a/cluster/src/assembly/resources/conf/iotdb-cluster.properties b/cluster/src/assembly/resources/conf/iotdb-cluster.properties index 73e7b423082e..3819dcc706be 100644 --- a/cluster/src/assembly/resources/conf/iotdb-cluster.properties +++ b/cluster/src/assembly/resources/conf/iotdb-cluster.properties @@ -29,6 +29,7 @@ #-------------------------------------------IMPORTANT---------------------------------------------# # used for communication between cluster nodes, eg heartbeat、raft logs and snapshots etc. +# if this parameter is commented, then the IP that binded by the hostname will be used. internal_ip=127.0.0.1 # port for metadata service @@ -51,7 +52,8 @@ open_server_rpc_port=false # nodes that already in the cluster, unnecessary to be the nodes that were used to build the # initial cluster by start-node.sh(.bat). Several nodes will be picked randomly to send the # request, the number of nodes picked depends on the number of retries. -seed_nodes=127.0.0.1:9003,127.0.0.1:9005,127.0.0.1:9007 +#seed_nodes=127.0.0.1:9003,127.0.0.1:9005,127.0.0.1:9007 +seed_nodes=127.0.0.1:9003 # whether to use thrift compressed protocol for internal communications. If you want to change # compression settings for external clients, please modify 'rpc_thrift_compression_enable' in @@ -65,7 +67,7 @@ rpc_thrift_compression_enable=false max_concurrent_client_num=10000 # number of replications for one partition -default_replica_num=3 +default_replica_num=1 # cluster name to identify different clusters # all node's cluster_name in one cluster are the same diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java index 11cedc8022c0..2f4215e8f2ae 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java @@ -21,27 +21,31 @@ import org.apache.iotdb.cluster.utils.ClusterConsistent; import org.apache.iotdb.db.conf.IoTDBDescriptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; public class ClusterConfig { - + private static Logger logger = LoggerFactory.getLogger(ClusterConfig.class); static final String CONFIG_NAME = "iotdb-cluster.properties"; - private String internalIp = "127.0.0.1"; + private String internalIp; private int internalMetaPort = 9003; private int internalDataPort = 40010; private int clusterRpcPort = IoTDBDescriptor.getInstance().getConfig().getRpcPort(); /** each one is a {internalIp | domain name}:{meta port} string tuple. */ - private List seedNodeUrls = - Arrays.asList(String.format("%s:%d", internalIp, internalMetaPort)); + private List seedNodeUrls; @ClusterConsistent private boolean isRpcThriftCompressionEnabled = false; private int maxConcurrentClientNum = 10000; - @ClusterConsistent private int replicationNum = 3; + @ClusterConsistent private int replicationNum = 1; @ClusterConsistent private String clusterName = "default"; @@ -164,6 +168,16 @@ public class ClusterConfig { private boolean openServerRpcPort = false; + public ClusterConfig() { + try { + internalIp = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + logger.error(e.getMessage()); + internalIp = "127.0.0.1"; + } + seedNodeUrls = Arrays.asList(String.format("%s:%d", internalIp, internalMetaPort)); + } + public int getSelectorNumOfClientPool() { return selectorNumOfClientPool; } diff --git a/docker/src/main/Dockerfile-cluster b/docker/src/main/Dockerfile-cluster new file mode 100644 index 000000000000..277132b6eab2 --- /dev/null +++ b/docker/src/main/Dockerfile-cluster @@ -0,0 +1,43 @@ +# +# 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. +# + +# docker build context is the root path of the repository + +FROM openjdk:11-jre-slim + +ADD distribution/target/apache-iotdb-*-cluster-bin.zip / + +RUN apt update \ + && apt install lsof procps unzip -y \ + && unzip /apache-iotdb-*-bin.zip -d / \ + && rm /apache-iotdb-*-bin.zip \ + && mv /apache-iotdb-* /iotdb \ + && apt remove unzip -y \ + && apt autoremove -y \ + && apt purge --auto-remove -y \ + && apt clean -y + +EXPOSE 6667 +EXPOSE 31999 +EXPOSE 5555 +EXPOSE 8181 +VOLUME /iotdb/data +VOLUME /iotdb/logs +ENV PATH="/iotdb/sbin/:/iotdb/tools/:${PATH}" +ENTRYPOINT ["/iotdb/sbin/start-node.sh"] diff --git a/docker/src/main/Dockerfile b/docker/src/main/Dockerfile-single similarity index 95% rename from docker/src/main/Dockerfile rename to docker/src/main/Dockerfile-single index 402227c64d18..c0e00a951760 100644 --- a/docker/src/main/Dockerfile +++ b/docker/src/main/Dockerfile-single @@ -21,7 +21,7 @@ FROM openjdk:11-jre-slim -ADD distribution/target/apache-iotdb-*-all-bin.zip / +ADD distribution/target/apache-iotdb-*-server-bin.zip / RUN apt update \ && apt install lsof procps unzip -y \ diff --git a/pom.xml b/pom.xml index 1c2b0f3b3674..eb27a4243862 100644 --- a/pom.xml +++ b/pom.xml @@ -508,6 +508,12 @@ mockito-all test + + org.testcontainers + testcontainers + 1.15.2 + test + @@ -898,6 +904,7 @@ src/test/**/*IT.java + src/test/**/*E2E.java @@ -911,7 +918,12 @@ src/test/**/*IT.java + src/test/**/*E2E.java + + + src/test/**/*Test.java + @@ -991,6 +1003,30 @@ +x ${project.build.directory}/tools/${thrift.executable} + + + + unixDockerCheck + + + /var/run/docker.sock + + + + testcontainer + + + + WinDockerCheck + + + C:\Program Files\Docker\Docker\resources\bin\docker.exe + + + + testcontainer + + java-11-and-above diff --git a/server/src/test/resources/testcontainers.properties b/server/src/test/resources/testcontainers.properties new file mode 100644 index 000000000000..af6effe66acd --- /dev/null +++ b/server/src/test/resources/testcontainers.properties @@ -0,0 +1,17 @@ +#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. + diff --git a/test/e2e/base/docker-compose.yaml b/test/e2e/base/docker-compose.yaml index d4970d45adbc..08ebc3b03440 100644 --- a/test/e2e/base/docker-compose.yaml +++ b/test/e2e/base/docker-compose.yaml @@ -23,7 +23,7 @@ services: server-prototype: build: context: ../../.. - dockerfile: docker/src/main/Dockerfile + dockerfile: ../../../docker/src/main/Dockerfile-single ports: - 6667:6667 networks: @@ -37,7 +37,7 @@ services: initializer: build: context: ../../.. - dockerfile: docker/src/main/Dockerfile + dockerfile: ../../../docker/src/main/Dockerfile-single networks: iotdb: entrypoint: diff --git a/testcontainer/pom.xml b/testcontainer/pom.xml new file mode 100644 index 000000000000..f8bb9f60e791 --- /dev/null +++ b/testcontainer/pom.xml @@ -0,0 +1,118 @@ + + + + org.apache.iotdb + iotdb-parent + 0.12.0-SNAPSHOT + ../pom.xml + + 4.0.0 + testcontainer + + false + docker + build -t apache/iotdb:maven-development -f ${basedir}/../docker/src/main/Dockerfile-single ${basedir}/../. + image rm apache/iotdb:maven-development + build -t apache/iotdb:cluster-maven-development -f ${basedir}/../docker/src/main/Dockerfile-cluster ${basedir}/../. + image rm apache/iotdb:cluster-maven-development + + + + org.apache.iotdb + iotdb-jdbc + ${project.version} + test + + + org.apache.iotdb + iotdb-session + ${project.version} + test + + + org.apache.iotdb + iotdb-cli + ${project.version} + test + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + build-docker-image + pre-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.build.single.argument} + + + + build-cluster-docker-image + pre-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.build.cluster.argument} + + + + clean-docker-image + post-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.clean.single.argument} + + + + clean-cluster-docker-image + post-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.clean.cluster.argument} + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + add-test-container-source + generate-test-sources + + add-test-source + + + + ${basedir}/src/test/java + + + + + + + + diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java new file mode 100644 index 000000000000..44c0d082d3c3 --- /dev/null +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java @@ -0,0 +1,80 @@ +/* + * 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.iotdb.db.sql; + +import org.apache.iotdb.jdbc.Config; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.NoProjectNameDockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; + +public class ClusterE2E { + private Statement statement; + private Connection connection; + + @Rule + public DockerComposeContainer environment = + new NoProjectNameDockerComposeContainer( + "3nodes", new File("src/test/resources/3nodes/docker-compose.yaml")) + .withExposedService("iotdb-server_1", 6667, Wait.forListeningPort()) + .withExposedService("iotdb-server_2", 6667, Wait.forListeningPort()) + .withExposedService("iotdb-server_3", 6667, Wait.forListeningPort()) + .withLocalCompose(true); + + int rpcPort = 6667; + + @Before + public void setUp() throws Exception { + + String ip = environment.getServiceHost("iotdb-server_1", 6667); + rpcPort = environment.getServicePort("iotdb-server_1", 6667); + + Class.forName(Config.JDBC_DRIVER_NAME); + connection = DriverManager.getConnection("jdbc:iotdb://" + ip + ":" + rpcPort, "root", "root"); + statement = connection.createStatement(); + } + + @After + public void tearDown() throws Exception { + statement.close(); + connection.close(); + } + + @Test + public void testSimplePutAndGet() throws SQLException { + String[] timeSeriesArray = {"root.sg1.aa.bb", "root.sg1.aa.bb.cc", "root.sg1.aa"}; + + for (String timeSeries : timeSeriesArray) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + timeSeries)); + } + } +} diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java new file mode 100644 index 000000000000..7a4705a681a3 --- /dev/null +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java @@ -0,0 +1,85 @@ +/* + * 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.iotdb.db.sql; + +import org.apache.iotdb.jdbc.Config; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.images.PullPolicy; +import org.testcontainers.utility.DockerImageName; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; + +public class SingleNodeE2E { + private Statement statement; + private Connection connection; + + @Rule + public GenericContainer dslContainer = + new GenericContainer(DockerImageName.parse("apache/iotdb:maven-development")) + .withImagePullPolicy(PullPolicy.defaultPolicy()) + // mount another properties for changing parameters, e.g., open 5555 port (sync module) + .withFileSystemBind( + new File("src/test/resources/iotdb-engine.properties").getAbsolutePath(), + "/iotdb/conf/iotdb-engine.properties", + BindMode.READ_ONLY) + .withExposedPorts(6667) + .waitingFor(Wait.forListeningPort()); + + int rpcPort = 6667; + int syncPort = 5555; + + @Before + public void setUp() throws Exception { + rpcPort = dslContainer.getMappedPort(6667); + + syncPort = dslContainer.getMappedPort(5555); + Class.forName(Config.JDBC_DRIVER_NAME); + connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:" + rpcPort, "root", "root"); + statement = connection.createStatement(); + } + + @After + public void tearDown() throws Exception { + statement.close(); + connection.close(); + } + + @Test + public void testSimplePutAndGet() throws SQLException { + String[] timeSeriesArray = {"root.sg1.aa.bb", "root.sg1.aa.bb.cc", "root.sg1.aa"}; + + for (String timeSeries : timeSeriesArray) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + timeSeries)); + } + } +} diff --git a/testcontainer/src/test/java/org/testcontainers/containers/NoProjectNameDockerComposeContainer.java b/testcontainer/src/test/java/org/testcontainers/containers/NoProjectNameDockerComposeContainer.java new file mode 100644 index 000000000000..0d1fa76a8337 --- /dev/null +++ b/testcontainer/src/test/java/org/testcontainers/containers/NoProjectNameDockerComposeContainer.java @@ -0,0 +1,38 @@ +/* + * 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.testcontainers.containers; + +import java.io.File; +import java.lang.reflect.Field; + +public class NoProjectNameDockerComposeContainer extends DockerComposeContainer { + + public NoProjectNameDockerComposeContainer(String identifier, File... composeFiles) { + super(identifier, composeFiles); + Field project = null; + try { + project = DockerComposeContainer.class.getDeclaredField("project"); + project.setAccessible(true); + project.set(this, ""); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/testcontainer/src/test/resources/1node/docker-compose.yaml b/testcontainer/src/test/resources/1node/docker-compose.yaml new file mode 100644 index 000000000000..9803930643ec --- /dev/null +++ b/testcontainer/src/test/resources/1node/docker-compose.yaml @@ -0,0 +1,43 @@ +# +# 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. +# + +version: '3.8' + +services: + iotdb-server: + image: apache/iotdb:cluster-maven-development + expose: + - 6667 + - 9003 + - 40010 + networks: + - iotdb + healthcheck: + test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/6667" ] + interval: 5s + timeout: 60s + retries: 120 + volumes: + - ./iotdb-cluster.properties:/iotdb/conf/iotdb-cluster.properties + scale: 1 + + +networks: + iotdb: + driver: bridge diff --git a/testcontainer/src/test/resources/1node/iotdb-cluster.properties b/testcontainer/src/test/resources/1node/iotdb-cluster.properties new file mode 100644 index 000000000000..2df52cce86cc --- /dev/null +++ b/testcontainer/src/test/resources/1node/iotdb-cluster.properties @@ -0,0 +1,35 @@ +# +# 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. + +internal_meta_port=9003 +internal_data_port=40010 +seed_nodes=3nodes_iotdb-server_1:9003 +default_replica_num=1 +consistency_level=mid +connection_timeout_ms=20000 +write_operation_timeout_ms=30000 +read_operation_timeout_ms=30000 +catch_up_timeout_ms=300000 +use_batch_in_catch_up=true +min_num_of_logs_in_mem=1000 +max_num_of_logs_in_mem=2000 +log_deletion_check_interval_second=-1 +is_use_async_server=false +is_use_async_applier=true +is_enable_raft_log_persistence=true +open_server_rpc_port=false diff --git a/testcontainer/src/test/resources/3nodes/docker-compose.yaml b/testcontainer/src/test/resources/3nodes/docker-compose.yaml new file mode 100644 index 000000000000..bbb18cc4987d --- /dev/null +++ b/testcontainer/src/test/resources/3nodes/docker-compose.yaml @@ -0,0 +1,43 @@ +# +# 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. +# + +version: '3.8' + +services: + iotdb-server: + image: apache/iotdb:cluster-maven-development + expose: + - 6667 + - 9003 + - 40010 + networks: + - iotdb + healthcheck: + test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/6667" ] + interval: 5s + timeout: 60s + retries: 120 + volumes: + - ./iotdb-cluster.properties:/iotdb/conf/iotdb-cluster.properties + scale: 3 + + +networks: + iotdb: + driver: bridge diff --git a/testcontainer/src/test/resources/3nodes/iotdb-cluster.properties b/testcontainer/src/test/resources/3nodes/iotdb-cluster.properties new file mode 100644 index 000000000000..fe6133d5e0ff --- /dev/null +++ b/testcontainer/src/test/resources/3nodes/iotdb-cluster.properties @@ -0,0 +1,35 @@ +# +# 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. + +internal_meta_port=9003 +internal_data_port=40010 +seed_nodes=3nodes_iotdb-server_1:9003,3nodes_iotdb-server_2:9003,3nodes_iotdb-server_3:9003 +default_replica_num=3 +consistency_level=mid +connection_timeout_ms=20000 +write_operation_timeout_ms=30000 +read_operation_timeout_ms=30000 +catch_up_timeout_ms=300000 +use_batch_in_catch_up=true +min_num_of_logs_in_mem=1000 +max_num_of_logs_in_mem=2000 +log_deletion_check_interval_second=-1 +is_use_async_server=false +is_use_async_applier=true +is_enable_raft_log_persistence=true +open_server_rpc_port=false diff --git a/testcontainer/src/test/resources/5nodes/docker-compose.yaml b/testcontainer/src/test/resources/5nodes/docker-compose.yaml new file mode 100644 index 000000000000..d45577f25e1d --- /dev/null +++ b/testcontainer/src/test/resources/5nodes/docker-compose.yaml @@ -0,0 +1,42 @@ +# +# 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. +# + +version: '3.8' + +services: + iotdb-server: + image: apache/iotdb:cluster-maven-development + expose: + - 6667 + - 9003 + - 40010 + networks: + - iotdb + healthcheck: + test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/6667" ] + interval: 5s + timeout: 60s + retries: 120 + volumes: + - ./iotdb-cluster.properties:/iotdb/conf/iotdb-cluster.properties + scale: 5 + +networks: + iotdb: + driver: bridge diff --git a/testcontainer/src/test/resources/5nodes/iotdb-cluster.properties b/testcontainer/src/test/resources/5nodes/iotdb-cluster.properties new file mode 100644 index 000000000000..705cca6d1354 --- /dev/null +++ b/testcontainer/src/test/resources/5nodes/iotdb-cluster.properties @@ -0,0 +1,35 @@ +# +# 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. + +internal_meta_port=9003 +internal_data_port=40010 +seed_nodes=5nodes_iotdb-server_1:9003,5nodes_iotdb-server_2:9003,5nodes_iotdb-server_3:9003,5nodes_iotdb-server_4:9003,5nodes_iotdb-server_5:9003 +default_replica_num=3 +consistency_level=mid +connection_timeout_ms=20000 +write_operation_timeout_ms=30000 +read_operation_timeout_ms=30000 +catch_up_timeout_ms=300000 +use_batch_in_catch_up=true +min_num_of_logs_in_mem=1000 +max_num_of_logs_in_mem=2000 +log_deletion_check_interval_second=-1 +is_use_async_server=false +is_use_async_applier=true +is_enable_raft_log_persistence=true +open_server_rpc_port=false diff --git a/testcontainer/src/test/resources/iotdb-engine.properties b/testcontainer/src/test/resources/iotdb-engine.properties new file mode 100644 index 000000000000..960aa13b97f5 --- /dev/null +++ b/testcontainer/src/test/resources/iotdb-engine.properties @@ -0,0 +1,24 @@ +#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. + + +base_dir=target/tmp +data_dirs=target/data +wal_dir=target/wal +index_root_dir=target/index +udf_root_dir=target/ext +tracing_dir=target/data/tracing \ No newline at end of file From b227b176d9eac8b6d5f4cd12468e698fc7325941 Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Sun, 18 Apr 2021 00:47:48 +0800 Subject: [PATCH 02/17] enable github CI for docker --- .github/workflows/e2e.yml | 4 ++ .../sql/{ClusterE2E.java => ClusterIT.java} | 2 +- .../{SingleNodeE2E.java => SingleNodeIT.java} | 2 +- testcontainer/src/test/resources/logback.xml | 46 +++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) rename testcontainer/src/test/java/org/apache/iotdb/db/sql/{ClusterE2E.java => ClusterIT.java} (99%) rename testcontainer/src/test/java/org/apache/iotdb/db/sql/{SingleNodeE2E.java => SingleNodeIT.java} (99%) create mode 100644 testcontainer/src/test/resources/logback.xml diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 6a0e21f21f51..3ce38a727c56 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -52,3 +52,7 @@ jobs: - name: Clean Up if: ${{ always() }} run: bash test/e2e/cases/${{ matrix.case }}/cleanup.sh + + - name: TestContainer + run: | + mvn integration-test -pl testcontainer diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java similarity index 99% rename from testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java rename to testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java index 44c0d082d3c3..7e7c926e6a8d 100644 --- a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java @@ -34,7 +34,7 @@ import java.sql.SQLException; import java.sql.Statement; -public class ClusterE2E { +public class ClusterIT { private Statement statement; private Connection connection; diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java similarity index 99% rename from testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java rename to testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java index 7a4705a681a3..5af217a1020a 100644 --- a/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java @@ -36,7 +36,7 @@ import java.sql.SQLException; import java.sql.Statement; -public class SingleNodeE2E { +public class SingleNodeIT { private Statement statement; private Connection connection; diff --git a/testcontainer/src/test/resources/logback.xml b/testcontainer/src/test/resources/logback.xml new file mode 100644 index 000000000000..52e0c143a2bc --- /dev/null +++ b/testcontainer/src/test/resources/logback.xml @@ -0,0 +1,46 @@ + + + + + + + + System.out + + %-5p [%d] [%thread] %C:%L - %m %n + utf-8 + + + DEBUG + + + + + + + + + + + From c02eb852506fcd9d7a33aee5fb0fe85c0bc5cde1 Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Sun, 18 Apr 2021 00:48:09 +0800 Subject: [PATCH 03/17] remove duplicated operations in integration-test phase --- cli/pom.xml | 1 - cluster/pom.xml | 1 - cross-tests/pom.xml | 1 - grafana/pom.xml | 1 - hadoop/pom.xml | 1 - jdbc/pom.xml | 1 - pom.xml | 2 - server/pom.xml | 1 - service-rpc/pom.xml | 1 - session/pom.xml | 1 - testcontainer/pom.xml | 199 +++++++++++------- .../org/apache/iotdb/db/sql/ClusterIT.java | 3 + tsfile/pom.xml | 1 - 13 files changed, 123 insertions(+), 91 deletions(-) diff --git a/cli/pom.xml b/cli/pom.xml index 1fb8f2992802..b6b36812dc80 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -96,7 +96,6 @@ integration-test integration-test - verify diff --git a/cluster/pom.xml b/cluster/pom.xml index d211396a6743..ca879cabd6c3 100644 --- a/cluster/pom.xml +++ b/cluster/pom.xml @@ -202,7 +202,6 @@ integration-test integration-test - verify diff --git a/cross-tests/pom.xml b/cross-tests/pom.xml index 0d8cd64f96b4..e3a5eb6a607f 100644 --- a/cross-tests/pom.xml +++ b/cross-tests/pom.xml @@ -73,7 +73,6 @@ integration-test integration-test - verify diff --git a/grafana/pom.xml b/grafana/pom.xml index a24ba06420a8..db78562bfd61 100644 --- a/grafana/pom.xml +++ b/grafana/pom.xml @@ -197,7 +197,6 @@ integration-test integration-test - verify diff --git a/hadoop/pom.xml b/hadoop/pom.xml index 776e377fe3ba..75951d342192 100644 --- a/hadoop/pom.xml +++ b/hadoop/pom.xml @@ -116,7 +116,6 @@ integration-test integration-test - verify diff --git a/jdbc/pom.xml b/jdbc/pom.xml index dd17752f78d0..1896f5e4426f 100644 --- a/jdbc/pom.xml +++ b/jdbc/pom.xml @@ -159,7 +159,6 @@ integration-test integration-test - verify diff --git a/pom.xml b/pom.xml index eb27a4243862..56c659f56d15 100644 --- a/pom.xml +++ b/pom.xml @@ -904,7 +904,6 @@ src/test/**/*IT.java - src/test/**/*E2E.java @@ -918,7 +917,6 @@ src/test/**/*IT.java - src/test/**/*E2E.java diff --git a/server/pom.xml b/server/pom.xml index dee952f65e8e..05f5b6476ac9 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -221,7 +221,6 @@ integration-test integration-test - verify diff --git a/service-rpc/pom.xml b/service-rpc/pom.xml index f517fdd42a5b..34df8699cbdb 100644 --- a/service-rpc/pom.xml +++ b/service-rpc/pom.xml @@ -114,7 +114,6 @@ integration-test integration-test - verify diff --git a/session/pom.xml b/session/pom.xml index e1330c556c30..6751dd1bceb0 100644 --- a/session/pom.xml +++ b/session/pom.xml @@ -54,7 +54,6 @@ integration-test integration-test - verify diff --git a/testcontainer/pom.xml b/testcontainer/pom.xml index f8bb9f60e791..a04c6d62491d 100644 --- a/testcontainer/pom.xml +++ b/testcontainer/pom.xml @@ -1,4 +1,24 @@ + org.apache.iotdb @@ -36,83 +56,104 @@ test - - - - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - - build-docker-image - pre-integration-test - - exec - - - ${docker.test.skip} - ${docker.build.executable} - ${docker.build.single.argument} - - - - build-cluster-docker-image - pre-integration-test - - exec - - - ${docker.test.skip} - ${docker.build.executable} - ${docker.build.cluster.argument} - - - - clean-docker-image - post-integration-test - - exec - - - ${docker.test.skip} - ${docker.build.executable} - ${docker.clean.single.argument} - - - - clean-cluster-docker-image - post-integration-test - - exec - - - ${docker.test.skip} - ${docker.build.executable} - ${docker.clean.cluster.argument} - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.2.0 - - - add-test-container-source - generate-test-sources - - add-test-source - - - - ${basedir}/src/test/java - - - - - - - + + + testcontainer + + true + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + build-docker-image + pre-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.build.single.argument} + + + + build-cluster-docker-image + pre-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.build.cluster.argument} + + + + clean-docker-image + post-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.clean.single.argument} + + + + clean-cluster-docker-image + post-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.clean.cluster.argument} + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + add-test-container-source + generate-test-sources + + add-test-source + + + + ${basedir}/src/test/java + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + run-integration-tests + integration-test + + integration-test + + + + + + + + diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java index 7e7c926e6a8d..eb2c8ce7f513 100644 --- a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java @@ -38,6 +38,8 @@ public class ClusterIT { private Statement statement; private Connection connection; + // in TestContainer's document, it is @ClassRule, and the environment is `public static` + // I am not sure the difference now. @Rule public DockerComposeContainer environment = new NoProjectNameDockerComposeContainer( @@ -68,6 +70,7 @@ public void tearDown() throws Exception { @Test public void testSimplePutAndGet() throws SQLException { + String[] timeSeriesArray = {"root.sg1.aa.bb", "root.sg1.aa.bb.cc", "root.sg1.aa"}; for (String timeSeries : timeSeriesArray) { diff --git a/tsfile/pom.xml b/tsfile/pom.xml index b5e1370e0416..41bb74e1f94e 100644 --- a/tsfile/pom.xml +++ b/tsfile/pom.xml @@ -115,7 +115,6 @@ integration-test integration-test - verify From d13381a6c802c7eefb6e46d93fa1426e4a195ee5 Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Tue, 20 Apr 2021 10:33:59 +0800 Subject: [PATCH 04/17] add readme for testcontainer --- testcontainer/Readme.md | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 testcontainer/Readme.md diff --git a/testcontainer/Readme.md b/testcontainer/Readme.md new file mode 100644 index 000000000000..e7c58d4e1ff3 --- /dev/null +++ b/testcontainer/Readme.md @@ -0,0 +1,66 @@ + + +# Description + +This module is for using Docker and TestContainer for end to end test. + +## Requirements + +You have to install Docker before you runn this module. +See [Docker Version Requirement](https://www.testcontainers.org/supported_docker_environment/). + +IoTDB project will detect whether a Docker is installed (but do not check the docker's version). + +The logic is, for Unix-like system, it checks whether `/var/run/docker.sock` exists. +For Window system, it checks whether `C:\Program Files\Docker\Docker\resources\bin\docker.exe` exists. + +If you are sure you have installed the Docker but `testcontainer` module is not loaed, use `-P unixDockerCheck` +in your maven command. + +## Behavior + +Before running `integration-test` in this module, binaries must be generated in the `distribution` module, +e.g, call `mvn package -Dmaven.test.skip=true`. + +In this module, when running `mvn pre-integration-test` (or `mvn integration-test`, `mvn post-integration-test`), +the module will build two docker images, `apache/iotdb:maven-development`, and `apache/iotdb:cluster-maven-development`. + +In the `post-integration-test` phase, the above images will be removed. + +In the `integration-test` phase, all `src/test/java/**/*IT.java` will be tested. + +## How it runs + +`apache/iotdb:maven-development` is generated following the Dockerfile `${basedir}/docker/src/main/Dockerfile-single`, and +`apache/iotdb:cluster-maven-development` is generated following the Dockerfile `${basedir}/docker/src/main/Dockerfile-cluster`. + +For testing a cluster, we use `docker-compose` and `testcontainer`. + +The docker-compose file is located at `src/test/resources/1nodes`, `src/test/resources/3nodes` and `src/test/resources/5nodes`, +in which one is for 1 node with replica number =1 , 3 nodes with replica number=3, and the last one is for 5 nodes with replica number =3. + +TestContainer can start the docker (or docker compose) automatically. + +But these docker compose files can also be used independently. +e.g., `docker-compose up`. + + From 3e9cd96f30231e93755d04ee18e4283f5a45f41f Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Wed, 7 Apr 2021 01:35:58 +0800 Subject: [PATCH 05/17] try test container --- .../resources/conf/iotdb-cluster.properties | 4 +- .../iotdb/cluster/config/ClusterConfig.java | 22 +++- docker/src/main/Dockerfile-cluster | 43 +++++++ .../main/{Dockerfile => Dockerfile-single} | 2 +- pom.xml | 36 ++++++ .../test/resources/testcontainers.properties | 17 +++ test/e2e/base/docker-compose.yaml | 4 +- testcontainer/pom.xml | 118 ++++++++++++++++++ .../org/apache/iotdb/db/sql/ClusterE2E.java | 80 ++++++++++++ .../apache/iotdb/db/sql/SingleNodeE2E.java | 85 +++++++++++++ .../NoProjectNameDockerComposeContainer.java | 38 ++++++ .../test/resources/1node/docker-compose.yaml | 43 +++++++ .../resources/1node/iotdb-cluster.properties | 35 ++++++ .../test/resources/3nodes/docker-compose.yaml | 43 +++++++ .../resources/3nodes/iotdb-cluster.properties | 35 ++++++ .../test/resources/5nodes/docker-compose.yaml | 42 +++++++ .../resources/5nodes/iotdb-cluster.properties | 35 ++++++ .../test/resources/iotdb-engine.properties | 24 ++++ 18 files changed, 698 insertions(+), 8 deletions(-) create mode 100644 docker/src/main/Dockerfile-cluster rename docker/src/main/{Dockerfile => Dockerfile-single} (95%) create mode 100644 server/src/test/resources/testcontainers.properties create mode 100644 testcontainer/pom.xml create mode 100644 testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java create mode 100644 testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java create mode 100644 testcontainer/src/test/java/org/testcontainers/containers/NoProjectNameDockerComposeContainer.java create mode 100644 testcontainer/src/test/resources/1node/docker-compose.yaml create mode 100644 testcontainer/src/test/resources/1node/iotdb-cluster.properties create mode 100644 testcontainer/src/test/resources/3nodes/docker-compose.yaml create mode 100644 testcontainer/src/test/resources/3nodes/iotdb-cluster.properties create mode 100644 testcontainer/src/test/resources/5nodes/docker-compose.yaml create mode 100644 testcontainer/src/test/resources/5nodes/iotdb-cluster.properties create mode 100644 testcontainer/src/test/resources/iotdb-engine.properties diff --git a/cluster/src/assembly/resources/conf/iotdb-cluster.properties b/cluster/src/assembly/resources/conf/iotdb-cluster.properties index 62014ca2a999..5fb14578e3c7 100644 --- a/cluster/src/assembly/resources/conf/iotdb-cluster.properties +++ b/cluster/src/assembly/resources/conf/iotdb-cluster.properties @@ -29,6 +29,7 @@ #-------------------------------------------IMPORTANT---------------------------------------------# # used for communication between cluster nodes, eg heartbeat、raft logs and snapshots etc. +# if this parameter is commented, then the IP that binded by the hostname will be used. internal_ip=127.0.0.1 # port for metadata service @@ -51,7 +52,8 @@ internal_data_port=40010 # nodes that already in the cluster, unnecessary to be the nodes that were used to build the # initial cluster by start-node.sh(.bat). Several nodes will be picked randomly to send the # request, the number of nodes picked depends on the number of retries. -seed_nodes=127.0.0.1:9003,127.0.0.1:9005,127.0.0.1:9007 +#seed_nodes=127.0.0.1:9003,127.0.0.1:9005,127.0.0.1:9007 +seed_nodes=127.0.0.1:9003 # whether to use thrift compressed protocol for internal communications. If you want to change # compression settings for external clients, please modify 'rpc_thrift_compression_enable' in diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java index 43e2ee5b5cad..979d06d2d611 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java @@ -21,22 +21,26 @@ import org.apache.iotdb.cluster.utils.ClusterConsistent; import org.apache.iotdb.db.conf.IoTDBDescriptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; public class ClusterConfig { - + private static Logger logger = LoggerFactory.getLogger(ClusterConfig.class); static final String CONFIG_NAME = "iotdb-cluster.properties"; - private String internalIp = "127.0.0.1"; + private String internalIp; private int internalMetaPort = 9003; private int internalDataPort = 40010; private int clusterRpcPort = IoTDBDescriptor.getInstance().getConfig().getRpcPort(); /** each one is a {internalIp | domain name}:{meta port} string tuple. */ - private List seedNodeUrls = - Arrays.asList(String.format("%s:%d", internalIp, internalMetaPort)); + private List seedNodeUrls; @ClusterConsistent private boolean isRpcThriftCompressionEnabled = false; private int maxConcurrentClientNum = 10000; @@ -164,6 +168,16 @@ public class ClusterConfig { private boolean openServerRpcPort = false; + public ClusterConfig() { + try { + internalIp = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + logger.error(e.getMessage()); + internalIp = "127.0.0.1"; + } + seedNodeUrls = Arrays.asList(String.format("%s:%d", internalIp, internalMetaPort)); + } + public int getSelectorNumOfClientPool() { return selectorNumOfClientPool; } diff --git a/docker/src/main/Dockerfile-cluster b/docker/src/main/Dockerfile-cluster new file mode 100644 index 000000000000..277132b6eab2 --- /dev/null +++ b/docker/src/main/Dockerfile-cluster @@ -0,0 +1,43 @@ +# +# 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. +# + +# docker build context is the root path of the repository + +FROM openjdk:11-jre-slim + +ADD distribution/target/apache-iotdb-*-cluster-bin.zip / + +RUN apt update \ + && apt install lsof procps unzip -y \ + && unzip /apache-iotdb-*-bin.zip -d / \ + && rm /apache-iotdb-*-bin.zip \ + && mv /apache-iotdb-* /iotdb \ + && apt remove unzip -y \ + && apt autoremove -y \ + && apt purge --auto-remove -y \ + && apt clean -y + +EXPOSE 6667 +EXPOSE 31999 +EXPOSE 5555 +EXPOSE 8181 +VOLUME /iotdb/data +VOLUME /iotdb/logs +ENV PATH="/iotdb/sbin/:/iotdb/tools/:${PATH}" +ENTRYPOINT ["/iotdb/sbin/start-node.sh"] diff --git a/docker/src/main/Dockerfile b/docker/src/main/Dockerfile-single similarity index 95% rename from docker/src/main/Dockerfile rename to docker/src/main/Dockerfile-single index 402227c64d18..c0e00a951760 100644 --- a/docker/src/main/Dockerfile +++ b/docker/src/main/Dockerfile-single @@ -21,7 +21,7 @@ FROM openjdk:11-jre-slim -ADD distribution/target/apache-iotdb-*-all-bin.zip / +ADD distribution/target/apache-iotdb-*-server-bin.zip / RUN apt update \ && apt install lsof procps unzip -y \ diff --git a/pom.xml b/pom.xml index 1c2b0f3b3674..eb27a4243862 100644 --- a/pom.xml +++ b/pom.xml @@ -508,6 +508,12 @@ mockito-all test + + org.testcontainers + testcontainers + 1.15.2 + test + @@ -898,6 +904,7 @@ src/test/**/*IT.java + src/test/**/*E2E.java @@ -911,7 +918,12 @@ src/test/**/*IT.java + src/test/**/*E2E.java + + + src/test/**/*Test.java + @@ -991,6 +1003,30 @@ +x ${project.build.directory}/tools/${thrift.executable} + + + + unixDockerCheck + + + /var/run/docker.sock + + + + testcontainer + + + + WinDockerCheck + + + C:\Program Files\Docker\Docker\resources\bin\docker.exe + + + + testcontainer + + java-11-and-above diff --git a/server/src/test/resources/testcontainers.properties b/server/src/test/resources/testcontainers.properties new file mode 100644 index 000000000000..af6effe66acd --- /dev/null +++ b/server/src/test/resources/testcontainers.properties @@ -0,0 +1,17 @@ +#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. + diff --git a/test/e2e/base/docker-compose.yaml b/test/e2e/base/docker-compose.yaml index d4970d45adbc..08ebc3b03440 100644 --- a/test/e2e/base/docker-compose.yaml +++ b/test/e2e/base/docker-compose.yaml @@ -23,7 +23,7 @@ services: server-prototype: build: context: ../../.. - dockerfile: docker/src/main/Dockerfile + dockerfile: ../../../docker/src/main/Dockerfile-single ports: - 6667:6667 networks: @@ -37,7 +37,7 @@ services: initializer: build: context: ../../.. - dockerfile: docker/src/main/Dockerfile + dockerfile: ../../../docker/src/main/Dockerfile-single networks: iotdb: entrypoint: diff --git a/testcontainer/pom.xml b/testcontainer/pom.xml new file mode 100644 index 000000000000..f8bb9f60e791 --- /dev/null +++ b/testcontainer/pom.xml @@ -0,0 +1,118 @@ + + + + org.apache.iotdb + iotdb-parent + 0.12.0-SNAPSHOT + ../pom.xml + + 4.0.0 + testcontainer + + false + docker + build -t apache/iotdb:maven-development -f ${basedir}/../docker/src/main/Dockerfile-single ${basedir}/../. + image rm apache/iotdb:maven-development + build -t apache/iotdb:cluster-maven-development -f ${basedir}/../docker/src/main/Dockerfile-cluster ${basedir}/../. + image rm apache/iotdb:cluster-maven-development + + + + org.apache.iotdb + iotdb-jdbc + ${project.version} + test + + + org.apache.iotdb + iotdb-session + ${project.version} + test + + + org.apache.iotdb + iotdb-cli + ${project.version} + test + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + build-docker-image + pre-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.build.single.argument} + + + + build-cluster-docker-image + pre-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.build.cluster.argument} + + + + clean-docker-image + post-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.clean.single.argument} + + + + clean-cluster-docker-image + post-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.clean.cluster.argument} + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + add-test-container-source + generate-test-sources + + add-test-source + + + + ${basedir}/src/test/java + + + + + + + + diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java new file mode 100644 index 000000000000..44c0d082d3c3 --- /dev/null +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java @@ -0,0 +1,80 @@ +/* + * 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.iotdb.db.sql; + +import org.apache.iotdb.jdbc.Config; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.NoProjectNameDockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; + +public class ClusterE2E { + private Statement statement; + private Connection connection; + + @Rule + public DockerComposeContainer environment = + new NoProjectNameDockerComposeContainer( + "3nodes", new File("src/test/resources/3nodes/docker-compose.yaml")) + .withExposedService("iotdb-server_1", 6667, Wait.forListeningPort()) + .withExposedService("iotdb-server_2", 6667, Wait.forListeningPort()) + .withExposedService("iotdb-server_3", 6667, Wait.forListeningPort()) + .withLocalCompose(true); + + int rpcPort = 6667; + + @Before + public void setUp() throws Exception { + + String ip = environment.getServiceHost("iotdb-server_1", 6667); + rpcPort = environment.getServicePort("iotdb-server_1", 6667); + + Class.forName(Config.JDBC_DRIVER_NAME); + connection = DriverManager.getConnection("jdbc:iotdb://" + ip + ":" + rpcPort, "root", "root"); + statement = connection.createStatement(); + } + + @After + public void tearDown() throws Exception { + statement.close(); + connection.close(); + } + + @Test + public void testSimplePutAndGet() throws SQLException { + String[] timeSeriesArray = {"root.sg1.aa.bb", "root.sg1.aa.bb.cc", "root.sg1.aa"}; + + for (String timeSeries : timeSeriesArray) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + timeSeries)); + } + } +} diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java new file mode 100644 index 000000000000..7a4705a681a3 --- /dev/null +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java @@ -0,0 +1,85 @@ +/* + * 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.iotdb.db.sql; + +import org.apache.iotdb.jdbc.Config; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.images.PullPolicy; +import org.testcontainers.utility.DockerImageName; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; + +public class SingleNodeE2E { + private Statement statement; + private Connection connection; + + @Rule + public GenericContainer dslContainer = + new GenericContainer(DockerImageName.parse("apache/iotdb:maven-development")) + .withImagePullPolicy(PullPolicy.defaultPolicy()) + // mount another properties for changing parameters, e.g., open 5555 port (sync module) + .withFileSystemBind( + new File("src/test/resources/iotdb-engine.properties").getAbsolutePath(), + "/iotdb/conf/iotdb-engine.properties", + BindMode.READ_ONLY) + .withExposedPorts(6667) + .waitingFor(Wait.forListeningPort()); + + int rpcPort = 6667; + int syncPort = 5555; + + @Before + public void setUp() throws Exception { + rpcPort = dslContainer.getMappedPort(6667); + + syncPort = dslContainer.getMappedPort(5555); + Class.forName(Config.JDBC_DRIVER_NAME); + connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:" + rpcPort, "root", "root"); + statement = connection.createStatement(); + } + + @After + public void tearDown() throws Exception { + statement.close(); + connection.close(); + } + + @Test + public void testSimplePutAndGet() throws SQLException { + String[] timeSeriesArray = {"root.sg1.aa.bb", "root.sg1.aa.bb.cc", "root.sg1.aa"}; + + for (String timeSeries : timeSeriesArray) { + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + timeSeries)); + } + } +} diff --git a/testcontainer/src/test/java/org/testcontainers/containers/NoProjectNameDockerComposeContainer.java b/testcontainer/src/test/java/org/testcontainers/containers/NoProjectNameDockerComposeContainer.java new file mode 100644 index 000000000000..0d1fa76a8337 --- /dev/null +++ b/testcontainer/src/test/java/org/testcontainers/containers/NoProjectNameDockerComposeContainer.java @@ -0,0 +1,38 @@ +/* + * 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.testcontainers.containers; + +import java.io.File; +import java.lang.reflect.Field; + +public class NoProjectNameDockerComposeContainer extends DockerComposeContainer { + + public NoProjectNameDockerComposeContainer(String identifier, File... composeFiles) { + super(identifier, composeFiles); + Field project = null; + try { + project = DockerComposeContainer.class.getDeclaredField("project"); + project.setAccessible(true); + project.set(this, ""); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/testcontainer/src/test/resources/1node/docker-compose.yaml b/testcontainer/src/test/resources/1node/docker-compose.yaml new file mode 100644 index 000000000000..9803930643ec --- /dev/null +++ b/testcontainer/src/test/resources/1node/docker-compose.yaml @@ -0,0 +1,43 @@ +# +# 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. +# + +version: '3.8' + +services: + iotdb-server: + image: apache/iotdb:cluster-maven-development + expose: + - 6667 + - 9003 + - 40010 + networks: + - iotdb + healthcheck: + test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/6667" ] + interval: 5s + timeout: 60s + retries: 120 + volumes: + - ./iotdb-cluster.properties:/iotdb/conf/iotdb-cluster.properties + scale: 1 + + +networks: + iotdb: + driver: bridge diff --git a/testcontainer/src/test/resources/1node/iotdb-cluster.properties b/testcontainer/src/test/resources/1node/iotdb-cluster.properties new file mode 100644 index 000000000000..2df52cce86cc --- /dev/null +++ b/testcontainer/src/test/resources/1node/iotdb-cluster.properties @@ -0,0 +1,35 @@ +# +# 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. + +internal_meta_port=9003 +internal_data_port=40010 +seed_nodes=3nodes_iotdb-server_1:9003 +default_replica_num=1 +consistency_level=mid +connection_timeout_ms=20000 +write_operation_timeout_ms=30000 +read_operation_timeout_ms=30000 +catch_up_timeout_ms=300000 +use_batch_in_catch_up=true +min_num_of_logs_in_mem=1000 +max_num_of_logs_in_mem=2000 +log_deletion_check_interval_second=-1 +is_use_async_server=false +is_use_async_applier=true +is_enable_raft_log_persistence=true +open_server_rpc_port=false diff --git a/testcontainer/src/test/resources/3nodes/docker-compose.yaml b/testcontainer/src/test/resources/3nodes/docker-compose.yaml new file mode 100644 index 000000000000..bbb18cc4987d --- /dev/null +++ b/testcontainer/src/test/resources/3nodes/docker-compose.yaml @@ -0,0 +1,43 @@ +# +# 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. +# + +version: '3.8' + +services: + iotdb-server: + image: apache/iotdb:cluster-maven-development + expose: + - 6667 + - 9003 + - 40010 + networks: + - iotdb + healthcheck: + test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/6667" ] + interval: 5s + timeout: 60s + retries: 120 + volumes: + - ./iotdb-cluster.properties:/iotdb/conf/iotdb-cluster.properties + scale: 3 + + +networks: + iotdb: + driver: bridge diff --git a/testcontainer/src/test/resources/3nodes/iotdb-cluster.properties b/testcontainer/src/test/resources/3nodes/iotdb-cluster.properties new file mode 100644 index 000000000000..fe6133d5e0ff --- /dev/null +++ b/testcontainer/src/test/resources/3nodes/iotdb-cluster.properties @@ -0,0 +1,35 @@ +# +# 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. + +internal_meta_port=9003 +internal_data_port=40010 +seed_nodes=3nodes_iotdb-server_1:9003,3nodes_iotdb-server_2:9003,3nodes_iotdb-server_3:9003 +default_replica_num=3 +consistency_level=mid +connection_timeout_ms=20000 +write_operation_timeout_ms=30000 +read_operation_timeout_ms=30000 +catch_up_timeout_ms=300000 +use_batch_in_catch_up=true +min_num_of_logs_in_mem=1000 +max_num_of_logs_in_mem=2000 +log_deletion_check_interval_second=-1 +is_use_async_server=false +is_use_async_applier=true +is_enable_raft_log_persistence=true +open_server_rpc_port=false diff --git a/testcontainer/src/test/resources/5nodes/docker-compose.yaml b/testcontainer/src/test/resources/5nodes/docker-compose.yaml new file mode 100644 index 000000000000..d45577f25e1d --- /dev/null +++ b/testcontainer/src/test/resources/5nodes/docker-compose.yaml @@ -0,0 +1,42 @@ +# +# 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. +# + +version: '3.8' + +services: + iotdb-server: + image: apache/iotdb:cluster-maven-development + expose: + - 6667 + - 9003 + - 40010 + networks: + - iotdb + healthcheck: + test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/6667" ] + interval: 5s + timeout: 60s + retries: 120 + volumes: + - ./iotdb-cluster.properties:/iotdb/conf/iotdb-cluster.properties + scale: 5 + +networks: + iotdb: + driver: bridge diff --git a/testcontainer/src/test/resources/5nodes/iotdb-cluster.properties b/testcontainer/src/test/resources/5nodes/iotdb-cluster.properties new file mode 100644 index 000000000000..705cca6d1354 --- /dev/null +++ b/testcontainer/src/test/resources/5nodes/iotdb-cluster.properties @@ -0,0 +1,35 @@ +# +# 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. + +internal_meta_port=9003 +internal_data_port=40010 +seed_nodes=5nodes_iotdb-server_1:9003,5nodes_iotdb-server_2:9003,5nodes_iotdb-server_3:9003,5nodes_iotdb-server_4:9003,5nodes_iotdb-server_5:9003 +default_replica_num=3 +consistency_level=mid +connection_timeout_ms=20000 +write_operation_timeout_ms=30000 +read_operation_timeout_ms=30000 +catch_up_timeout_ms=300000 +use_batch_in_catch_up=true +min_num_of_logs_in_mem=1000 +max_num_of_logs_in_mem=2000 +log_deletion_check_interval_second=-1 +is_use_async_server=false +is_use_async_applier=true +is_enable_raft_log_persistence=true +open_server_rpc_port=false diff --git a/testcontainer/src/test/resources/iotdb-engine.properties b/testcontainer/src/test/resources/iotdb-engine.properties new file mode 100644 index 000000000000..960aa13b97f5 --- /dev/null +++ b/testcontainer/src/test/resources/iotdb-engine.properties @@ -0,0 +1,24 @@ +#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. + + +base_dir=target/tmp +data_dirs=target/data +wal_dir=target/wal +index_root_dir=target/index +udf_root_dir=target/ext +tracing_dir=target/data/tracing \ No newline at end of file From 908b9517455dee12ba645f8c53db7d2777125fcf Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Sun, 18 Apr 2021 00:47:48 +0800 Subject: [PATCH 06/17] enable github CI for docker --- .github/workflows/e2e.yml | 4 ++ .../sql/{ClusterE2E.java => ClusterIT.java} | 2 +- .../{SingleNodeE2E.java => SingleNodeIT.java} | 2 +- testcontainer/src/test/resources/logback.xml | 46 +++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) rename testcontainer/src/test/java/org/apache/iotdb/db/sql/{ClusterE2E.java => ClusterIT.java} (99%) rename testcontainer/src/test/java/org/apache/iotdb/db/sql/{SingleNodeE2E.java => SingleNodeIT.java} (99%) create mode 100644 testcontainer/src/test/resources/logback.xml diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 6a0e21f21f51..3ce38a727c56 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -52,3 +52,7 @@ jobs: - name: Clean Up if: ${{ always() }} run: bash test/e2e/cases/${{ matrix.case }}/cleanup.sh + + - name: TestContainer + run: | + mvn integration-test -pl testcontainer diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java similarity index 99% rename from testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java rename to testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java index 44c0d082d3c3..7e7c926e6a8d 100644 --- a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterE2E.java +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java @@ -34,7 +34,7 @@ import java.sql.SQLException; import java.sql.Statement; -public class ClusterE2E { +public class ClusterIT { private Statement statement; private Connection connection; diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java similarity index 99% rename from testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java rename to testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java index 7a4705a681a3..5af217a1020a 100644 --- a/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeE2E.java +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java @@ -36,7 +36,7 @@ import java.sql.SQLException; import java.sql.Statement; -public class SingleNodeE2E { +public class SingleNodeIT { private Statement statement; private Connection connection; diff --git a/testcontainer/src/test/resources/logback.xml b/testcontainer/src/test/resources/logback.xml new file mode 100644 index 000000000000..52e0c143a2bc --- /dev/null +++ b/testcontainer/src/test/resources/logback.xml @@ -0,0 +1,46 @@ + + + + + + + + System.out + + %-5p [%d] [%thread] %C:%L - %m %n + utf-8 + + + DEBUG + + + + + + + + + + + From 09a5bc7b320d2f5505890142195f2ee9c1cca2b1 Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Sun, 18 Apr 2021 00:48:09 +0800 Subject: [PATCH 07/17] remove duplicated operations in integration-test phase --- cli/pom.xml | 1 - cluster/pom.xml | 1 - cross-tests/pom.xml | 1 - grafana/pom.xml | 1 - hadoop/pom.xml | 1 - jdbc/pom.xml | 1 - pom.xml | 2 - server/pom.xml | 1 - service-rpc/pom.xml | 1 - session/pom.xml | 1 - testcontainer/pom.xml | 199 +++++++++++------- .../org/apache/iotdb/db/sql/ClusterIT.java | 3 + tsfile/pom.xml | 1 - 13 files changed, 123 insertions(+), 91 deletions(-) diff --git a/cli/pom.xml b/cli/pom.xml index 1fb8f2992802..b6b36812dc80 100644 --- a/cli/pom.xml +++ b/cli/pom.xml @@ -96,7 +96,6 @@ integration-test integration-test - verify diff --git a/cluster/pom.xml b/cluster/pom.xml index d211396a6743..ca879cabd6c3 100644 --- a/cluster/pom.xml +++ b/cluster/pom.xml @@ -202,7 +202,6 @@ integration-test integration-test - verify diff --git a/cross-tests/pom.xml b/cross-tests/pom.xml index 0d8cd64f96b4..e3a5eb6a607f 100644 --- a/cross-tests/pom.xml +++ b/cross-tests/pom.xml @@ -73,7 +73,6 @@ integration-test integration-test - verify diff --git a/grafana/pom.xml b/grafana/pom.xml index a24ba06420a8..db78562bfd61 100644 --- a/grafana/pom.xml +++ b/grafana/pom.xml @@ -197,7 +197,6 @@ integration-test integration-test - verify diff --git a/hadoop/pom.xml b/hadoop/pom.xml index 776e377fe3ba..75951d342192 100644 --- a/hadoop/pom.xml +++ b/hadoop/pom.xml @@ -116,7 +116,6 @@ integration-test integration-test - verify diff --git a/jdbc/pom.xml b/jdbc/pom.xml index dd17752f78d0..1896f5e4426f 100644 --- a/jdbc/pom.xml +++ b/jdbc/pom.xml @@ -159,7 +159,6 @@ integration-test integration-test - verify diff --git a/pom.xml b/pom.xml index eb27a4243862..56c659f56d15 100644 --- a/pom.xml +++ b/pom.xml @@ -904,7 +904,6 @@ src/test/**/*IT.java - src/test/**/*E2E.java @@ -918,7 +917,6 @@ src/test/**/*IT.java - src/test/**/*E2E.java diff --git a/server/pom.xml b/server/pom.xml index fecd1d9800b9..42d53267a5df 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -227,7 +227,6 @@ integration-test integration-test - verify diff --git a/service-rpc/pom.xml b/service-rpc/pom.xml index f517fdd42a5b..34df8699cbdb 100644 --- a/service-rpc/pom.xml +++ b/service-rpc/pom.xml @@ -114,7 +114,6 @@ integration-test integration-test - verify diff --git a/session/pom.xml b/session/pom.xml index e1330c556c30..6751dd1bceb0 100644 --- a/session/pom.xml +++ b/session/pom.xml @@ -54,7 +54,6 @@ integration-test integration-test - verify diff --git a/testcontainer/pom.xml b/testcontainer/pom.xml index f8bb9f60e791..a04c6d62491d 100644 --- a/testcontainer/pom.xml +++ b/testcontainer/pom.xml @@ -1,4 +1,24 @@ + org.apache.iotdb @@ -36,83 +56,104 @@ test - - - - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - - build-docker-image - pre-integration-test - - exec - - - ${docker.test.skip} - ${docker.build.executable} - ${docker.build.single.argument} - - - - build-cluster-docker-image - pre-integration-test - - exec - - - ${docker.test.skip} - ${docker.build.executable} - ${docker.build.cluster.argument} - - - - clean-docker-image - post-integration-test - - exec - - - ${docker.test.skip} - ${docker.build.executable} - ${docker.clean.single.argument} - - - - clean-cluster-docker-image - post-integration-test - - exec - - - ${docker.test.skip} - ${docker.build.executable} - ${docker.clean.cluster.argument} - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.2.0 - - - add-test-container-source - generate-test-sources - - add-test-source - - - - ${basedir}/src/test/java - - - - - - - + + + testcontainer + + true + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + build-docker-image + pre-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.build.single.argument} + + + + build-cluster-docker-image + pre-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.build.cluster.argument} + + + + clean-docker-image + post-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.clean.single.argument} + + + + clean-cluster-docker-image + post-integration-test + + exec + + + ${docker.test.skip} + ${docker.build.executable} + ${docker.clean.cluster.argument} + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + add-test-container-source + generate-test-sources + + add-test-source + + + + ${basedir}/src/test/java + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + run-integration-tests + integration-test + + integration-test + + + + + + + + diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java index 7e7c926e6a8d..eb2c8ce7f513 100644 --- a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java @@ -38,6 +38,8 @@ public class ClusterIT { private Statement statement; private Connection connection; + // in TestContainer's document, it is @ClassRule, and the environment is `public static` + // I am not sure the difference now. @Rule public DockerComposeContainer environment = new NoProjectNameDockerComposeContainer( @@ -68,6 +70,7 @@ public void tearDown() throws Exception { @Test public void testSimplePutAndGet() throws SQLException { + String[] timeSeriesArray = {"root.sg1.aa.bb", "root.sg1.aa.bb.cc", "root.sg1.aa"}; for (String timeSeries : timeSeriesArray) { diff --git a/tsfile/pom.xml b/tsfile/pom.xml index b5e1370e0416..41bb74e1f94e 100644 --- a/tsfile/pom.xml +++ b/tsfile/pom.xml @@ -115,7 +115,6 @@ integration-test integration-test - verify From 11aaa5bc08ff41277395b288f724901321012afb Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Tue, 20 Apr 2021 10:33:59 +0800 Subject: [PATCH 08/17] add readme for testcontainer --- testcontainer/Readme.md | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 testcontainer/Readme.md diff --git a/testcontainer/Readme.md b/testcontainer/Readme.md new file mode 100644 index 000000000000..e7c58d4e1ff3 --- /dev/null +++ b/testcontainer/Readme.md @@ -0,0 +1,66 @@ + + +# Description + +This module is for using Docker and TestContainer for end to end test. + +## Requirements + +You have to install Docker before you runn this module. +See [Docker Version Requirement](https://www.testcontainers.org/supported_docker_environment/). + +IoTDB project will detect whether a Docker is installed (but do not check the docker's version). + +The logic is, for Unix-like system, it checks whether `/var/run/docker.sock` exists. +For Window system, it checks whether `C:\Program Files\Docker\Docker\resources\bin\docker.exe` exists. + +If you are sure you have installed the Docker but `testcontainer` module is not loaed, use `-P unixDockerCheck` +in your maven command. + +## Behavior + +Before running `integration-test` in this module, binaries must be generated in the `distribution` module, +e.g, call `mvn package -Dmaven.test.skip=true`. + +In this module, when running `mvn pre-integration-test` (or `mvn integration-test`, `mvn post-integration-test`), +the module will build two docker images, `apache/iotdb:maven-development`, and `apache/iotdb:cluster-maven-development`. + +In the `post-integration-test` phase, the above images will be removed. + +In the `integration-test` phase, all `src/test/java/**/*IT.java` will be tested. + +## How it runs + +`apache/iotdb:maven-development` is generated following the Dockerfile `${basedir}/docker/src/main/Dockerfile-single`, and +`apache/iotdb:cluster-maven-development` is generated following the Dockerfile `${basedir}/docker/src/main/Dockerfile-cluster`. + +For testing a cluster, we use `docker-compose` and `testcontainer`. + +The docker-compose file is located at `src/test/resources/1nodes`, `src/test/resources/3nodes` and `src/test/resources/5nodes`, +in which one is for 1 node with replica number =1 , 3 nodes with replica number=3, and the last one is for 5 nodes with replica number =3. + +TestContainer can start the docker (or docker compose) automatically. + +But these docker compose files can also be used independently. +e.g., `docker-compose up`. + + From 55ff156a7b97e08289df41c19c6f9b443d4952ee Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Thu, 22 Apr 2021 23:30:58 +0800 Subject: [PATCH 09/17] tmp --- .github/workflows/e2e.yml | 2 +- .../org/apache/iotdb/cluster/ClusterMain.java | 5 ++- .../iotdb/cluster/config/ClusterConfig.java | 5 +++ .../cluster/config/ClusterDescriptor.java | 2 ++ pom.xml | 19 ++++++++--- .../org/apache/iotdb/db/sql/ClusterIT.java | 34 ++++++++++++++++--- .../test/resources/1node/docker-compose.yaml | 1 + .../test/resources/3nodes/docker-compose.yaml | 1 + .../test/resources/5nodes/docker-compose.yaml | 1 + testcontainer/src/test/resources/logback.xml | 2 +- 10 files changed, 60 insertions(+), 12 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 3ce38a727c56..8700aff2d5dc 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -43,7 +43,7 @@ jobs: - name: Build Docker Image run: | - docker build . -f docker/src/main/Dockerfile -t "iotdb:$GITHUB_SHA" + docker build . -f docker/src/main/Dockerfile-single -t "iotdb:$GITHUB_SHA" docker images - name: Run Test Case ${{ matrix.case }} diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java index f39e9a6f5cdc..eaf0c8e19000 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java @@ -141,6 +141,7 @@ public static void main(String[] args) { private static void startServerCheck() throws StartupException { ClusterConfig config = ClusterDescriptor.getInstance().getConfig(); + logger.info("seed urls in start Server Check 1:" + config.getSeedNodeUrls()); // check the initial replicateNum and refuse to start when the replicateNum <= 0 if (config.getReplicationNum() <= 0) { String message = @@ -148,6 +149,7 @@ private static void startServerCheck() throws StartupException { "ReplicateNum should be greater than 0 instead of %d.", config.getReplicationNum()); throw new StartupException(metaServer.getMember().getName(), message); } + logger.info("seed urls in start Server Check 2:" + config.getSeedNodeUrls()); // check the initial cluster size and refuse to start when the size < quorum int quorum = config.getReplicationNum() / 2 + 1; if (config.getSeedNodeUrls().size() < quorum) { @@ -157,6 +159,7 @@ private static void startServerCheck() throws StartupException { config.getSeedNodeUrls().size(), quorum); throw new StartupException(metaServer.getMember().getName(), message); } + logger.info("seed urls in start Server Check 3:" + config.getSeedNodeUrls()); // assert not duplicated nodes Set seedNodes = new HashSet<>(); for (String url : config.getSeedNodeUrls()) { @@ -170,7 +173,7 @@ private static void startServerCheck() throws StartupException { seedNodes.add(node); } - // assert this node is in all nodes when restart + // assert this node is in all nodes when restart 172.19.0.2:9003, 172.19.0.3:9003, if (!metaServer.getMember().getAllNodes().isEmpty()) { if (!metaServer.getMember().getAllNodes().contains(metaServer.getMember().getThisNode())) { String message = diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java index 979d06d2d611..7d3e42a5a0db 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterConfig.java @@ -168,6 +168,11 @@ public class ClusterConfig { private boolean openServerRpcPort = false; + /** + * create a clusterConfig class. The internalIP will be set according to the server's hostname. If + * there is something error for getting the ip of the hostname, then set the internalIp as + * localhost. + */ public ClusterConfig() { try { internalIp = InetAddress.getLocalHost().getHostAddress(); diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java index 25f85e038740..f0d31ed93b6b 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java @@ -96,6 +96,7 @@ public void replaceHostnameWithIp() throws UnknownHostException, BadSeedUrlForma config.setInternalIp(hostnameToIP(config.getInternalIp())); } List newSeedUrls = new ArrayList<>(); + logger.info("seed urls:" + config.getSeedNodeUrls()); for (String seedUrl : config.getSeedNodeUrls()) { String[] splits = seedUrl.split(":"); if (splits.length != 2) { @@ -111,6 +112,7 @@ public void replaceHostnameWithIp() throws UnknownHostException, BadSeedUrlForma } } config.setSeedNodeUrls(newSeedUrls); + logger.info("after replace, seed urls:" + config.getSeedNodeUrls()); logger.debug( "after replace, the rpcIP={}, internalIP={}, seedUrls={}", IoTDBDescriptor.getInstance().getConfig().getRpcAddress(), diff --git a/pom.xml b/pom.xml index 56c659f56d15..93ccb21281cb 100644 --- a/pom.xml +++ b/pom.xml @@ -941,13 +941,24 @@ - - com.diffplug.spotless - spotless-maven-plugin - + + + spotless + + true + + + + + com.diffplug.spotless + spotless-maven-plugin + + + + + + . + diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java index 74d92b8d5ec0..72dd62bc16b8 100644 --- a/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/ClusterIT.java @@ -20,11 +20,7 @@ import org.apache.iotdb.jdbc.Config; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.containers.DockerComposeContainer; @@ -33,11 +29,9 @@ import org.testcontainers.containers.wait.strategy.Wait; import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; +import java.util.HashSet; +import java.util.Set; public class ClusterIT { private static Logger logger = LoggerFactory.getLogger(ClusterIT.class); @@ -82,26 +76,25 @@ public void tearDown() throws Exception { } @Test - public void testSimplePutAndGet() { + public void testSimplePutAndGet() throws SQLException { String[] timeSeriesArray = {"root.sg1.aa.bb", "root.sg1.aa.bb.cc", "root.sg1.aa"}; for (String timeSeries : timeSeriesArray) { - try { - Assert.assertTrue( - statement.execute( - String.format( - "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", - timeSeries))); - ResultSet resultSet = null; - resultSet = statement.executeQuery("show time series"); - for (String timeseries : timeSeriesArray) { - Assert.assertTrue(resultSet.next()); - Assert.assertEquals(timeseries, resultSet.getString(1)); - } - } catch (SQLException throwables) { - Assert.fail(throwables.getMessage()); - } + statement.execute( + String.format( + "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", + timeSeries)); + } + ResultSet resultSet = null; + resultSet = statement.executeQuery("show timeseries"); + Set result = new HashSet<>(); + while (resultSet.next()) { + result.add(resultSet.getString(1)); + } + Assert.assertEquals(3, result.size()); + for (String timeseries : timeSeriesArray) { + Assert.assertTrue(result.contains(timeseries)); } } } diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java index 5af217a1020a..65b32ecc6b46 100644 --- a/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java +++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SingleNodeIT.java @@ -20,23 +20,23 @@ import org.apache.iotdb.jdbc.Config; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testcontainers.containers.BindMode; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.images.PullPolicy; import org.testcontainers.utility.DockerImageName; import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; +import java.util.HashSet; +import java.util.Set; public class SingleNodeIT { + private static Logger logger = LoggerFactory.getLogger(SingleNodeIT.class); private Statement statement; private Connection connection; @@ -49,6 +49,11 @@ public class SingleNodeIT { new File("src/test/resources/iotdb-engine.properties").getAbsolutePath(), "/iotdb/conf/iotdb-engine.properties", BindMode.READ_ONLY) + .withFileSystemBind( + new File("src/test/resources/logback-container.xml").getAbsolutePath(), + "/iotdb/conf/logback.xml", + BindMode.READ_ONLY) + .withLogConsumer(new Slf4jLogConsumer(logger)) .withExposedPorts(6667) .waitingFor(Wait.forListeningPort()); @@ -81,5 +86,15 @@ public void testSimplePutAndGet() throws SQLException { "create timeseries %s with datatype=INT64, encoding=PLAIN, compression=SNAPPY", timeSeries)); } + ResultSet resultSet = null; + resultSet = statement.executeQuery("show timeseries"); + Set result = new HashSet<>(); + while (resultSet.next()) { + result.add(resultSet.getString(1)); + } + Assert.assertEquals(3, result.size()); + for (String timeseries : timeSeriesArray) { + Assert.assertTrue(result.contains(timeseries)); + } } } diff --git a/testcontainer/src/test/resources/1node/docker-compose.yaml b/testcontainer/src/test/resources/1node/docker-compose.yaml index 7ced71fdf00b..e1308beb2221 100644 --- a/testcontainer/src/test/resources/1node/docker-compose.yaml +++ b/testcontainer/src/test/resources/1node/docker-compose.yaml @@ -35,7 +35,7 @@ services: retries: 120 volumes: - ./iotdb-cluster.properties:/iotdb/conf/iotdb-cluster.properties - - ../logback.xml:/iotdb/conf/logback.xml + - ../logback-container.xml:/iotdb/conf/logback.xml scale: 1 diff --git a/testcontainer/src/test/resources/3nodes/docker-compose.yaml b/testcontainer/src/test/resources/3nodes/docker-compose.yaml index 0f9640db7713..9349e1c21623 100644 --- a/testcontainer/src/test/resources/3nodes/docker-compose.yaml +++ b/testcontainer/src/test/resources/3nodes/docker-compose.yaml @@ -35,7 +35,7 @@ services: retries: 120 volumes: - ./iotdb-cluster.properties:/iotdb/conf/iotdb-cluster.properties - - ../logback.xml:/iotdb/conf/logback.xml + - ../logback-container.xml:/iotdb/conf/logback.xml scale: 3 diff --git a/testcontainer/src/test/resources/5nodes/docker-compose.yaml b/testcontainer/src/test/resources/5nodes/docker-compose.yaml index c6028c0dfe95..5ca9bd1b82cb 100644 --- a/testcontainer/src/test/resources/5nodes/docker-compose.yaml +++ b/testcontainer/src/test/resources/5nodes/docker-compose.yaml @@ -35,7 +35,7 @@ services: retries: 120 volumes: - ./iotdb-cluster.properties:/iotdb/conf/iotdb-cluster.properties - - ../logback.xml:/iotdb/conf/logback.xml + - ../logback-container.xml:/iotdb/conf/logback.xml scale: 5 networks: diff --git a/testcontainer/src/test/resources/logback-container.xml b/testcontainer/src/test/resources/logback-container.xml new file mode 100644 index 000000000000..7a5f7f918fce --- /dev/null +++ b/testcontainer/src/test/resources/logback-container.xml @@ -0,0 +1,40 @@ + + + + + + + + System.out + + %-5p [%d] [%thread] %C{25}:%L - %m %n + utf-8 + + + DEBUG + + + + + + + diff --git a/testcontainer/src/test/resources/logback.xml b/testcontainer/src/test/resources/logback.xml index 49fef966208c..b0e7f31b04e2 100644 --- a/testcontainer/src/test/resources/logback.xml +++ b/testcontainer/src/test/resources/logback.xml @@ -33,13 +33,20 @@ DEBUG - - - - - + + + System.out + + [%thread] %m %n + utf-8 + + + DEBUG + + + + + From 7e35eedd59ee4eccde9634885d9c6eb20f46fb3f Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Fri, 23 Apr 2021 01:04:25 +0800 Subject: [PATCH 11/17] remove unused log --- .../src/main/java/org/apache/iotdb/cluster/ClusterMain.java | 3 --- .../org/apache/iotdb/cluster/config/ClusterDescriptor.java | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java index eaf0c8e19000..553aee8b5b2e 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java @@ -35,7 +35,6 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.exception.StartupException; import org.apache.iotdb.db.exception.query.QueryProcessException; - import org.apache.thrift.TException; import org.apache.thrift.async.TAsyncClientManager; import org.apache.thrift.protocol.TBinaryProtocol.Factory; @@ -141,7 +140,6 @@ public static void main(String[] args) { private static void startServerCheck() throws StartupException { ClusterConfig config = ClusterDescriptor.getInstance().getConfig(); - logger.info("seed urls in start Server Check 1:" + config.getSeedNodeUrls()); // check the initial replicateNum and refuse to start when the replicateNum <= 0 if (config.getReplicationNum() <= 0) { String message = @@ -149,7 +147,6 @@ private static void startServerCheck() throws StartupException { "ReplicateNum should be greater than 0 instead of %d.", config.getReplicationNum()); throw new StartupException(metaServer.getMember().getName(), message); } - logger.info("seed urls in start Server Check 2:" + config.getSeedNodeUrls()); // check the initial cluster size and refuse to start when the size < quorum int quorum = config.getReplicationNum() / 2 + 1; if (config.getSeedNodeUrls().size() < quorum) { diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java index f0d31ed93b6b..af66b115c308 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java @@ -19,12 +19,11 @@ package org.apache.iotdb.cluster.config; +import com.google.common.net.InetAddresses; import org.apache.iotdb.cluster.exception.BadSeedUrlFormatException; import org.apache.iotdb.db.conf.IoTDBConstant; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.exception.query.QueryProcessException; - -import com.google.common.net.InetAddresses; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,7 +95,6 @@ public void replaceHostnameWithIp() throws UnknownHostException, BadSeedUrlForma config.setInternalIp(hostnameToIP(config.getInternalIp())); } List newSeedUrls = new ArrayList<>(); - logger.info("seed urls:" + config.getSeedNodeUrls()); for (String seedUrl : config.getSeedNodeUrls()) { String[] splits = seedUrl.split(":"); if (splits.length != 2) { @@ -112,7 +110,6 @@ public void replaceHostnameWithIp() throws UnknownHostException, BadSeedUrlForma } } config.setSeedNodeUrls(newSeedUrls); - logger.info("after replace, seed urls:" + config.getSeedNodeUrls()); logger.debug( "after replace, the rpcIP={}, internalIP={}, seedUrls={}", IoTDBDescriptor.getInstance().getConfig().getRpcAddress(), From 750f7759852c78dd22e8b9dac70e913e49b66ddb Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Fri, 23 Apr 2021 09:00:42 +0800 Subject: [PATCH 12/17] apply spotless --- .../src/main/java/org/apache/iotdb/cluster/ClusterMain.java | 1 + .../org/apache/iotdb/cluster/config/ClusterDescriptor.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java index 553aee8b5b2e..b5c0110b8383 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java @@ -35,6 +35,7 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.exception.StartupException; import org.apache.iotdb.db.exception.query.QueryProcessException; + import org.apache.thrift.TException; import org.apache.thrift.async.TAsyncClientManager; import org.apache.thrift.protocol.TBinaryProtocol.Factory; diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java index af66b115c308..25f85e038740 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/config/ClusterDescriptor.java @@ -19,11 +19,12 @@ package org.apache.iotdb.cluster.config; -import com.google.common.net.InetAddresses; import org.apache.iotdb.cluster.exception.BadSeedUrlFormatException; import org.apache.iotdb.db.conf.IoTDBConstant; import org.apache.iotdb.db.conf.IoTDBDescriptor; import org.apache.iotdb.db.exception.query.QueryProcessException; + +import com.google.common.net.InetAddresses; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From 178026618c722e026fcce257d4e1fa643bafc905 Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Fri, 23 Apr 2021 12:04:37 +0800 Subject: [PATCH 13/17] change version to 0.13.0 --- testcontainer/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testcontainer/pom.xml b/testcontainer/pom.xml index a04c6d62491d..ecd16b780891 100644 --- a/testcontainer/pom.xml +++ b/testcontainer/pom.xml @@ -23,7 +23,7 @@ org.apache.iotdb iotdb-parent - 0.12.0-SNAPSHOT + 0.13.0-SNAPSHOT ../pom.xml 4.0.0 From b836fff25564944cf91246120a01b279da6d4565 Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Fri, 23 Apr 2021 18:26:43 +0800 Subject: [PATCH 14/17] fix relateive path error in test/ docker-compose.yaml --- test/e2e/base/docker-compose.yaml | 4 ++-- test/e2e/cases/cli/cleanup.sh | 0 test/e2e/cases/cli/run.sh | 0 3 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 test/e2e/cases/cli/cleanup.sh mode change 100644 => 100755 test/e2e/cases/cli/run.sh diff --git a/test/e2e/base/docker-compose.yaml b/test/e2e/base/docker-compose.yaml index 08ebc3b03440..f536ec696620 100644 --- a/test/e2e/base/docker-compose.yaml +++ b/test/e2e/base/docker-compose.yaml @@ -23,7 +23,7 @@ services: server-prototype: build: context: ../../.. - dockerfile: ../../../docker/src/main/Dockerfile-single + dockerfile: docker/src/main/Dockerfile-single ports: - 6667:6667 networks: @@ -37,7 +37,7 @@ services: initializer: build: context: ../../.. - dockerfile: ../../../docker/src/main/Dockerfile-single + dockerfile: docker/src/main/Dockerfile-single networks: iotdb: entrypoint: diff --git a/test/e2e/cases/cli/cleanup.sh b/test/e2e/cases/cli/cleanup.sh old mode 100644 new mode 100755 diff --git a/test/e2e/cases/cli/run.sh b/test/e2e/cases/cli/run.sh old mode 100644 new mode 100755 From 5bd711f088b3b150e682bce47ec2e837071fc8c4 Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Sat, 24 Apr 2021 00:17:33 +0800 Subject: [PATCH 15/17] fix e2e test in github action --- .github/workflows/e2e.yml | 4 ++-- .../src/main/java/org/apache/iotdb/cluster/ClusterMain.java | 2 +- testcontainer/Readme.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 8700aff2d5dc..b668c5e138e1 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -39,7 +39,7 @@ jobs: restore-keys: ${{ runner.os }}-m2 - name: Build Distribution Zip - run: ./mvnw.sh -B -DskipTests clean package + run: ./mvnw.sh -B -DskipTests clean install - name: Build Docker Image run: | @@ -55,4 +55,4 @@ jobs: - name: TestContainer run: | - mvn integration-test -pl testcontainer + mvn -B integration-test -pl testcontainer diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java index 553aee8b5b2e..1cc638b75c68 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java @@ -170,7 +170,7 @@ private static void startServerCheck() throws StartupException { seedNodes.add(node); } - // assert this node is in all nodes when restart 172.19.0.2:9003, 172.19.0.3:9003, + // assert this node is in all nodes when restart if (!metaServer.getMember().getAllNodes().isEmpty()) { if (!metaServer.getMember().getAllNodes().contains(metaServer.getMember().getThisNode())) { String message = diff --git a/testcontainer/Readme.md b/testcontainer/Readme.md index e7c58d4e1ff3..234c6861b65e 100644 --- a/testcontainer/Readme.md +++ b/testcontainer/Readme.md @@ -34,7 +34,7 @@ The logic is, for Unix-like system, it checks whether `/var/run/docker.sock` exi For Window system, it checks whether `C:\Program Files\Docker\Docker\resources\bin\docker.exe` exists. If you are sure you have installed the Docker but `testcontainer` module is not loaed, use `-P unixDockerCheck` -in your maven command. +in your maven command, which also works on Windows OS. ## Behavior From f7a8de692c9928a1ec951c4d035e129a3ce66f93 Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Sat, 24 Apr 2021 00:21:41 +0800 Subject: [PATCH 16/17] remove unused logs --- cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java index ec6d50e20cdd..dc3e767bd8dd 100644 --- a/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java +++ b/cluster/src/main/java/org/apache/iotdb/cluster/ClusterMain.java @@ -157,7 +157,7 @@ private static void startServerCheck() throws StartupException { config.getSeedNodeUrls().size(), quorum); throw new StartupException(metaServer.getMember().getName(), message); } - logger.info("seed urls in start Server Check 3:" + config.getSeedNodeUrls()); + // assert not duplicated nodes Set seedNodes = new HashSet<>(); for (String url : config.getSeedNodeUrls()) { From c55c9b1a62020040af9cff46a3454a4b1a8e6ca4 Mon Sep 17 00:00:00 2001 From: xiangdong huang Date: Sat, 24 Apr 2021 11:49:43 +0800 Subject: [PATCH 17/17] add logback space --- testcontainer/src/test/resources/logback-container.xml | 1 - testcontainer/src/test/resources/logback.xml | 1 - 2 files changed, 2 deletions(-) diff --git a/testcontainer/src/test/resources/logback-container.xml b/testcontainer/src/test/resources/logback-container.xml index 7a5f7f918fce..e897fe24cb4d 100644 --- a/testcontainer/src/test/resources/logback-container.xml +++ b/testcontainer/src/test/resources/logback-container.xml @@ -33,7 +33,6 @@ DEBUG - diff --git a/testcontainer/src/test/resources/logback.xml b/testcontainer/src/test/resources/logback.xml index b0e7f31b04e2..098f463a66d3 100644 --- a/testcontainer/src/test/resources/logback.xml +++ b/testcontainer/src/test/resources/logback.xml @@ -33,7 +33,6 @@ DEBUG - System.out