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/06 17:36:51 UTC

[iotdb] 01/01: 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 35250170bde2c14fbd03a677e02c2fb1c01d4116
Author: xiangdong huang <sa...@gmail.com>
AuthorDate: Wed Apr 7 01:35:58 2021 +0800

    try test container
---
 pom.xml                                            | 65 ++++++++++++++++++++
 .../container/org/apache/iotdb/db/sql/SqlE2E.java  | 69 ++++++++++++++++++++++
 .../src/test/resources/testcontainers.properties   | 17 ++++++
 3 files changed, 151 insertions(+)

diff --git a/pom.xml b/pom.xml
index 1c2b0f3..0728d88 100644
--- a/pom.xml
+++ b/pom.xml
@@ -155,6 +155,8 @@
         <!-- disable enforcer by default-->
         <enforcer.skip>true</enforcer.skip>
         <spotless.version>2.4.2</spotless.version>
+        <!-- we will concat ${basedir}/src/test/${docker.test.folder} as the test source folder-->
+        <docker.test.folder>java</docker.test.folder>
     </properties>
     <!--
         if we claim dependencies in dependencyManagement, then we do not claim
@@ -508,6 +510,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 +906,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,6 +920,7 @@
                             <includes>
                                 <!-- Include integration tests within integration-test phase. -->
                                 <include>src/test/**/*IT.java</include>
+                                <include>src/test/**/*E2E.java</include>
                             </includes>
                         </configuration>
                     </execution>
@@ -1363,5 +1373,60 @@
                 <enforcer.skip>false</enforcer.skip>
             </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>
+            <properties>
+                <docker.test.folder>container</docker.test.folder>
+            </properties>
+        </profile>
+        <profile>
+            <id>WinDockerCheck</id>
+            <activation>
+                <file>
+                    <exists>C:\Program Files\Docker\Docker\resources\bin\docker.exe</exists>
+                </file>
+            </activation>
+            <properties>
+                <docker.test.folder>container</docker.test.folder>
+            </properties>
+        </profile>
+        <!-- If docker exist, we add src/test/container as the test source folder.
+        Otherwise, we just add src/test/java as the test source folder, which does not take any effect.-->
+        <profile>
+            <id>dockerTest</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <build>
+                <plugins>
+                    <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/${docker.test.folder}</source>
+                                    </sources>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
     </profiles>
 </project>
diff --git a/server/src/test/container/org/apache/iotdb/db/sql/SqlE2E.java b/server/src/test/container/org/apache/iotdb/db/sql/SqlE2E.java
new file mode 100644
index 0000000..299a98d
--- /dev/null
+++ b/server/src/test/container/org/apache/iotdb/db/sql/SqlE2E.java
@@ -0,0 +1,69 @@
+/*
+ * 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.GenericContainer;
+import org.testcontainers.images.builder.ImageFromDockerfile;
+
+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(
+          new ImageFromDockerfile().withDockerfile(new File("../docker/src/Dockerfile").toPath()));
+
+  @Before
+  public void setUp() throws Exception {
+
+    Class.forName(Config.JDBC_DRIVER_NAME);
+    connection = DriverManager.getConnection("jdbc:iotdb://127.0.0.1:6667/", "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/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.
+