You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hx...@apache.org on 2021/04/17 16:07:45 UTC
[iotdb] 01/14: try test container
This is an automated email from the ASF dual-hosted git repository.
hxd pushed a commit to branch testcontainer
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 5ae6666c00979afca7f2882e13b0fc1b6ac09ff1
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Wed Apr 7 01:35:58 2021 +0800
try test container
---
docker/src/main/{Dockerfile => Dockerfile-cluster} | 4 +-
docker/src/main/{Dockerfile => Dockerfile-single} | 2 +-
pom.xml | 36 +++++++
.../src/test/resources/testcontainers.properties | 17 +++
test/e2e/base/docker-compose.yaml | 4 +-
testcontainer/pom.xml | 118 +++++++++++++++++++++
.../test/java/org/apache/iotdb/db/sql/SqlE2E.java | 85 +++++++++++++++
.../test/resources/composes/docker-compose-3.yaml | 28 ++---
.../src/test/resources/iotdb-engine.properties | 24 +++++
9 files changed, 293 insertions(+), 25 deletions(-)
diff --git a/docker/src/main/Dockerfile b/docker/src/main/Dockerfile-cluster
similarity index 92%
copy from docker/src/main/Dockerfile
copy to docker/src/main/Dockerfile-cluster
index 402227c..277132b 100644
--- a/docker/src/main/Dockerfile
+++ b/docker/src/main/Dockerfile-cluster
@@ -21,7 +21,7 @@
FROM openjdk:11-jre-slim
-ADD distribution/target/apache-iotdb-*-all-bin.zip /
+ADD distribution/target/apache-iotdb-*-cluster-bin.zip /
RUN apt update \
&& apt install lsof procps unzip -y \
@@ -40,4 +40,4 @@ EXPOSE 8181
VOLUME /iotdb/data
VOLUME /iotdb/logs
ENV PATH="/iotdb/sbin/:/iotdb/tools/:${PATH}"
-ENTRYPOINT ["/iotdb/sbin/start-server.sh"]
+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 402227c..c0e00a9 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 1c2b0f3..eb27a42 100644
--- a/pom.xml
+++ b/pom.xml
@@ -508,6 +508,12 @@
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ <version>1.15.2</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<pluginManagement>
@@ -898,6 +904,7 @@
<excludes>
<!-- Exclude integration tests within (unit) test phase. -->
<exclude>src/test/**/*IT.java</exclude>
+ <exclude>src/test/**/*E2E.java</exclude>
</excludes>
</configuration>
</execution>
@@ -911,7 +918,12 @@
<includes>
<!-- Include integration tests within integration-test phase. -->
<include>src/test/**/*IT.java</include>
+ <include>src/test/**/*E2E.java</include>
</includes>
+ <excludes>
+ <!-- Exclude unit tests within (unit) test phase. -->
+ <exclude>src/test/**/*Test.java</exclude>
+ </excludes>
</configuration>
</execution>
</executions>
@@ -991,6 +1003,30 @@
<thrift.exec-cmd.args>+x ${project.build.directory}/tools/${thrift.executable}</thrift.exec-cmd.args>
</properties>
</profile>
+ <!-- for TestContainer. As it requires docker, we have to detect whether docker exists.-->
+ <profile>
+ <!-- Mac and Unix-->
+ <id>unixDockerCheck</id>
+ <activation>
+ <file>
+ <exists>/var/run/docker.sock</exists>
+ </file>
+ </activation>
+ <modules>
+ <module>testcontainer</module>
+ </modules>
+ </profile>
+ <profile>
+ <id>WinDockerCheck</id>
+ <activation>
+ <file>
+ <exists>C:\Program Files\Docker\Docker\resources\bin\docker.exe</exists>
+ </file>
+ </activation>
+ <modules>
+ <module>testcontainer</module>
+ </modules>
+ </profile>
<!-- Some APIs were removed in Java 11, so we need to add replacements -->
<profile>
<id>java-11-and-above</id>
diff --git a/server/src/test/resources/testcontainers.properties b/server/src/test/resources/testcontainers.properties
new file mode 100644
index 0000000..af6effe
--- /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 d4970d4..08ebc3b 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 0000000..f8bb9f6
--- /dev/null
+++ b/testcontainer/pom.xml
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.iotdb</groupId>
+ <artifactId>iotdb-parent</artifactId>
+ <version>0.12.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>testcontainer</artifactId>
+ <properties>
+ <docker.test.skip>false</docker.test.skip>
+ <docker.build.executable>docker</docker.build.executable>
+ <docker.build.single.argument>build -t apache/iotdb:maven-development -f ${basedir}/../docker/src/main/Dockerfile-single ${basedir}/../.</docker.build.single.argument>
+ <docker.clean.single.argument>image rm apache/iotdb:maven-development</docker.clean.single.argument>
+ <docker.build.cluster.argument>build -t apache/iotdb:cluster-maven-development -f ${basedir}/../docker/src/main/Dockerfile-cluster ${basedir}/../.</docker.build.cluster.argument>
+ <docker.clean.cluster.argument>image rm apache/iotdb:cluster-maven-development</docker.clean.cluster.argument>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.iotdb</groupId>
+ <artifactId>iotdb-jdbc</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.iotdb</groupId>
+ <artifactId>iotdb-session</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.iotdb</groupId>
+ <artifactId>iotdb-cli</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <!-- before integration test, we build the docker image -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.6.0</version>
+ <executions>
+ <execution>
+ <id>build-docker-image</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <skip>${docker.test.skip}</skip>
+ <executable>${docker.build.executable}</executable>
+ <commandlineArgs>${docker.build.single.argument}</commandlineArgs>
+ </configuration>
+ </execution>
+ <execution>
+ <id>build-cluster-docker-image</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <skip>${docker.test.skip}</skip>
+ <executable>${docker.build.executable}</executable>
+ <commandlineArgs>${docker.build.cluster.argument}</commandlineArgs>
+ </configuration>
+ </execution>
+ <execution>
+ <id>clean-docker-image</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <skip>${docker.test.skip}</skip>
+ <executable>${docker.build.executable}</executable>
+ <commandlineArgs>${docker.clean.single.argument}</commandlineArgs>
+ </configuration>
+ </execution>
+ <execution>
+ <id>clean-cluster-docker-image</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ <configuration>
+ <skip>${docker.test.skip}</skip>
+ <executable>${docker.build.executable}</executable>
+ <commandlineArgs>${docker.clean.cluster.argument}</commandlineArgs>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>3.2.0</version>
+ <executions>
+ <execution>
+ <id>add-test-container-source</id>
+ <phase>generate-test-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${basedir}/src/test/java</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/testcontainer/src/test/java/org/apache/iotdb/db/sql/SqlE2E.java b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SqlE2E.java
new file mode 100644
index 0000000..4fec53e
--- /dev/null
+++ b/testcontainer/src/test/java/org/apache/iotdb/db/sql/SqlE2E.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 SqlE2E {
+ 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/test/e2e/base/docker-compose.yaml b/testcontainer/src/test/resources/composes/docker-compose-3.yaml
similarity index 68%
copy from test/e2e/base/docker-compose.yaml
copy to testcontainer/src/test/resources/composes/docker-compose-3.yaml
index d4970d4..e345335 100644
--- a/test/e2e/base/docker-compose.yaml
+++ b/testcontainer/src/test/resources/composes/docker-compose-3.yaml
@@ -20,32 +20,20 @@
version: '3.8'
services:
- server-prototype:
- build:
- context: ../../..
- dockerfile: docker/src/main/Dockerfile
- ports:
- - 6667:6667
+ iotdb-server:
+ image: apache/iotdb:cluster-maven-development
+ expose:
+ - 6667
+ - 9003
+ - 40010
networks:
- iotdb:
+ - iotdb
healthcheck:
test: [ "CMD", "bash", "-c", "cat < /dev/null > /dev/tcp/127.0.0.1/6667" ]
interval: 5s
timeout: 60s
retries: 120
- initializer:
- build:
- context: ../../..
- dockerfile: docker/src/main/Dockerfile
- networks:
- iotdb:
- entrypoint:
- - bash
- - -c
- - |
- cat /res/init.sql | grep -v '^--' | xargs -I {} /iotdb/sbin/start-cli.sh -h server -e {}
- echo "Ready to Run IoTDB E2E Tests"
-
networks:
iotdb:
+ driver: bridge
diff --git a/testcontainer/src/test/resources/iotdb-engine.properties b/testcontainer/src/test/resources/iotdb-engine.properties
new file mode 100644
index 0000000..960aa13
--- /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