diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java index d4c30115f851aa0f8b6f80994bbece609649428d..78420083a1d235036203bb3d57b2617663032d8d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java @@ -14,13 +14,43 @@ import java.math.BigDecimal; import java.sql.*; import java.time.Instant; import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException; +import java.time.format.ResolverStyle; +import java.time.temporal.ChronoField; import java.util.ArrayList; import java.util.Calendar; import java.util.List; public class RestfulResultSet extends AbstractResultSet implements ResultSet { + public static DateTimeFormatter rfc3339Parser = null; + + { + rfc3339Parser = new DateTimeFormatterBuilder() + .parseCaseInsensitive() + .appendValue(ChronoField.YEAR, 4) + .appendLiteral('-') + .appendValue(ChronoField.MONTH_OF_YEAR, 2) + .appendLiteral('-') + .appendValue(ChronoField.DAY_OF_MONTH, 2) + .appendLiteral('T') + .appendValue(ChronoField.HOUR_OF_DAY, 2) + .appendLiteral(':') + .appendValue(ChronoField.MINUTE_OF_HOUR, 2) + .appendLiteral(':') + .appendValue(ChronoField.SECOND_OF_MINUTE, 2) + .optionalStart() + .appendFraction(ChronoField.NANO_OF_SECOND, 2, 9, true) + .optionalEnd() + .appendOffset("+HH:MM", "Z").toFormatter() + .withResolverStyle(ResolverStyle.STRICT) + .withChronology(IsoChronology.INSTANCE); + } + private final Statement statement; // data private final List> resultSet = new ArrayList<>(); @@ -187,25 +217,41 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { } case UTC: { String value = row.getString(colIndex); - long epochSec = Timestamp.valueOf(value.substring(0, 19).replace("T", " ")).getTime() / 1000; - int fractionalSec = Integer.parseInt(value.substring(20, value.length() - 5)); - long nanoAdjustment; - if (value.length() > 31) { - // ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x00 - nanoAdjustment = fractionalSec; - this.timestampPrecision = TimestampPrecision.NS; - } else if (value.length() > 28) { - // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x00 - nanoAdjustment = fractionalSec * 1000L; - this.timestampPrecision = TimestampPrecision.US; + if (value.lastIndexOf(":") > 19) { + ZonedDateTime parse = ZonedDateTime.parse(value, rfc3339Parser); + long nanoAdjustment; + if (value.length() > 32) { + // ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x:00 + this.timestampPrecision = TimestampPrecision.NS; + } else if (value.length() > 29) { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x:00 + this.timestampPrecision = TimestampPrecision.US; + } else { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x:00 + this.timestampPrecision = TimestampPrecision.MS; + } + return Timestamp.from(parse.toInstant()); } else { - // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x00 - nanoAdjustment = fractionalSec * 1000_000L; - this.timestampPrecision = TimestampPrecision.MS; + long epochSec = Timestamp.valueOf(value.substring(0, 19).replace("T", " ")).getTime() / 1000; + int fractionalSec = Integer.parseInt(value.substring(20, value.length() - 5)); + long nanoAdjustment; + if (value.length() > 32) { + // ns timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSSSSS+0x00 + nanoAdjustment = fractionalSec; + this.timestampPrecision = TimestampPrecision.NS; + } else if (value.length() > 29) { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSSSSS+0x00 + nanoAdjustment = fractionalSec * 1000L; + this.timestampPrecision = TimestampPrecision.US; + } else { + // ms timestamp: yyyy-MM-ddTHH:mm:ss.SSS+0x00 + nanoAdjustment = fractionalSec * 1000_000L; + this.timestampPrecision = TimestampPrecision.MS; + } + ZoneOffset zoneOffset = ZoneOffset.of(value.substring(value.length() - 5)); + Instant instant = Instant.ofEpochSecond(epochSec, nanoAdjustment).atOffset(zoneOffset).toInstant(); + return Timestamp.from(instant); } - ZoneOffset zoneOffset = ZoneOffset.of(value.substring(value.length() - 5)); - Instant instant = Instant.ofEpochSecond(epochSec, nanoAdjustment).atOffset(zoneOffset).toInstant(); - return Timestamp.from(instant); } case STRING: default: { diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index cdcd2eec482cc39e940bf20f6ae636568257faf2..dada75e4a04b035cbe20da72075215c77f1c5883 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -72,6 +72,7 @@ public class RestfulStatement extends AbstractStatement { } this.database = sql.trim().replace("use", "").trim(); this.conn.setCatalog(this.database); + this.conn.setClientInfo(TSDBDriver.PROPERTY_KEY_DBNAME, this.database); result = false; } else if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) { executeOneQuery(sql); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ParameterBindTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ParameterBindTest.java index 46f201d1c0a525f52014d133e25fc0db4741050c..63c3a6318a611f7159c0ac16dc85cd5e05de47c0 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ParameterBindTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ParameterBindTest.java @@ -128,8 +128,8 @@ public class ParameterBindTest { @After public void after() { try { -// Statement stmt = conn.createStatement(); -// stmt.execute("drop database if exists test_pd"); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists test_pd"); if (conn != null) conn.close(); } catch (SQLException e) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java index 712cc0c8c1b0b094a20db0fe36d33f553878d71d..cc47a47f1cd2f0a0c8efdde5ab7afa39b395a16d 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SchemalessInsertTest.java @@ -187,7 +187,6 @@ public class SchemalessInsertTest { public void after() { try (Statement stmt = conn.createStatement()) { stmt.execute("drop database if exists " + dbname); - stmt.close(); conn.close(); } catch (SQLException e) { e.printStackTrace(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java index 64b7ab1cabe2c5815ff87d9881873150f21049c6..c69a556ae4e6c6b31dbb106c7ff4a3e2352296ee 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBConnectionTest.java @@ -380,8 +380,12 @@ public class TSDBConnectionTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test"); + statement.close(); conn.close(); + } } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java index 9f297955d687f3cfcc3acef626e1f905ecee6bdf..609523f522724a9bf49e7ded76d2855cbdda6ac1 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java @@ -1,6 +1,5 @@ package com.taosdata.jdbc; -import org.junit.BeforeClass; import org.junit.Test; import java.sql.*; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java index f44d647595e99ae00a355ca25f702cf2e0c1cc36..f508fbdeed5bf617cf81330985981b5715678472 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java @@ -7,6 +7,7 @@ import org.junit.Test; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.sql.SQLException; +import java.sql.SQLWarning; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -19,115 +20,111 @@ public class TSDBJNIConnectorTest { private static TSDBResultSetRowData rowData; @Test - public void test() { + public void test() throws SQLException { try { - try { - //change sleepSeconds when debugging with attach to process to find PID - int sleepSeconds = -1; - if (sleepSeconds > 0) { - RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); - String jvmName = runtimeBean.getName(); - long pid = Long.valueOf(jvmName.split("@")[0]); - System.out.println("JVM PID = " + pid); - - Thread.sleep(sleepSeconds * 1000); - } - } catch (Exception e) { - e.printStackTrace(); + //change sleepSeconds when debugging with attach to process to find PID + int sleepSeconds = -1; + if (sleepSeconds > 0) { + RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); + String jvmName = runtimeBean.getName(); + long pid = Long.valueOf(jvmName.split("@")[0]); + System.out.println("JVM PID = " + pid); + + Thread.sleep(sleepSeconds * 1000); } + } catch (Exception e) { + e.printStackTrace(); + } - // init - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR, "/etc/taos"); - TSDBJNIConnector.init(properties); - - // connect - TSDBJNIConnector connector = new TSDBJNIConnector(); - connector.connect("127.0.0.1", 6030, null, "root", "taosdata"); - - // setup - String setupSqlStrs[] = {"create database if not exists d precision \"us\"", - "create table if not exists d.t(ts timestamp, f int)", - "create database if not exists d2", - "create table if not exists d2.t2(ts timestamp, f int)", - "insert into d.t values(now+100s, 100)", - "insert into d2.t2 values(now+200s, 200)" - }; - for (String setupSqlStr : setupSqlStrs) { - long setupSql = connector.executeQuery(setupSqlStr); - - assertEquals(0, connector.getResultTimePrecision(setupSql)); - if (connector.isUpdateQuery(setupSql)) { - connector.freeResultSet(setupSql); - } + // init + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CONFIG_DIR, "/etc/taos"); + TSDBJNIConnector.init(properties); + + // connect + TSDBJNIConnector connector = new TSDBJNIConnector(); + connector.connect("127.0.0.1", 6030, null, "root", "taosdata"); + + // setup + String setupSqlStrs[] = {"create database if not exists d precision \"us\"", + "create table if not exists d.t(ts timestamp, f int)", + "create database if not exists d2", + "create table if not exists d2.t2(ts timestamp, f int)", + "insert into d.t values(now+100s, 100)", + "insert into d2.t2 values(now+200s, 200)" + }; + for (String setupSqlStr : setupSqlStrs) { + long setupSql = connector.executeQuery(setupSqlStr); + + assertEquals(0, connector.getResultTimePrecision(setupSql)); + if (connector.isUpdateQuery(setupSql)) { + connector.freeResultSet(setupSql); } + } - { - long sqlObj1 = connector.executeQuery("select * from d2.t2"); - assertEquals(0, connector.getResultTimePrecision(sqlObj1)); - List columnMetaDataList = new ArrayList<>(); - int code = connector.getSchemaMetaData(sqlObj1, columnMetaDataList); - rowData = new TSDBResultSetRowData(columnMetaDataList.size()); - assertTrue(next(connector, sqlObj1)); - assertEquals(0, connector.getResultTimePrecision(sqlObj1)); - connector.freeResultSet(sqlObj1); - } + { + long sqlObj1 = connector.executeQuery("select * from d2.t2"); + assertEquals(0, connector.getResultTimePrecision(sqlObj1)); + List columnMetaDataList = new ArrayList<>(); + int code = connector.getSchemaMetaData(sqlObj1, columnMetaDataList); + rowData = new TSDBResultSetRowData(columnMetaDataList.size()); + assertTrue(next(connector, sqlObj1)); + assertEquals(0, connector.getResultTimePrecision(sqlObj1)); + connector.freeResultSet(sqlObj1); + } - // executeQuery - long pSql = connector.executeQuery("select * from d.t"); + // executeQuery + long pSql = connector.executeQuery("select * from d.t"); - if (connector.isUpdateQuery(pSql)) { - connector.freeResultSet(pSql); - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY); - } + if (connector.isUpdateQuery(pSql)) { + connector.freeResultSet(pSql); + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY); + } - assertEquals(1, connector.getResultTimePrecision(pSql)); + assertEquals(1, connector.getResultTimePrecision(pSql)); - // get schema - List columnMetaDataList = new ArrayList<>(); - int code = connector.getSchemaMetaData(pSql, columnMetaDataList); - if (code == TSDBConstants.JNI_CONNECTION_NULL) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); - } - if (code == TSDBConstants.JNI_RESULT_SET_NULL) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); - } - if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0); - } + // get schema + List columnMetaDataList = new ArrayList<>(); + int code = connector.getSchemaMetaData(pSql, columnMetaDataList); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); + } + if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); + } + if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_NUM_OF_FIELDS_0); + } + assertEquals(1, connector.getResultTimePrecision(pSql)); + int columnSize = columnMetaDataList.size(); + // print metadata + for (int i = 0; i < columnSize; i++) { +// System.out.println(columnMetaDataList.get(i)); + } + rowData = new TSDBResultSetRowData(columnSize); + // iterate resultSet + for (int i = 0; next(connector, pSql); i++) { assertEquals(1, connector.getResultTimePrecision(pSql)); - int columnSize = columnMetaDataList.size(); - // print metadata - for (int i = 0; i < columnSize; i++) { - System.out.println(columnMetaDataList.get(i)); - } - rowData = new TSDBResultSetRowData(columnSize); - // iterate resultSet - for (int i = 0; next(connector, pSql); i++) { - assertEquals(1, connector.getResultTimePrecision(pSql)); - System.out.println(); - } - // close resultSet - code = connector.freeResultSet(pSql); - if (code == TSDBConstants.JNI_CONNECTION_NULL) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); - } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); - } - // close statement - connector.executeQuery("use d"); - String[] lines = new String[]{ - "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000", - "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000"}; - connector.insertLines(lines, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO_SECONDS); - - // close connection - connector.closeConnection(); - - } catch (SQLException e) { - e.printStackTrace(); } + // close resultSet + code = connector.freeResultSet(pSql); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_CONNECTION_NULL); + } else if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); + } + // close statement + connector.executeQuery("use d"); + String[] lines = new String[]{ + "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000", + "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000"}; + connector.insertLines(lines, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO_SECONDS); + + // close connection + connector.executeQuery("drop database if exists d"); + connector.executeQuery("drop database if exists d2"); + connector.closeConnection(); } private static boolean next(TSDBJNIConnector connector, long pSql) throws SQLException { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java index dc41d85cf38c5fbedb6e5f5c26d593c8c9d5c4d7..56e8b96bbd9dee496969a010b0385c4ecd7f1145 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBParameterMetaDataTest.java @@ -17,6 +17,7 @@ public class TSDBParameterMetaDataTest { private static PreparedStatement pstmt_select; private static ParameterMetaData parameterMetaData_insert; private static ParameterMetaData parameterMetaData_select; + private static final String dbname = "test_pstmt"; @Test public void getParameterCount() throws SQLException { @@ -152,9 +153,9 @@ public class TSDBParameterMetaDataTest { try { conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists test_pstmt"); - stmt.execute("create database if not exists test_pstmt"); - stmt.execute("use test_pstmt"); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))"); stmt.execute("create table t1 using weather tags('beijing')"); } @@ -190,8 +191,12 @@ public class TSDBParameterMetaDataTest { pstmt_insert.close(); if (pstmt_select != null) pstmt_select.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java index 3d76e1f98d4f8aa1d0ba3d68395e4036c5b069e6..8cb4628884fdd85c1bfd6f24ac311d82687da5ab 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java @@ -1233,6 +1233,7 @@ public class TSDBPreparedStatementTest { try { Statement statement = conn.createStatement(); statement.execute("drop database if exists " + dbname); + statement.execute("drop database if exists dbtest"); statement.close(); if (conn != null) conn.close(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java index f72cbbec8c1b4c0acad1c83ffcbcb35c1fb8ea7b..7b9083bf9be242f8bcb21565a47d6092675e2d6e 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBResultSetTest.java @@ -668,8 +668,12 @@ public class TSDBResultSetTest { rs.close(); if (stmt != null) stmt.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists restful_test"); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertDbwithoutUseDbTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertDbwithoutUseDbTest.java index 05c7b0feca21f3f5b9062f9cbc26921aa607732a..60edcc506e9fea7bc055322b7b00d0f9e9d75591 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertDbwithoutUseDbTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertDbwithoutUseDbTest.java @@ -1,9 +1,6 @@ package com.taosdata.jdbc.cases; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; +import org.junit.*; import org.junit.runners.MethodSorters; import java.sql.*; @@ -16,36 +13,32 @@ public class InsertDbwithoutUseDbTest { private static final String host = "127.0.0.1"; private static Properties properties; private static final Random random = new Random(System.currentTimeMillis()); + private static final String dbname = "inWithoutDb"; @Test public void case001() throws SQLException { // prepare schema String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; Connection conn = DriverManager.getConnection(url, properties); - try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists inWithoutDb"); - stmt.execute("create database if not exists inWithoutDb"); - stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)"); - } + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("create table " + dbname + ".weather(ts timestamp, f1 int)"); + conn.close(); // execute insert - url = "jdbc:TAOS://127.0.0.1:6030/inWithoutDb?user=root&password=taosdata"; + url = "jdbc:TAOS://127.0.0.1:6030/" + dbname + "?user=root&password=taosdata"; conn = DriverManager.getConnection(url, properties); - try (Statement stmt = conn.createStatement()) { - int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")"); - Assert.assertEquals(1, affectedRow); - boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")"); - Assert.assertEquals(false, flag); - ResultSet rs = stmt.executeQuery("select count(*) from weather"); - rs.next(); - int count = rs.getInt("count(*)"); - Assert.assertEquals(2, count); - - } catch (SQLException e) { - e.printStackTrace(); - } - + stmt = conn.createStatement(); + int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")"); + Assert.assertEquals(1, affectedRow); + boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")"); + Assert.assertEquals(false, flag); + ResultSet rs = stmt.executeQuery("select count(*) from weather"); + rs.next(); + int count = rs.getInt("count(*)"); + Assert.assertEquals(2, count); conn.close(); } @@ -54,28 +47,25 @@ public class InsertDbwithoutUseDbTest { // prepare the schema final String url = "jdbc:TAOS-RS://" + host + ":6041/inWithoutDb?user=root&password=taosdata"; Connection conn = DriverManager.getConnection(url, properties); - try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists inWithoutDb"); - stmt.execute("create database if not exists inWithoutDb"); - stmt.execute("create table inWithoutDb.weather(ts timestamp, f1 int)"); - } - conn.close(); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("create table " + dbname + ".weather(ts timestamp, f1 int)"); + stmt.close(); // execute - conn = DriverManager.getConnection(url, properties); - try (Statement stmt = conn.createStatement()) { - int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")"); - Assert.assertEquals(1, affectedRow); - boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")"); - Assert.assertEquals(false, flag); - ResultSet rs = stmt.executeQuery("select count(*) from weather"); - rs.next(); - int count = rs.getInt("count(*)"); - Assert.assertEquals(2, count); - - } catch (SQLException e) { - e.printStackTrace(); - } + stmt = conn.createStatement(); + int affectedRow = stmt.executeUpdate("insert into weather(ts, f1) values(now," + random.nextInt(100) + ")"); + Assert.assertEquals(1, affectedRow); + boolean flag = stmt.execute("insert into weather(ts, f1) values(now + 10s," + random.nextInt(100) + ")"); + Assert.assertEquals(false, flag); + ResultSet rs = stmt.executeQuery("select count(*) from weather"); + rs.next(); + int count = rs.getInt("count(*)"); + Assert.assertEquals(2, count); + stmt.execute("drop database if exists " + dbname); + stmt.close(); + conn.close(); } @BeforeClass diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java index ac254bebf39f55b358883716e23ba72b695703f7..7cc1c811d136a974a8cd9b8d4b990fe206c9e98d 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java @@ -427,8 +427,12 @@ public class InsertSpecialCharacterJniTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbName); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java index eedccec6f1ad3aecbaebbd525788a68e7c236511..81e424971c90e75a0ca3e8d14b82eefc45e417c8 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java @@ -391,8 +391,12 @@ public class InsertSpecialCharacterRestfulTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists "+ dbName); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/JDBCTypeAndTypeCompareTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/JDBCTypeAndTypeCompareTest.java index eb3b2985dfaff1b956909a50ca23470279cb48ca..38e8d99afe4a9fbca8d7167df482b6c2ac6976d8 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/JDBCTypeAndTypeCompareTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/JDBCTypeAndTypeCompareTest.java @@ -1,19 +1,22 @@ package com.taosdata.jdbc.cases; +import org.junit.AfterClass; import org.junit.Test; import java.sql.*; public class JDBCTypeAndTypeCompareTest { + private static Connection conn; + private static final String dbname = "test"; @Test public void test() throws SQLException { - Connection conn = DriverManager.getConnection("jdbc:TAOS://192.168.17.156:6030/", "root", "taosdata"); + conn = DriverManager.getConnection("jdbc:TAOS://127.0.0.1:6030/", "root", "taosdata"); Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists test"); - stmt.execute("create database if not exists test"); - stmt.execute("use test"); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(10), f9 nchar(10) )"); stmt.execute("insert into weather values(now, 1, 2, 3.0, 4.0, 5, 6, true, 'test','test')"); @@ -29,6 +32,19 @@ public class JDBCTypeAndTypeCompareTest { } stmt.close(); - conn.close(); + } + + @AfterClass + public static void afterClass() { + try { + if (null != conn) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); + conn.close(); + } + } catch (SQLException e) { + e.printStackTrace(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java index eb8f134227713e4c41224dc6a561916427290864..0889170e656910181fe39f844e585c11f0d78d5e 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionJNITest.java @@ -47,7 +47,7 @@ public class MicroSecondPrecisionJNITest { Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos); ts = rs.getLong(1); - Assert.assertEquals(timestamp1, ts); + Assert.assertEquals(timestamp2, ts); } catch (SQLException e) { e.printStackTrace(); } @@ -79,8 +79,13 @@ public class MicroSecondPrecisionJNITest { @AfterClass public static void afterClass() { try { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database " + ms_timestamp_db); + statement.execute("drop database " + us_timestamp_db); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java index f418436a4afac5f16b27789eb43081f131bf1f92..48c5ef8a463452dc205c43247678bfd0f3e761a2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MicroSecondPrecisionRestfulTest.java @@ -47,7 +47,7 @@ public class MicroSecondPrecisionRestfulTest { Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos); ts = rs.getLong(1); - Assert.assertEquals(timestamp1, ts); + Assert.assertEquals(timestamp2, ts); } } @@ -77,7 +77,7 @@ public class MicroSecondPrecisionRestfulTest { Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos); ts = rs.getLong(1); - Assert.assertEquals(timestamp1, ts); + Assert.assertEquals(timestamp2, ts); } } @@ -107,7 +107,7 @@ public class MicroSecondPrecisionRestfulTest { Assert.assertEquals(timestamp2 % 1000_000l * 1000, nanos); ts = rs.getLong(1); - Assert.assertEquals(timestamp1, ts); + Assert.assertEquals(timestamp2, ts); } } @@ -142,12 +142,21 @@ public class MicroSecondPrecisionRestfulTest { } @AfterClass - public static void afterClass() throws SQLException { - if (conn1 != null) - conn1.close(); - if (conn2 != null) - conn2.close(); - if (conn3 != null) - conn3.close(); + public static void afterClass() { + try { + if (conn1 != null) { + Statement statement = conn1.createStatement(); + statement.execute("drop database if exists " + ms_timestamp_db); + statement.execute("drop database if exists " + us_timestamp_db); + statement.close(); + conn1.close(); + } + if (conn2 != null) + conn2.close(); + if (conn3 != null) + conn3.close(); + }catch (SQLException e){ + e.printStackTrace(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java index 0bf8334079e630bf61b7955a37c74401da24a947..220ac0e7ce023229c1e897b9125a4ebb2cae3687 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/MultiConnectionWithDifferentDbTest.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc.cases; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -90,4 +91,16 @@ public class MultiConnectionWithDifferentDbTest { } } + @After + public void after() { + String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; + try (Connection connection = DriverManager.getConnection(url); + Statement statement = connection.createStatement()) { + statement.execute("drop database if exists " + db1); + statement.execute("drop database if exists " + db2); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java index a84f5233974e9bd9acdbbe3ca8ae0404c11b34a1..c85c6f95a93df565cd5ff8eca91c0beeac3b3c02 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampJNITest.java @@ -1,9 +1,6 @@ package com.taosdata.jdbc.cases; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; import java.sql.*; import java.time.Instant; @@ -83,9 +80,9 @@ public class NanoSecondTimestampJNITest { // then long actual = rs.getLong(1); - Assert.assertEquals(ms, actual); + Assert.assertEquals(ns, actual); actual = rs.getLong("ts"); - Assert.assertEquals(ms, actual); + Assert.assertEquals(ns, actual); } @Test @@ -160,4 +157,18 @@ public class NanoSecondTimestampJNITest { } } + @AfterClass + public static void afterClass(){ + try { + if (null != conn){ + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); + conn.close(); + } + }catch (SQLException e){ + e.printStackTrace(); + } + } + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java index c8aaf5c6788d18e782e431ba4ed97fb69f4702ab..796f21ed21bb69e952042e89f61e0eb98fcf4273 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NanoSecondTimestampRestfulTest.java @@ -1,9 +1,6 @@ package com.taosdata.jdbc.cases; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.*; import java.sql.*; import java.time.Instant; @@ -83,9 +80,9 @@ public class NanoSecondTimestampRestfulTest { // then long actual = rs.getLong(1); - Assert.assertEquals(ms, actual); + Assert.assertEquals(ns, actual); actual = rs.getLong("ts"); - Assert.assertEquals(ms, actual); + Assert.assertEquals(ns, actual); } @Test @@ -160,4 +157,14 @@ public class NanoSecondTimestampRestfulTest { } } + @AfterClass + public static void afterClass() throws SQLException { + if (conn != null){ + try (Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists " + dbname); + } + conn.close(); + } + } + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java index 6efd9f5ebee29a122c2106439117738c44241597..8bbc2fe077a1292b24ee7cb67158620c96f9a605 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetJNITest.java @@ -45,7 +45,11 @@ public class NullValueInResultSetJNITest { @After public void after() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test_null"); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java index f331a58583db832124465492d07f24f1772348ce..08f641b96e86398d72d9ab42ccaed57e2227ecdc 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetRestfulTest.java @@ -47,7 +47,11 @@ public class NullValueInResultSetRestfulTest { @After public void after() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test_null"); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java index 61d767b5cf2bcd2e478de74e5f4bb8d66ad21678..890505ac65cf02deb85dd362ebd700291317e849 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetTest.java @@ -85,7 +85,11 @@ public class NullValueInResultSetTest { public static void afterClass() throws SQLException { if (conn_restful != null) conn_restful.close(); - if (conn_jni != null) + if (conn_jni != null) { + Statement statement = conn_jni.createStatement(); + statement.execute("drop database if exists test_null"); + statement.close(); conn_jni.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java index 2d336135e5d1dc28db010387ab838f17d9b9a9cc..76053ccc41895fcdc00ffe9da2252bf63313894e 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisionInNanoInJniTest.java @@ -62,8 +62,12 @@ public class TimestampPrecisionInNanoInJniTest { @AfterClass public static void afterClass() { try { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + ns_timestamp_db); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } @@ -83,7 +87,7 @@ public class TimestampPrecisionInNanoInJniTest { int nanos = rs.getTimestamp(1).getNanos(); Assert.assertEquals(ts % 1000_000_000l, nanos); long test_ts = rs.getLong(1); - Assert.assertEquals(ts / 1000_000l, test_ts); + Assert.assertEquals(ts, test_ts); } @Test diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisonInNanoRestTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisonInNanoRestTest.java index cfd6a066acc2c2abd94e525fb69d4027a317134c..4aedf867d408536fde6896e01f61ef13873d1624 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisonInNanoRestTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/TimestampPrecisonInNanoRestTest.java @@ -62,8 +62,12 @@ public class TimestampPrecisonInNanoRestTest { @AfterClass public static void afterClass() { try { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + ns_timestamp_db); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } @@ -83,7 +87,7 @@ public class TimestampPrecisonInNanoRestTest { int nanos = rs.getTimestamp(1).getNanos(); Assert.assertEquals(ts % 1000_000_000l, nanos); long test_ts = rs.getLong(1); - Assert.assertEquals(ts / 1000_000l, test_ts); + Assert.assertEquals(ts, test_ts); } @Test diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java index 0be6b90e7a9b5e1e7707b88c1c60d2751b7d245b..cff353093aca6772e96a88f1083bc428a49ab9b2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberJniTest.java @@ -156,8 +156,12 @@ public class UnsignedNumberJniTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists unsign_jni"); + statement.close(); conn.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java index 842dbfeff8478115df93b48cfe29fe376c4cff05..b3ca6871db7cbf0888737856e66d236c4cc80d49 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UnsignedNumberRestfulTest.java @@ -14,6 +14,7 @@ public class UnsignedNumberRestfulTest { private static final String host = "127.0.0.1"; private static Connection conn; private static long ts; + private static final String dbname = "unsign_restful"; @Test public void testCase001() throws SQLException { @@ -148,9 +149,9 @@ public class UnsignedNumberRestfulTest { final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; conn = DriverManager.getConnection(url, properties); Statement stmt = conn.createStatement(); - stmt.execute("drop database if exists unsign_restful"); - stmt.execute("create database if not exists unsign_restful"); - stmt.execute("use unsign_restful"); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); stmt.execute("create table us_table(ts timestamp, f1 tinyint unsigned, f2 smallint unsigned, f3 int unsigned, f4 bigint unsigned)"); stmt.executeUpdate("insert into us_table(ts,f1,f2,f3,f4) values(" + ts + ", 127, 32767,2147483647, 9223372036854775807)"); stmt.close(); @@ -162,8 +163,12 @@ public class UnsignedNumberRestfulTest { @AfterClass public static void afterClass() { try { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java index 2e0448bc248bb2a962466e632443d4e6d918ab9f..c4f2cba446e6138679ae9f8b8efff3666c056deb 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/UseNowInsertTimestampTest.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc.cases; +import org.junit.AfterClass; import org.junit.Test; import java.sql.*; @@ -8,7 +9,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class UseNowInsertTimestampTest { - String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; + private static String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; @Test public void millisec() throws SQLException { @@ -55,13 +56,14 @@ public class UseNowInsertTimestampTest { @Test public void nanosec() throws SQLException { + long now_time = System.currentTimeMillis() * 1000_000L + System.nanoTime() % 1000_000L; try (Connection conn = DriverManager.getConnection(url)) { Statement stmt = conn.createStatement(); stmt.execute("drop database if exists test"); stmt.execute("create database if not exists test precision 'ns'"); stmt.execute("use test"); stmt.execute("create table weather(ts timestamp, f1 int)"); - stmt.execute("insert into weather values(now, 1)"); + stmt.execute("insert into weather values(" + now_time + ", 1)"); ResultSet rs = stmt.executeQuery("select * from weather"); rs.next(); @@ -74,4 +76,15 @@ public class UseNowInsertTimestampTest { stmt.execute("drop database if exists test"); } } + + @AfterClass + public static void afterClass() { + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); + } catch (SQLException e) { + e.printStackTrace(); + } + + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java index bbf71349b85c7bdc51fde30f293c7cd724de3699..7ad7c23136f8e24b0c7139e97fb4b46c04a98abb 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BadLocaleSettingTest.java @@ -45,7 +45,11 @@ public class BadLocaleSettingTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database " + dbName); + statement.close(); conn.close(); + } } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java index e8c799e86c61c6b4a7cb8b3396c6c3e09548ee0e..94a5382410ba05c1fbf3afb4f8bb73d6c5271c3a 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/BatchFetchTest.java @@ -79,4 +79,15 @@ public class BatchFetchTest { } return builder.toString(); } + + @AfterClass + public static void afterClass(){ + String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); + } catch (SQLException e) { + e.printStackTrace(); + } + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java index e28faeb280a9f9f9ae931e7b610910fb912278b3..41629189aea4658514bd317c90bc055340397a23 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/CharsetTest.java @@ -1,6 +1,7 @@ package com.taosdata.jdbc.confprops; import com.taosdata.jdbc.TSDBDriver; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; @@ -37,4 +38,18 @@ public class CharsetTest { } } + @AfterClass + public static void afterClass(){ + String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"; + Properties props = new Properties(); + props.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + + try (Connection conn = DriverManager.getConnection(url, props); + Statement stmt = conn.createStatement()) { + stmt.execute("drop database if exists test"); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java index 6569aa5f085f5d389144a9e8ddc0787786f9fff3..bc19e63ba6e05c8170366de4375148ebde0138d0 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimeZoneTest.java @@ -29,7 +29,7 @@ public class TimeZoneTest { } @Test - public void taosTimeZone() { + public void taosTimeZone() throws SQLException { // given Properties props = new Properties(); props.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); @@ -39,7 +39,7 @@ public class TimeZoneTest { Statement stmt = connection.createStatement(); stmt.execute("drop database if exists timezone_test"); - stmt.execute("create database if not exists timezone_test keep 365000"); + stmt.execute("create database if not exists timezone_test keep 36500"); stmt.execute("use timezone_test"); stmt.execute("create table weather(ts timestamp, temperature float)"); @@ -51,7 +51,7 @@ public class TimeZoneTest { System.out.println("ts: " + ts.getTime() + "," + ts); } - stmt.execute("insert into timezone_test.weather(ts, temperature, humidity) values('1970-01-02 00:00:00', 1.0, 2.0)"); + stmt.execute("insert into timezone_test.weather(ts, temperature) values('1970-01-02 00:00:00', 1.0)"); rs = stmt.executeQuery("select * from timezone_test.weather"); while (rs.next()) { @@ -63,8 +63,6 @@ public class TimeZoneTest { stmt.execute("drop database if exists timezone_test"); stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java index 7e3701c153fa3f45852dd1a5860cf30910dc906d..a6f8cf7c0ad79d1a046a5075f05f6930ea1d19ce 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/confprops/TimestampFormatTest.java @@ -1,17 +1,17 @@ package com.taosdata.jdbc.confprops; import com.taosdata.jdbc.TSDBDriver; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import java.sql.*; import java.time.Instant; +import java.util.Calendar; import java.util.Properties; public class TimestampFormatTest { private static final String host = "127.0.0.1"; private long ts = Instant.now().toEpochMilli(); + private Connection conn; @Test public void string() throws SQLException { @@ -154,13 +154,27 @@ public class TimestampFormatTest { @Before public void before() throws SQLException { String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"; - try (Connection conn = DriverManager.getConnection(url); - Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists test"); - stmt.execute("create database if not exists test"); - stmt.execute("use test"); - stmt.execute("create table weather(ts timestamp, temperature nchar(10))"); - stmt.execute("insert into weather values(" + ts + ", '北京')"); + conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists test"); + stmt.execute("create database if not exists test"); + stmt.execute("use test"); + stmt.execute("create table weather(ts timestamp, temperature nchar(10))"); + stmt.execute("insert into weather values(" + ts + ", '北京')"); + stmt.close(); + } + + @After + public void after() { + try { + if (null != conn) { + Statement stmt = conn.createStatement(); + stmt.execute("drop database if exists test"); + stmt.close(); + conn.close(); + } + } catch (SQLException e) { + e.printStackTrace(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/DatabaseSpecifiedTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/DatabaseSpecifiedTest.java index 9fe51e7203fac7133783e47fd5b0cc07f33b2494..0a37e255a4ac8e8db2b07fc915ab7ba6dd54397c 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/DatabaseSpecifiedTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/DatabaseSpecifiedTest.java @@ -33,7 +33,6 @@ public class DatabaseSpecifiedTest { String loc = rs.getString("loc"); assertEquals("beijing", loc); } - connection.close(); } @Before @@ -59,8 +58,12 @@ public class DatabaseSpecifiedTest { @After public void after() { try { - if (connection != null) + if (connection != null) { + Statement statement = connection.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); connection.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java index e7ce1d76f123a043d49eb64931c0d537d09664df..e4785a197e659977ae22745e14e664fd803464f7 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulConnectionTest.java @@ -383,8 +383,12 @@ public class RestfulConnectionTest { @AfterClass public static void afterClass() throws SQLException { - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test"); + statement.close(); conn.close(); + } } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java index 81d7f5b56c4b4e67b9573522ee031006a7e11a2b..c8ca1a5de7ac870c01d248a8b042cffefa4857b7 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulParameterMetaDataTest.java @@ -18,6 +18,7 @@ public class RestfulParameterMetaDataTest { private static PreparedStatement pstmt_select; private static ParameterMetaData parameterMetaData_insert; private static ParameterMetaData parameterMetaData_select; + private static final String dbname = "test_pstmt"; @Test public void getParameterCount() throws SQLException { @@ -148,9 +149,9 @@ public class RestfulParameterMetaDataTest { Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata"); try (Statement stmt = conn.createStatement()) { - stmt.execute("drop database if exists test_pstmt"); - stmt.execute("create database if not exists test_pstmt"); - stmt.execute("use test_pstmt"); + stmt.execute("drop database if exists " + dbname); + stmt.execute("create database if not exists " + dbname); + stmt.execute("use " + dbname); stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64)) tags(loc nchar(64))"); stmt.execute("create table t1 using weather tags('beijing')"); } @@ -186,8 +187,12 @@ public class RestfulParameterMetaDataTest { pstmt_insert.close(); if (pstmt_select != null) pstmt_select.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java index 4760a723e4b4e662326987290c2c630803f8f470..40d0e0214fe1016df8d42e9dfd8d31472165c798 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulPreparedStatementTest.java @@ -400,8 +400,12 @@ public class RestfulPreparedStatementTest { pstmt_select.close(); if (pstmt_without_parameters != null) pstmt_without_parameters.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists test_pstmt"); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java index f3011af799c987ed399920875ae512fd8533ec77..6e5851474f2697022eef5dc62be3f69ca5878df9 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/rs/RestfulResultSetMetaDataTest.java @@ -15,6 +15,7 @@ public class RestfulResultSetMetaDataTest { private static Statement stmt; private static ResultSet rs; private static ResultSetMetaData meta; + private static final String dbname = "restful_test"; @Test public void getColumnCount() throws SQLException { @@ -206,8 +207,12 @@ public class RestfulResultSetMetaDataTest { rs.close(); if (stmt != null) stmt.close(); - if (conn != null) + if (conn != null) { + Statement statement = conn.createStatement(); + statement.execute("drop database if exists " + dbname); + statement.close(); conn.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 13afd1c29894fea07e5c269eee53b36a386ee442..76818ac51c3a7879689f68d9af075601310fdc52 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -1003,6 +1003,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { newCfg.daysToKeep0 = daysToKeep0; } +#ifdef _STORAGE if (daysToKeep1 > 0 && (daysToKeep1 != pDb->cfg.daysToKeep1 || newCfg.daysToKeep1 != pDb->cfg.daysToKeep1)) { mDebug("db:%s, daysToKeep1:%d change to %d", pDb->name, pDb->cfg.daysToKeep1, daysToKeep1); newCfg.daysToKeep1 = daysToKeep1; @@ -1012,6 +1013,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { mDebug("db:%s, daysToKeep2:%d change to %d", pDb->name, pDb->cfg.daysToKeep2, daysToKeep2); newCfg.daysToKeep2 = daysToKeep2; } +#endif if (minRows > 0 && minRows != pDb->cfg.minRowsPerFileBlock) { mError("db:%s, can't alter minRows option", pDb->name); @@ -1100,6 +1102,7 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SAlterDbMsg *pAlter) { // community version can only change daysToKeep // but enterprise version can change all daysToKeep options + #ifndef _STORAGE newCfg.daysToKeep1 = newCfg.daysToKeep0; newCfg.daysToKeep2 = newCfg.daysToKeep0; diff --git a/src/util/src/tnettest.c b/src/util/src/tnettest.c index 8dc2d4c993e001c95f63d72c60db8b8fe3ac3df8..7d1076abbf1eb0c35385b769bfc6a88cfd8a21a7 100644 --- a/src/util/src/tnettest.c +++ b/src/util/src/tnettest.c @@ -356,7 +356,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p epSet.inUse = 0; epSet.numOfEps = 1; epSet.port[0] = port; - strcpy(epSet.fqdn[0], serverFqdn); + tstrncpy(epSet.fqdn[0], serverFqdn, sizeof(epSet.fqdn[0])); reqMsg.msgType = TSDB_MSG_TYPE_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pktLen); @@ -364,7 +364,7 @@ static int32_t taosNetCheckRpc(const char* serverFqdn, uint16_t port, uint16_t p reqMsg.code = 0; reqMsg.handle = NULL; // rpc handle returned to app reqMsg.ahandle = NULL; // app handle set by client - strcpy(reqMsg.pCont, "nettest"); + tstrncpy((char*)reqMsg.pCont, "nettest", pktLen); rpcSendRecv(pRpcConn, &epSet, &reqMsg, &rspMsg); @@ -606,7 +606,7 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, epSet.inUse = 0; epSet.numOfEps = 1; epSet.port[0] = port; - strcpy(epSet.fqdn[0], host); + tstrncpy(epSet.fqdn[0], host, sizeof(epSet.fqdn[0])); reqMsg.msgType = TSDB_MSG_TYPE_NETWORK_TEST; reqMsg.pCont = rpcMallocCont(pkgLen); @@ -614,8 +614,8 @@ static void taosNetCheckSpeed(char *host, int32_t port, int32_t pkgLen, reqMsg.code = 0; reqMsg.handle = NULL; // rpc handle returned to app reqMsg.ahandle = NULL; // app handle set by client - strcpy(reqMsg.pCont, "nettest speed"); - + tstrncpy((char*)reqMsg.pCont, "nettest speed", pkgLen); + rpcSendRecv(pRpcConn, &epSet, &reqMsg, &rspMsg); int code = 0; diff --git a/tests/pytest/tools/taosdemoTestTblAlt.py b/tests/pytest/tools/taosdemoTestTblAlt.py index 7587ab9eb3e89275451864d28ccf985bcaac949a..444aab519bf7089b792125ffa3caa6de5ad4eb8d 100644 --- a/tests/pytest/tools/taosdemoTestTblAlt.py +++ b/tests/pytest/tools/taosdemoTestTblAlt.py @@ -30,6 +30,7 @@ class TDTestCase: self.numberOfRecords = 1000000 def getBuildPath(self): + buildPath="" selfPath = os.path.dirname(os.path.realpath(__file__)) if ("community" in selfPath): @@ -38,7 +39,7 @@ class TDTestCase: projPath = selfPath[:selfPath.find("tests")] for root, dirs, files in os.walk(projPath): - if ("taosd" in files): + if ("taosd" in files and "taosBenchmark" in files): rootRealPath = os.path.dirname(os.path.realpath(root)) if ("packaging" not in rootRealPath): buildPath = root[:len(root) - len("/build/bin")] @@ -48,7 +49,7 @@ class TDTestCase: def insertDataAndAlterTable(self, threadID): buildPath = self.getBuildPath() if (buildPath == ""): - tdLog.exit("taosd not found!") + tdLog.exit("taosd or staosBenchmark not found!") else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath + "/build/bin/"