tests: add test

This commit is contained in:
Shuaiqiang Chang 2020-06-09 22:41:13 +08:00
parent 2bb969a9fb
commit f732250271
7 changed files with 211 additions and 123 deletions

View File

@ -1,119 +1,136 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.taosdata.jdbc</groupId>
<groupId>com.taosdata.jdbc</groupId> <artifactId>taos-jdbcdriver</artifactId>
<artifactId>taos-jdbcdriver</artifactId> <version>1.0.3</version>
<version>1.0.3</version> <packaging>jar</packaging>
<packaging>jar</packaging> <name>JDBCDriver</name>
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
<name>JDBCDriver</name> <description>TDengine JDBC Driver</description>
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url> <licenses>
<description>TDengine JDBC Driver</description> <license>
<name>GNU AFFERO GENERAL PUBLIC LICENSE Version 3</name>
<licenses> <url>https://github.com/taosdata/TDengine/blob/master/LICENSE</url>
<license> <distribution>repo</distribution>
<name>GNU AFFERO GENERAL PUBLIC LICENSE Version 3</name> </license>
<url>https://github.com/taosdata/TDengine/blob/master/LICENSE</url> </licenses>
<distribution>repo</distribution> <scm>
</license> <connection>scm:git:git://github.com/taosdata/TDengine.git</connection>
</licenses> <developerConnection>scm:git:git@github.com:taosdata/TDengine.git</developerConnection>
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
<scm> <tag>HEAD</tag>
<connection>scm:git:git://github.com/taosdata/TDengine.git</connection> </scm>
<developerConnection>scm:git:git@github.com:taosdata/TDengine.git</developerConnection> <developers>
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url> <developer>
<tag>HEAD</tag> <name>taosdata</name>
</scm> <email>support@taosdata.com</email>
<organization>https://www.taosdata.com/</organization>
<developers> <organizationUrl>https://www.taosdata.com/</organizationUrl>
<developer> </developer>
<name>taosdata</name> </developers>
<email>support@taosdata.com</email> <properties>
<organization>https://www.taosdata.com/</organization> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<organizationUrl>https://www.taosdata.com/</organizationUrl> <java.version>1.8</java.version>
</developer> <maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
</developers> <commons-logging.version>1.1.2</commons-logging.version>
<commons-lang3.version>3.5</commons-lang3.version>
<properties> </properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <dependencies>
<java.version>1.8</java.version> <dependency>
<groupId>commons-logging</groupId>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version> <artifactId>commons-logging</artifactId>
<version>${commons-logging.version}</version>
<commons-logging.version>1.1.2</commons-logging.version> <exclusions>
<commons-lang3.version>3.5</commons-lang3.version> <exclusion>
</properties> <groupId>*</groupId>
<artifactId>*</artifactId>
<dependencies> </exclusion>
<dependency> </exclusions>
<groupId>commons-logging</groupId> </dependency>
<artifactId>commons-logging</artifactId> <dependency>
<version>${commons-logging.version}</version> <groupId>org.apache.commons</groupId>
<exclusions> <artifactId>commons-lang3</artifactId>
<exclusion> <version>${commons-lang3.version}</version>
<groupId>*</groupId> </dependency>
<artifactId>*</artifactId> <dependency>
</exclusion> <groupId>junit</groupId>
</exclusions> <artifactId>junit</artifactId>
</dependency> <version>4.8.2</version>
<dependency> <scope>test</scope>
<groupId>org.apache.commons</groupId> </dependency>
<artifactId>commons-lang3</artifactId> <dependency>
<version>${commons-lang3.version}</version> <groupId>org.jacoco</groupId>
</dependency> <artifactId>jacoco-maven-plugin</artifactId>
<dependency> <version>0.8.3</version>
<groupId>junit</groupId> </dependency>
<artifactId>junit</artifactId> </dependencies>
<version>4.8.2</version> <build>
<scope>test</scope> <plugins>
</dependency> <plugin>
</dependencies> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<build> <version>3.0.0</version>
<plugins> <configuration>
<plugin> <descriptors>
<groupId>org.apache.maven.plugins</groupId> <descriptor>src/main/assembly/assembly-jar.xml</descriptor>
<artifactId>maven-assembly-plugin</artifactId> </descriptors>
<version>3.0.0</version> </configuration>
<configuration> <executions>
<descriptors> <execution>
<!--<descriptor>src/main/assembly/assembly.xml</descriptor>--> <id>make-assembly</id>
<descriptor>src/main/assembly/assembly-jar.xml</descriptor> <phase>package</phase>
</descriptors> <goals>
</configuration> <goal>single</goal>
<executions> </goals>
<execution> </execution>
<id>make-assembly</id> </executions>
<phase>package</phase> </plugin>
<goals> <plugin>
<goal>single</goal> <groupId>org.apache.maven.plugins</groupId>
</goals> <artifactId>maven-compiler-plugin</artifactId>
</execution> <version>${maven-compiler-plugin.version}</version>
</executions> <configuration>
</plugin> <encoding>UTF-8</encoding>
<plugin> <source>${java.version}</source>
<groupId>org.apache.maven.plugins</groupId> <target>${java.version}</target>
<artifactId>maven-compiler-plugin</artifactId> <debug>true</debug>
<version>${maven-compiler-plugin.version}</version> <showDeprecation>true</showDeprecation>
<configuration> </configuration>
<encoding>UTF-8</encoding> </plugin>
<source>${java.version}</source> <plugin>
<target>${java.version}</target> <groupId>org.apache.maven.plugins</groupId>
<debug>true</debug> <artifactId>maven-surefire-plugin</artifactId>
<showDeprecation>true</showDeprecation> <version>2.12.4</version>
</configuration> <configuration>
</plugin> <testFailureIgnore>true</testFailureIgnore>
<plugin> </configuration>
<groupId>org.apache.maven.plugins</groupId> </plugin>
<artifactId>maven-surefire-plugin</artifactId> <plugin>
<version>2.12.4</version> <groupId>org.jacoco</groupId>
<configuration> <artifactId>jacoco-maven-plugin</artifactId>
<testFailureIgnore>true</testFailureIgnore> <version>0.8.3</version>
</configuration> <configuration>
</plugin> <includes>
</plugins> <include>com/**/*</include>
</build> </includes>
</configuration>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -22,6 +22,7 @@ public class TestPreparedStatement {
} }
} }
resSet.close(); resSet.close();
pstmt.close();
connection.close(); connection.close();
} catch (Exception e) { } catch (Exception e) {

View File

@ -12,7 +12,7 @@ import java.util.Properties;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class TSDBAsyncSubscribeTest { public class AsyncSubscribeTest {
Connection connection = null; Connection connection = null;
Statement statement = null; Statement statement = null;
String dbName = "test"; String dbName = "test";

View File

@ -9,7 +9,7 @@ import java.util.Properties;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class TSDBImportTest { public class ImportTest {
Connection connection = null; Connection connection = null;
Statement statement = null; Statement statement = null;
String dbName = "test"; String dbName = "test";
@ -36,7 +36,7 @@ public class TSDBImportTest {
} }
@Test @Test
public void insertInto() throws Exception { public void insertData() throws Exception {
long ts = 1496732686000l; long ts = 1496732686000l;
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
@ -49,6 +49,7 @@ public class TSDBImportTest {
@Test @Test
public void selectData() throws Exception { public void selectData() throws Exception {
insertData();
String sql = "select * from test.t0"; String sql = "select * from test.t0";
ResultSet resSet = statement.executeQuery(sql); ResultSet resSet = statement.executeQuery(sql);
@ -61,7 +62,7 @@ public class TSDBImportTest {
} }
@Test @Test
public void importInto() throws Exception { public void importData() throws Exception {
// 避免时间重复 // 避免时间重复
long ts = 1496732686000l; long ts = 1496732686000l;
@ -78,7 +79,7 @@ public class TSDBImportTest {
assertEquals(10, rows); assertEquals(10, rows);
} }
// @After @After
public void close() throws Exception { public void close() throws Exception {
statement.executeUpdate("drop database " + dbName); statement.executeUpdate("drop database " + dbName);
statement.close(); statement.close();

View File

@ -0,0 +1,65 @@
package com.taosdata.jdbc;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
public class SelectTest {
Connection connection = null;
Statement statement = null;
String dbName = "test";
String tName = "t0";
String host = "localhost";
@Before
public void createDatabaseAndTable() throws SQLException {
try {
Class.forName("com.taosdata.jdbc.TSDBDriver");
} catch (ClassNotFoundException e) {
return;
}
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata"
, properties);
statement = connection.createStatement();
statement.executeUpdate("drop database if exists " + dbName);
statement.executeUpdate("create database if not exists " + dbName);
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
}
@Test
public void selectData() throws SQLException {
long ts = 1496732686000l;
for (int i = 0; i < 50; i++) {
ts++;
int row = statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")");
System.out.println("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")\t" + row);
assertEquals(1, row);
}
String sql = "select * from " + dbName + "." + tName;
ResultSet resSet = statement.executeQuery(sql);
int num = 0;
while (resSet.next()) {
num++;
}
resSet.close();
assertEquals(num, 50);
}
public void close() throws SQLException {
statement.executeUpdate("drop database " + dbName);
statement.close();
connection.close();
}
}

View File

@ -0,0 +1,4 @@
package com.taosdata.jdbc;
public class StableTest {
}

View File

@ -12,7 +12,7 @@ import java.util.Properties;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class TSDBSubscribeTest { public class SubscribeTest {
Connection connection = null; Connection connection = null;
Statement statement = null; Statement statement = null;
String dbName = "test"; String dbName = "test";