From bd22f9418feded9abf654d508a2ad334f04f0802 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Sat, 6 Jun 2020 14:03:16 +0800 Subject: [PATCH 01/29] refactor: remove TSDBError --- .../java/com/taosdata/jdbc/TSDBError.java | 223 ------------------ .../java/com/taosdata/jdbc/TSDBStatement.java | 1 + .../src/test/java/TestPreparedStatement.java | 3 + 3 files changed, 4 insertions(+), 223 deletions(-) delete mode 100644 src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java deleted file mode 100644 index bb1b2afd07..0000000000 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java +++ /dev/null @@ -1,223 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - *****************************************************************************/ -package com.taosdata.jdbc; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * TDengine error code and error message enumeration. - * - */ -public enum TSDBError { - - TSDB_CODE_SUCCESS(0, "success"), - TSDB_CODE_ACTION_IN_PROGRESS(1, "in progress"), - TSDB_CODE_LAST_SESSION_NOT_FINISHED(5, "last session not finished"), - TSDB_CODE_INVALID_SESSION_ID(6, "invalid session ID"), - TSDB_CODE_INVALID_TRAN_ID(7, "invalid tran ID"), - TSDB_CODE_INVALID_MSG_TYPE(8, "invalid msg type"), - TSDB_CODE_ALREADY_PROCESSED(9, "alredy processed"), - TSDB_CODE_AUTH_FAILURE(10, "authentication failure"), - TSDB_CODE_WRONG_MSG_SIZE(11, "wrong msg size"), - TSDB_CODE_UNEXPECTED_RESPONSE(12, "unexpected response"), - TSDB_CODE_INVALID_RESPONSE_TYPE(13, "invalid response type"), - TSDB_CODE_NO_RESOURCE(14, "no resource"), - TSDB_CODE_INVALID_TIME_STAMP(15, "invalid time stamp"), - TSDB_CODE_MISMATCHED_METER_ID(16, "mismatched meter ID"), - TSDB_CODE_ACTION_TRANS_NOT_FINISHED(17, "transcation not finished"), - TSDB_CODE_ACTION_NOT_ONLINE(18, "not online"), - TSDB_CODE_ACTION_SEND_FAILD(19, "send failed"), - TSDB_CODE_NOT_ACTIVE_SESSION(20, "not active session"), - TSDB_CODE_INSERT_FAILED(21, "insert failed"), - TSDB_CODE_APP_ERROR(22, "App error"), - TSDB_CODE_INVALID_IE(23, "invalid IE"), - TSDB_CODE_INVALID_VALUE(24, "invalid value"), - TSDB_CODE_REDIRECT(25, "service not available"), - TSDB_CODE_ALREADY_THERE(26, "already there"), - TSDB_CODE_INVALID_TABLE_ID(27, "invalid meter ID"), - TSDB_CODE_INVALID_SQL(28, "invalid SQL"), // this message often comes with additional info which will vary based on the specific error situation - TSDB_CODE_NETWORK_UNAVAIL(29, "failed to connect to server"), - TSDB_CODE_INVALID_MSG_LEN(30, "invalid msg len"), - TSDB_CODE_INVALID_DB(31, "invalid DB"), - TSDB_CODE_INVALID_TABLE(32, "invalid table"), - TSDB_CODE_DB_ALREADY_EXIST(33, "DB already there"), - TSDB_CODE_TABLE_ALREADY_EXIST(34, "table already there"), - TSDB_CODE_INVALID_USER(35, "invalid user name"), - TSDB_CODE_INVALID_ACCT(36, "invalid acct name"), - TSDB_CODE_INVALID_PASS(37, "invalid password"), - TSDB_CODE_DB_NOT_SELECTED(38, "DB not selected"), - TSDB_CODE_MEMORY_CORRUPTED(39, "memory corrupted"), - TSDB_CODE_USER_ALREADY_EXIST(40, "user name exists"), - TSDB_CODE_NO_RIGHTS(41, "not authorized"), - TSDB_CODE_DISCONNECTED(42, "login disconnected), login again"), - TSDB_CODE_NO_MASTER(43, "mgmt master node not available"), - TSDB_CODE_NOT_CONFIGURED(44, "not configured"), - TSDB_CODE_INVALID_OPTION(45, "invalid option"), - TSDB_CODE_NODE_OFFLINE(46, "node offline"), - TSDB_CODE_SYNC_REQUIRED(47, "sync required"), - TSDB_CODE_NO_ENOUGH_DNODES(48, "more dnodes are needed"), - TSDB_CODE_UNSYNCED(49, "node in unsynced state"), - TSDB_CODE_TOO_SLOW(50, "too slow"), - TSDB_CODE_OTHERS(51, "others"), - TSDB_CODE_NO_REMOVE_MASTER(52, "can't remove dnode which is master"), - TSDB_CODE_WRONG_SCHEMA(53, "wrong schema"), - TSDB_CODE_NO_RESULT(54, "no results"), - TSDB_CODE_TOO_MANY_USERS(55, "num of users execeed maxUsers"), - TSDB_CODE_TOO_MANY_DATABSES(56, "num of databases execeed maxDbs"), - TSDB_CODE_TOO_MANY_TABLES(57, "num of tables execeed maxTables"), - TSDB_CODE_TOO_MANY_DNODES(58, "num of dnodes execeed maxDnodes"), - TSDB_CODE_TOO_MANY_ACCTS(59, "num of accounts execeed maxAccts"), - TSDB_CODE_ACCT_ALREADY_EXIST(60, "accout name exists"), - TSDB_CODE_DNODE_ALREADY_EXIST(61, "dnode ip exists"), - TSDB_CODE_SDB_ERROR(62, "sdb error"), - TSDB_CODE_METRICMETA_EXPIRED(63, "metric meta expired"), // local cached metric-meta expired causes error in metric query - TSDB_CODE_NOT_READY(64, "not ready"), // peer is not ready to process data - TSDB_CODE_MAX_SESSIONS(65, "too many sessions on server"), // too many sessions - TSDB_CODE_MAX_CONNECTIONS(66, "too many sessions from app"), // too many connections - TSDB_CODE_SESSION_ALREADY_EXIST(67, "session to dest is already there"), - TSDB_CODE_NO_QSUMMARY(68, "query list not there), please show again"), - TSDB_CODE_SERV_OUT_OF_MEMORY(69, "server out of memory"), - TSDB_CODE_INVALID_QHANDLE(70, "invalid query handle"), - TSDB_CODE_RELATED_TABLES_EXIST(71, "tables related to metric exist"), - TSDB_CODE_MONITOR_DB_FORBEIDDEN(72, "can't drop monitor database or tables"), - TSDB_CODE_VG_COMMITLOG_INIT_FAILED(73, "commit log init failed"), - TSDB_CODE_VG_INIT_FAILED(74, "vgroup init failed"), - TSDB_CODE_DATA_ALREADY_IMPORTED(75, "data is already imported"), - TSDB_CODE_OPS_NOT_SUPPORT(76, "not supported operation"), - TSDB_CODE_INVALID_QUERY_ID(77, "invalid query id string"), - TSDB_CODE_INVALID_STREAM_ID(78, "invalid stream id string"), - TSDB_CODE_INVALID_CONNECTION(79, "invalid connection string"), - TSDB_CODE_ACTION_NOT_BALANCED(80, "dnode not balanced"), - TSDB_CODE_CLI_OUT_OF_MEMORY(81, "client out of memory"), - TSDB_CODE_DATA_OVERFLOW(82, "data value overflow"), - TSDB_CODE_QUERY_CANCELLED(83, "query cancelled"), - TSDB_CODE_GRANT_POINT_LIMITED(84, "grant points limited"), - TSDB_CODE_GRANT_EXPIRED(85, "grant expired"), - TSDB_CODE_CLI_NO_DISKSPACE(86, "client no disk space"), - TSDB_CODE_FILE_CORRUPTED(87, "DB file corrupted"), - TSDB_CODE_INVALID_CLIENT_VERSION(88, "version of client and server not match"); - - private long errCode; - private String errMessage; - private static Map errorCodeMap = new HashMap<>(86); - static { - errorCodeMap.put(0, "success"); - errorCodeMap.put(1, "in progress"); - errorCodeMap.put(5, "last session not finished"); - errorCodeMap.put(6, "invalid session ID"); - errorCodeMap.put(7, "invalid tran ID"); - errorCodeMap.put(8, "invalid msg type"); - errorCodeMap.put(9, "alredy processed"); - errorCodeMap.put(10, "authentication failure"); - errorCodeMap.put(11, "wrong msg size"); - errorCodeMap.put(12, "unexpected response"); - errorCodeMap.put(13, "invalid response type"); - errorCodeMap.put(14, "no resource"); - errorCodeMap.put(15, "invalid time stamp"); - errorCodeMap.put(16, "mismatched meter ID"); - errorCodeMap.put(17, "transcation not finished"); - errorCodeMap.put(18, "not online"); - errorCodeMap.put(19, "send failed"); - errorCodeMap.put(20, "not active session"); - errorCodeMap.put(21, "insert failed"); - errorCodeMap.put(22, "App error"); - errorCodeMap.put(23, "invalid IE"); - errorCodeMap.put(24, "invalid value"); - errorCodeMap.put(25, "service not available"); - errorCodeMap.put(26, "already there"); - errorCodeMap.put(27, "invalid meter ID"); - errorCodeMap.put(28, "invalid SQL"); // this message often comes with additional info which will vary based on the specific error situation - errorCodeMap.put(29, "failed to connect to server"); - errorCodeMap.put(30, "invalid msg len"); - errorCodeMap.put(31, "invalid DB"); - errorCodeMap.put(32, "invalid table"); - errorCodeMap.put(33, "DB already there"); - errorCodeMap.put(34, "table already there"); - errorCodeMap.put(35, "invalid user name"); - errorCodeMap.put(36, "invalid acct name"); - errorCodeMap.put(37, "invalid password"); - errorCodeMap.put(38, "DB not selected"); - errorCodeMap.put(39, "memory corrupted"); - errorCodeMap.put(40, "user name exists"); - errorCodeMap.put(41, "not authorized"); - errorCodeMap.put(42, "login disconnected); login again"); - errorCodeMap.put(43, "mgmt master node not available"); - errorCodeMap.put(44, "not configured"); - errorCodeMap.put(45, "invalid option"); - errorCodeMap.put(46, "node offline"); - errorCodeMap.put(47, "sync required"); - errorCodeMap.put(48, "more dnodes are needed"); - errorCodeMap.put(49, "node in unsynced state"); - errorCodeMap.put(50, "too slow"); - errorCodeMap.put(51, "others"); - errorCodeMap.put(52, "can't remove dnode which is master"); - errorCodeMap.put(53, "wrong schema"); - errorCodeMap.put(54, "no results"); - errorCodeMap.put(55, "num of users execeed maxUsers"); - errorCodeMap.put(56, "num of databases execeed maxDbs"); - errorCodeMap.put(57, "num of tables execeed maxTables"); - errorCodeMap.put(58, "num of dnodes execeed maxDnodes"); - errorCodeMap.put(59, "num of accounts execeed maxAccts"); - errorCodeMap.put(60, "accout name exists"); - errorCodeMap.put(61, "dnode ip exists"); - errorCodeMap.put(62, "sdb error"); - errorCodeMap.put(63, "metric meta expired"); // local cached metric-meta expired causes error in metric query - errorCodeMap.put(64, "not ready"); // peer is not ready to process data - errorCodeMap.put(65, "too many sessions on server"); // too many sessions - errorCodeMap.put(66, "too many sessions from app"); // too many connections - errorCodeMap.put(67, "session to dest is already there"); - errorCodeMap.put(68, "query list not there); please show again"); - errorCodeMap.put(69, "server out of memory"); - errorCodeMap.put(70, "invalid query handle"); - errorCodeMap.put(71, "tables related to metric exist"); - errorCodeMap.put(72, "can't drop monitor database or tables"); - errorCodeMap.put(73, "commit log init failed"); - errorCodeMap.put(74, "vgroup init failed"); - errorCodeMap.put(75, "data is already imported"); - errorCodeMap.put(76, "not supported operation"); - errorCodeMap.put(77, "invalid query id string"); - errorCodeMap.put(78, "invalid stream id string"); - errorCodeMap.put(79, "invalid connection string"); - errorCodeMap.put(80, "dnode not balanced"); - errorCodeMap.put(81, "client out of memory"); - errorCodeMap.put(82, "data value overflow"); - errorCodeMap.put(83, "query cancelled"); - errorCodeMap.put(84, "grant points limited"); - errorCodeMap.put(85, "grant expired"); - errorCodeMap.put(86, "client no disk space"); - errorCodeMap.put(87, "DB file corrupted"); - errorCodeMap.put(88, "version of client and server not match"); - } - - TSDBError(long code, String message) { - this.errCode = code; - this.errMessage = message; - } - - public long getErrCode() { - return this.errCode; - } - - public String getErrMessage() { - return this.errMessage; - } - - public static String getErrMessageByCode(long errCode) { - return errorCodeMap.get(errCode); - } - -} diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index dbe1e41e6b..c3756aff34 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -79,6 +79,7 @@ public class TSDBStatement implements Statement { throw new SQLException("The executed SQL is not a DML or a DDL"); } else { int num = this.connecter.getAffectedRows(res); + this.connecter.freeResultSet(res); return num; } } diff --git a/src/connector/jdbc/src/test/java/TestPreparedStatement.java b/src/connector/jdbc/src/test/java/TestPreparedStatement.java index 3b84645b5b..9d7f1cf760 100644 --- a/src/connector/jdbc/src/test/java/TestPreparedStatement.java +++ b/src/connector/jdbc/src/test/java/TestPreparedStatement.java @@ -21,9 +21,12 @@ public class TestPreparedStatement { System.out.printf("%d: %s\n", i, resSet.getString(i)); } } + resSet.close(); + connection.close(); } catch (Exception e) { e.printStackTrace(); + } } } From 75686a8ef027b05d8b07f38030df3fd17e19a5a2 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Tue, 9 Jun 2020 12:03:59 +0800 Subject: [PATCH 02/29] fix: affectRows --- src/client/src/TSDBJNIConnector.c | 2 +- src/connector/jdbc/pom.xml | 14 +++ .../com/taosdata/jdbc/TSDBJNIConnector.java | 13 +-- .../taosdata/jdbc/TSDBAsyncSubscribeTest.java | 96 +++++++++++++++++++ .../com/taosdata/jdbc/TSDBImportTest.java | 77 +++++++++++++++ .../com/taosdata/jdbc/TSDBSubscribeTest.java | 90 +++++++++++++++++ 6 files changed, 282 insertions(+), 10 deletions(-) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index cec4737226..de39e62420 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -344,7 +344,7 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getResultSetImp( STscObj *pObj = pSql->pTscObj; if (tscIsUpdateQuery(pSql)) { - taos_free_result(pSql); // free result here + // taos_free_result(pSql); // free result here jniTrace("jobj:%p, conn:%p, no resultset, %p", jobj, pObj, (void *)tres); return 0; } else { diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 36f1a1010c..0f441d097e 100755 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -62,6 +62,12 @@ commons-lang3 ${commons-lang3.version} + + junit + junit + 4.8.2 + test + @@ -98,6 +104,14 @@ true + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + true + + diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index 8bb7084604..46158210b1 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -51,8 +51,6 @@ public class TSDBJNIConnector { /** * Returns the status of last result set in current connection - * - * @return */ public boolean isResultsetClosed() { return this.isResultsetClosed; @@ -112,7 +110,7 @@ public class TSDBJNIConnector { * * @throws SQLException */ - public int executeQuery(String sql) throws SQLException { + public long executeQuery(String sql) throws SQLException { if (!this.isResultsetClosed) { freeResultSet(taosResultSetPointer); } @@ -127,7 +125,6 @@ public class TSDBJNIConnector { } int code = this.getErrCode(pSql); - affectedRows = code; if (code < 0) { affectedRows = -1; if (code == TSDBConstants.JNI_TDENGINE_ERROR) { @@ -146,7 +143,7 @@ public class TSDBJNIConnector { if (taosResultSetPointer != TSDBConstants.JNI_NULL_POINTER) { isResultsetClosed = false; } - return code; + return pSql; } private native long executeQueryImp(byte[] sqlBytes, long connection); @@ -199,8 +196,6 @@ public class TSDBJNIConnector { /** * Close the open result set which is associated to the current connection. If the result set is already * closed, return 0 for success. - * - * @return */ public int freeResultSet() { int resCode = TSDBConstants.JNI_SUCCESS; @@ -217,7 +212,7 @@ public class TSDBJNIConnector { /** * Get affected rows count */ - public int getAffectedRows(Long pSql) { + public int getAffectedRows(long pSql) { int affectedRows = this.affectedRows; if (affectedRows < 0) { affectedRows = this.getAffectedRowsImp(this.taos, pSql); @@ -225,7 +220,7 @@ public class TSDBJNIConnector { return affectedRows; } - private native int getAffectedRowsImp(long connection, Long pSql); + private native int getAffectedRowsImp(long connection, long pSql); /** * Get schema metadata diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java new file mode 100644 index 0000000000..530b47d277 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java @@ -0,0 +1,96 @@ +package com.taosdata.jdbc; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import static org.junit.Assert.assertTrue; + +public class TSDBAsyncSubscribeTest { + Connection connection = null; + Statement statement = null; + String dbName = "test"; + String tName = "t0"; + String host = "localhost"; + String topic = "test"; + long subscribId = 0; + +// @Before + public void createDatabase() 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("create database if not exists " + dbName); + statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); + long ts = System.currentTimeMillis(); + for (int i = 0; i < 5; i++) { + ts += i; + statement.executeUpdate("insert into \" + dbName + \".\" + tName + \" values (" + ts + ", " + (100 + i) + ", " + i + ")"); + } + } + +// @Test + public void subscribe() throws Exception { + TSDBSubscribe subscribe = null; + try { + String rawSql = "select * from " + dbName + "." + tName + ";"; + System.out.println(rawSql); + subscribe = ((TSDBConnection) connection).createSubscribe(); + subscribId = subscribe.subscribe(topic, rawSql, false, 1000, new CallBack("first")); + + assertTrue(subscribId > 0); + } catch (Exception e) { + e.printStackTrace(); + } + + Thread.sleep(2000); + subscribe.unsubscribe(subscribId, true); + } + + private static class CallBack implements TSDBSubscribeCallBack { + private String name = ""; + + public CallBack(String name) { + this.name = name; + } + + @Override + public void invoke(TSDBResultSet resultSet) { + System.out.println("resultSet"); + try { + while (null != resultSet && resultSet.next()) { + System.out.print("callback_" + name + ": "); + for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) { + System.out.printf(i + ": " + resultSet.getString(i) + "\t"); + } + System.out.println(); + } + resultSet.close(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + } + +// @After + public void close() throws Exception { + statement.executeQuery("drop database test"); + statement.close(); + connection.close(); + } +} \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java new file mode 100644 index 0000000000..1fd15b2dfd --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java @@ -0,0 +1,77 @@ +package com.taosdata.jdbc; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class TSDBImportTest { + Connection connection = null; + Statement statement = null; + String dbName = "test"; + String tName = "t0"; + String host = "localhost"; + + @Before + public void createDatabase() 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 insertInto() throws Exception { + long ts = System.currentTimeMillis(); + + for (int i = 0; i < 50; i++) { + ts += i; + 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); + } + } + + @Test + public void importInto() throws Exception { + // 避免时间重复 + long ts = System.currentTimeMillis() + 1000; + + StringBuilder sqlBuilder = new StringBuilder("insert into ").append(dbName).append(".").append(tName).append(" values "); + + for (int i = 0; i < 50; i++) { + int a = i / 5; + long t = ts + a; + sqlBuilder.append("(").append(t).append(",").append((100 + i)).append(",").append(i).append(") "); + } + System.out.println(sqlBuilder.toString()); + int rows = statement.executeUpdate(sqlBuilder.toString()); + System.out.println(rows); + assertEquals(10, rows); + } + + @After + public void close() throws Exception { + statement.executeQuery("drop database " + dbName); + statement.close(); + connection.close(); + } +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java new file mode 100644 index 0000000000..b7c6313587 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java @@ -0,0 +1,90 @@ +package com.taosdata.jdbc; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import static org.junit.Assert.assertTrue; + +public class TSDBSubscribeTest { + Connection connection = null; + Statement statement = null; + String dbName = "test"; + String tName = "t0"; + String host = "localhost"; + String topic = "test"; + +// @Before + public void createDatabase() 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("create database if not exists " + dbName); + statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); + long ts = System.currentTimeMillis(); + for (int i = 0; i < 5; i++) { + ts += i; + statement.executeUpdate("insert into \" + dbName + \".\" + tName + \" values (" + ts + ", " + (100 + i) + ", " + i + ")"); + } + } + +// @Test + public void subscribe() throws Exception { + TSDBSubscribe subscribe = null; + long subscribId = 0; + try { + + String rawSql = "select * from " + dbName + "." + tName + ";"; + System.out.println(rawSql); + subscribe = ((TSDBConnection) connection).createSubscribe(); + subscribId = subscribe.subscribe(topic, rawSql, false, 1000); + + assertTrue(subscribId > 0); + + int a = 0; + while (true) { + Thread.sleep(900); + TSDBResultSet resSet = subscribe.consume(subscribId); + + while (resSet.next()) { + for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) { + System.out.printf(i + ": " + resSet.getString(i) + "\t"); + } + System.out.println("\n======" + a + "=========="); + } + resSet.close(); + a++; + if (a >= 3) { + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (null != subscribe && 0 != subscribId) { + subscribe.unsubscribe(subscribId, true); + } + } + } + +// @After + public void close() throws Exception { + statement.executeQuery("drop database " + dbName); + statement.close(); + connection.close(); + } +} \ No newline at end of file From 2bb969a9fb0b96c2f26967068e705053e106b273 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Tue, 9 Jun 2020 18:08:31 +0800 Subject: [PATCH 03/29] tests:add import --- .../java/com/taosdata/jdbc/TSDBStatement.java | 6 +++- .../taosdata/jdbc/TSDBAsyncSubscribeTest.java | 7 ++--- .../com/taosdata/jdbc/TSDBImportTest.java | 30 ++++++++++++------- .../com/taosdata/jdbc/TSDBSubscribeTest.java | 6 ++-- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index c3756aff34..c856c03a83 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -51,13 +51,17 @@ public class TSDBStatement implements Statement { if (isClosed) { throw new SQLException("Invalid method call on a closed statement."); } - this.connecter.executeQuery(sql); + System.out.println(sql); + long res = this.connecter.executeQuery(sql); long resultSetPointer = this.connecter.getResultSet(); if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { + this.connecter.freeResultSet(res); throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); } else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) { +// create/insert/update/del/alter + this.connecter.freeResultSet(res); return null; } else { return new TSDBResultSet(this.connecter, resultSetPointer); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java index 530b47d277..245ababae1 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java @@ -21,7 +21,7 @@ public class TSDBAsyncSubscribeTest { String topic = "test"; long subscribId = 0; -// @Before + @Before public void createDatabase() throws SQLException { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); @@ -43,7 +43,7 @@ public class TSDBAsyncSubscribeTest { } } -// @Test + @Test public void subscribe() throws Exception { TSDBSubscribe subscribe = null; try { @@ -70,7 +70,6 @@ public class TSDBAsyncSubscribeTest { @Override public void invoke(TSDBResultSet resultSet) { - System.out.println("resultSet"); try { while (null != resultSet && resultSet.next()) { System.out.print("callback_" + name + ": "); @@ -87,7 +86,7 @@ public class TSDBAsyncSubscribeTest { } } -// @After + @After public void close() throws Exception { statement.executeQuery("drop database test"); statement.close(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java index 1fd15b2dfd..8b3c9f3141 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java @@ -4,10 +4,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; import java.util.Properties; import static org.junit.Assert.assertEquals; @@ -40,20 +37,33 @@ public class TSDBImportTest { @Test public void insertInto() throws Exception { - long ts = System.currentTimeMillis(); + long ts = 1496732686000l; for (int i = 0; i < 50; i++) { - ts += 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); + System.out.println("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")\t" + row); assertEquals(1, row); } } + @Test + public void selectData() throws Exception { + String sql = "select * from test.t0"; + ResultSet resSet = statement.executeQuery(sql); + + while (resSet.next()) { + for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) { + System.out.printf(i + ": " + resSet.getString(i) + "\t"); + } + } + resSet.close(); + } + @Test public void importInto() throws Exception { // 避免时间重复 - long ts = System.currentTimeMillis() + 1000; + long ts = 1496732686000l; StringBuilder sqlBuilder = new StringBuilder("insert into ").append(dbName).append(".").append(tName).append(" values "); @@ -68,9 +78,9 @@ public class TSDBImportTest { assertEquals(10, rows); } - @After +// @After public void close() throws Exception { - statement.executeQuery("drop database " + dbName); + statement.executeUpdate("drop database " + dbName); statement.close(); connection.close(); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java index b7c6313587..11698ea299 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java @@ -20,7 +20,7 @@ public class TSDBSubscribeTest { String host = "localhost"; String topic = "test"; -// @Before + @Before public void createDatabase() throws SQLException { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); @@ -42,7 +42,7 @@ public class TSDBSubscribeTest { } } -// @Test + @Test public void subscribe() throws Exception { TSDBSubscribe subscribe = null; long subscribId = 0; @@ -81,7 +81,7 @@ public class TSDBSubscribeTest { } } -// @After + @After public void close() throws Exception { statement.executeQuery("drop database " + dbName); statement.close(); From f732250271b28aaf785f7a54b184031e44e1ef18 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Tue, 9 Jun 2020 22:41:13 +0800 Subject: [PATCH 04/29] tests: add test --- src/connector/jdbc/pom.xml | 251 ++++++++++-------- .../src/test/java/TestPreparedStatement.java | 1 + ...cribeTest.java => AsyncSubscribeTest.java} | 2 +- .../{TSDBImportTest.java => ImportTest.java} | 9 +- .../java/com/taosdata/jdbc/SelectTest.java | 65 +++++ .../java/com/taosdata/jdbc/StableTest.java | 4 + ...BSubscribeTest.java => SubscribeTest.java} | 2 +- 7 files changed, 211 insertions(+), 123 deletions(-) rename src/connector/jdbc/src/test/java/com/taosdata/jdbc/{TSDBAsyncSubscribeTest.java => AsyncSubscribeTest.java} (98%) rename src/connector/jdbc/src/test/java/com/taosdata/jdbc/{TSDBImportTest.java => ImportTest.java} (94%) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java rename src/connector/jdbc/src/test/java/com/taosdata/jdbc/{TSDBSubscribeTest.java => SubscribeTest.java} (98%) diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 0f441d097e..456c9e6423 100755 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -1,119 +1,136 @@ - 4.0.0 - - com.taosdata.jdbc - taos-jdbcdriver - 1.0.3 - jar - - JDBCDriver - https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc - TDengine JDBC Driver - - - - GNU AFFERO GENERAL PUBLIC LICENSE Version 3 - https://github.com/taosdata/TDengine/blob/master/LICENSE - repo - - - - - scm:git:git://github.com/taosdata/TDengine.git - scm:git:git@github.com:taosdata/TDengine.git - https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc - HEAD - - - - - taosdata - support@taosdata.com - https://www.taosdata.com/ - https://www.taosdata.com/ - - - - - UTF-8 - 1.8 - - 3.6.0 - - 1.1.2 - 3.5 - - - - - commons-logging - commons-logging - ${commons-logging.version} - - - * - * - - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - junit - junit - 4.8.2 - test - - - - - - - org.apache.maven.plugins - maven-assembly-plugin - 3.0.0 - - - - src/main/assembly/assembly-jar.xml - - - - - make-assembly - package - - single - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - UTF-8 - ${java.version} - ${java.version} - true - true - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.12.4 - - true - - - - - - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + com.taosdata.jdbc + taos-jdbcdriver + 1.0.3 + jar + JDBCDriver + https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc + TDengine JDBC Driver + + + GNU AFFERO GENERAL PUBLIC LICENSE Version 3 + https://github.com/taosdata/TDengine/blob/master/LICENSE + repo + + + + scm:git:git://github.com/taosdata/TDengine.git + scm:git:git@github.com:taosdata/TDengine.git + https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc + HEAD + + + + taosdata + support@taosdata.com + https://www.taosdata.com/ + https://www.taosdata.com/ + + + + UTF-8 + 1.8 + 3.6.0 + 1.1.2 + 3.5 + + + + commons-logging + commons-logging + ${commons-logging.version} + + + * + * + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + junit + junit + 4.8.2 + test + + + org.jacoco + jacoco-maven-plugin + 0.8.3 + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.0.0 + + + src/main/assembly/assembly-jar.xml + + + + + make-assembly + package + + single + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + UTF-8 + ${java.version} + ${java.version} + true + true + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + true + + + + org.jacoco + jacoco-maven-plugin + 0.8.3 + + + com/**/* + + + + + pre-test + + prepare-agent + + + + post-test + test + + report + + + + + + diff --git a/src/connector/jdbc/src/test/java/TestPreparedStatement.java b/src/connector/jdbc/src/test/java/TestPreparedStatement.java index 9d7f1cf760..aabc34549b 100644 --- a/src/connector/jdbc/src/test/java/TestPreparedStatement.java +++ b/src/connector/jdbc/src/test/java/TestPreparedStatement.java @@ -22,6 +22,7 @@ public class TestPreparedStatement { } } resSet.close(); + pstmt.close(); connection.close(); } catch (Exception e) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java similarity index 98% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java index 245ababae1..a7b6848f1e 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBAsyncSubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java @@ -12,7 +12,7 @@ import java.util.Properties; import static org.junit.Assert.assertTrue; -public class TSDBAsyncSubscribeTest { +public class AsyncSubscribeTest { Connection connection = null; Statement statement = null; String dbName = "test"; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ImportTest.java similarity index 94% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/ImportTest.java index 8b3c9f3141..063046bc74 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBImportTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ImportTest.java @@ -9,7 +9,7 @@ import java.util.Properties; import static org.junit.Assert.assertEquals; -public class TSDBImportTest { +public class ImportTest { Connection connection = null; Statement statement = null; String dbName = "test"; @@ -36,7 +36,7 @@ public class TSDBImportTest { } @Test - public void insertInto() throws Exception { + public void insertData() throws Exception { long ts = 1496732686000l; for (int i = 0; i < 50; i++) { @@ -49,6 +49,7 @@ public class TSDBImportTest { @Test public void selectData() throws Exception { + insertData(); String sql = "select * from test.t0"; ResultSet resSet = statement.executeQuery(sql); @@ -61,7 +62,7 @@ public class TSDBImportTest { } @Test - public void importInto() throws Exception { + public void importData() throws Exception { // 避免时间重复 long ts = 1496732686000l; @@ -78,7 +79,7 @@ public class TSDBImportTest { assertEquals(10, rows); } -// @After + @After public void close() throws Exception { statement.executeUpdate("drop database " + dbName); statement.close(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java new file mode 100644 index 0000000000..4b57131178 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java @@ -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(); + } +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java new file mode 100644 index 0000000000..cf44a78b97 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java @@ -0,0 +1,4 @@ +package com.taosdata.jdbc; + +public class StableTest { +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java similarity index 98% rename from src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java rename to src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java index 11698ea299..fd18d85476 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBSubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java @@ -12,7 +12,7 @@ import java.util.Properties; import static org.junit.Assert.assertTrue; -public class TSDBSubscribeTest { +public class SubscribeTest { Connection connection = null; Statement statement = null; String dbName = "test"; From e6df815118a5edd1d7e7ef2b28cdd762bec1d082 Mon Sep 17 00:00:00 2001 From: freemine Date: Thu, 11 Jun 2020 00:28:04 +0800 Subject: [PATCH 05/29] un-hard-coded-username/password --- src/cq/test/cqtest.c | 4 ++-- src/kit/taosdump/taosdump.c | 6 ++++-- src/mnode/src/mnodeAcct.c | 8 +++++--- src/mnode/src/mnodeDb.c | 12 ++++++------ src/mnode/src/mnodeDnode.c | 14 +++++++------- src/mnode/src/mnodeMnode.c | 4 +++- src/mnode/src/mnodeProfile.c | 12 ++++++------ src/mnode/src/mnodeUser.c | 20 ++++++++++---------- src/plugins/monitor/src/monitorMain.c | 4 ++-- 9 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/cq/test/cqtest.c b/src/cq/test/cqtest.c index 1416a591be..0dd2220c55 100644 --- a/src/cq/test/cqtest.c +++ b/src/cq/test/cqtest.c @@ -48,8 +48,8 @@ int main(int argc, char *argv[]) { taosInitLog("cq.log", 100000, 10); SCqCfg cqCfg; - strcpy(cqCfg.user, "root"); - strcpy(cqCfg.pass, "taosdata"); + strcpy(cqCfg.user, tsDefaultUser); + strcpy(cqCfg.pass, tsDefaultPass); cqCfg.vgId = 2; cqCfg.cqWrite = writeToQueue; diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 6cb57ef0d5..2695b0dd85 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -34,6 +34,8 @@ #include "taosdef.h" #include "tutil.h" +#include "tglobal.h" + #define COMMAND_SIZE 65536 #define DEFAULT_DUMP_FILE "taosdump.sql" @@ -324,7 +326,7 @@ void taosFreeDbInfos(); int main(int argc, char *argv[]) { SDumpArguments arguments = { // connection option - NULL, "root", "taosdata", 0, + NULL, tsDefaultUser, tsDefaultPass, 0, // output file DEFAULT_DUMP_FILE, DEFAULT_DUMP_FILE, NULL, // dump unit option @@ -502,7 +504,7 @@ int taosDumpOut(SDumpArguments *arguments) { } strncpy(dbInfos[count]->name, (char *)row[TSDB_SHOW_DB_NAME_INDEX], fields[TSDB_SHOW_DB_NAME_INDEX].bytes); - if (strcmp(arguments->user, "root") == 0) { + if (strcmp(arguments->user, tsDefaultUser) == 0) { dbInfos[count]->replica = (int)(*((int16_t *)row[TSDB_SHOW_DB_REPLICA_INDEX])); dbInfos[count]->days = (int)(*((int16_t *)row[TSDB_SHOW_DB_DAYS_INDEX])); dbInfos[count]->keep = *((int *)row[TSDB_SHOW_DB_KEEP_INDEX]); diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index 7ea5188b96..f03d8a7c5b 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -25,6 +25,8 @@ #include "mnodeSdb.h" #include "mnodeUser.h" +#include "tglobal.h" + void * tsAcctSdb = NULL; static int32_t tsAcctUpdateSize; static int32_t mnodeCreateRootAcct(); @@ -171,8 +173,8 @@ static int32_t mnodeCreateRootAcct() { SAcctObj *pAcct = malloc(sizeof(SAcctObj)); memset(pAcct, 0, sizeof(SAcctObj)); - strcpy(pAcct->user, "root"); - taosEncryptPass((uint8_t*)"taosdata", strlen("taosdata"), pAcct->pass); + strcpy(pAcct->user, tsDefaultUser); + taosEncryptPass((uint8_t*)tsDefaultPass, strlen(tsDefaultPass), pAcct->pass); pAcct->cfg = (SAcctCfg){ .maxUsers = 10, .maxDbs = 64, @@ -204,4 +206,4 @@ int32_t acctInit() { return TSDB_CODE_SUCCESS; } void acctCleanUp() {} int32_t acctCheck(void *pAcct, EAcctGrantType type) { return TSDB_CODE_SUCCESS; } -#endif \ No newline at end of file +#endif diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 3666d61adc..40f5981be9 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -472,7 +472,7 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn cols++; #ifndef __CLOUD_VERSION__ - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { #endif pShow->bytes[cols] = 4; pSchema[cols].type = TSDB_DATA_TYPE_INT; @@ -484,7 +484,7 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn #endif #ifndef __CLOUD_VERSION__ - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { #endif pShow->bytes[cols] = 2; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; @@ -508,7 +508,7 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn cols++; #ifndef __CLOUD_VERSION__ - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { #endif pShow->bytes[cols] = 4; pSchema[cols].type = TSDB_DATA_TYPE_INT; @@ -622,7 +622,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void cols++; #ifndef __CLOUD_VERSION__ - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { #endif pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int32_t *)pWrite = pDb->numOfVgroups; @@ -632,7 +632,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void #endif #ifndef __CLOUD_VERSION__ - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { #endif pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int16_t *)pWrite = pDb->cfg.replications; @@ -653,7 +653,7 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void cols++; #ifndef __CLOUD_VERSION__ - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { #endif pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int32_t *)pWrite = pDb->cfg.maxTables; // table num can be created should minus 1 diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index d2af86badb..e2e3143595 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -250,7 +250,7 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) { // TODO temporary disabled for compiling: strcpy(pCmCfgDnode->ep, pCmCfgDnode->ep); } - if (strcmp(pMsg->pUser->user, "root") != 0) { + if (strcmp(pMsg->pUser->user, tsDefaultUser) != 0) { return TSDB_CODE_MND_NO_RIGHTS; } @@ -447,7 +447,7 @@ static int32_t mnodeDropDnodeByEp(char *ep) { static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) { SCMCreateDnodeMsg *pCreate = pMsg->rpcMsg.pCont; - if (strcmp(pMsg->pUser->user, "root") != 0) { + if (strcmp(pMsg->pUser->user, tsDefaultUser) != 0) { return TSDB_CODE_MND_NO_RIGHTS; } else { int32_t code = mnodeCreateDnode(pCreate->ep); @@ -467,7 +467,7 @@ static int32_t mnodeProcessCreateDnodeMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessDropDnodeMsg(SMnodeMsg *pMsg) { SCMDropDnodeMsg *pDrop = pMsg->rpcMsg.pCont; - if (strcmp(pMsg->pUser->user, "root") != 0) { + if (strcmp(pMsg->pUser->user, tsDefaultUser) != 0) { return TSDB_CODE_MND_NO_RIGHTS; } else { int32_t code = mnodeDropDnodeByEp(pDrop->ep); @@ -486,7 +486,7 @@ static int32_t mnodeGetDnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->pAcct->user, "root") != 0) { + if (strcmp(pUser->pAcct->user, tsDefaultUser) != 0) { mnodeDecUserRef(pUser); return TSDB_CODE_MND_NO_RIGHTS; } @@ -615,7 +615,7 @@ static int32_t mnodeGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) { + if (strcmp(pUser->user, tsDefaultUser) != 0) { mnodeDecUserRef(pUser); return TSDB_CODE_MND_NO_RIGHTS; } @@ -725,7 +725,7 @@ static int32_t mnodeGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) { + if (strcmp(pUser->user, tsDefaultUser) != 0) { mnodeDecUserRef(pUser); return TSDB_CODE_MND_NO_RIGHTS; } @@ -812,7 +812,7 @@ static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) { + if (strcmp(pUser->user, tsDefaultUser) != 0) { mnodeDecUserRef(pUser); return TSDB_CODE_MND_NO_RIGHTS; } diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index 43ee45f3b1..604b53323f 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -31,6 +31,8 @@ #include "mnodeShow.h" #include "mnodeUser.h" +#include "tglobal.h" + static void * tsMnodeSdb = NULL; static int32_t tsMnodeUpdateSize = 0; static SRpcIpSet tsMnodeIpSetForShell; @@ -333,7 +335,7 @@ static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->pAcct->user, "root") != 0) { + if (strcmp(pUser->pAcct->user, tsDefaultUser) != 0) { mnodeDecUserRef(pUser); return TSDB_CODE_MND_NO_RIGHTS; } diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index bfb92096ec..245deb6321 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -168,7 +168,7 @@ static void *mnodeGetNextConn(SHashMutableIterator *pIter, SConnObj **pConn) { static int32_t mnodeGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + if (strcmp(pUser->user, tsDefaultUser) != 0) return TSDB_CODE_MND_NO_RIGHTS; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -282,7 +282,7 @@ int32_t mnodeSaveQueryStreamList(SConnObj *pConn, SCMHeartBeatMsg *pHBMsg) { static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + if (strcmp(pUser->user, tsDefaultUser) != 0) return TSDB_CODE_MND_NO_RIGHTS; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -391,7 +391,7 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) { SUserObj *pUser = mnodeGetUserFromConn(pConn); if (pUser == NULL) return 0; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + if (strcmp(pUser->user, tsDefaultUser) != 0) return TSDB_CODE_MND_NO_RIGHTS; int32_t cols = 0; SSchema *pSchema = pMeta->schema; @@ -519,7 +519,7 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) { SUserObj *pUser = pMsg->pUser; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + if (strcmp(pUser->user, tsDefaultUser) != 0) return TSDB_CODE_MND_NO_RIGHTS; SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont; mPrint("kill query msg is received, queryId:%s", pKill->queryId); @@ -549,7 +549,7 @@ static int32_t mnodeProcessKillQueryMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) { SUserObj *pUser = pMsg->pUser; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + if (strcmp(pUser->user, tsDefaultUser) != 0) return TSDB_CODE_MND_NO_RIGHTS; SCMKillQueryMsg *pKill = pMsg->rpcMsg.pCont; mPrint("kill stream msg is received, streamId:%s", pKill->queryId); @@ -579,7 +579,7 @@ static int32_t mnodeProcessKillStreamMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessKillConnectionMsg(SMnodeMsg *pMsg) { SUserObj *pUser = pMsg->pUser; - if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_MND_NO_RIGHTS; + if (strcmp(pUser->user, tsDefaultUser) != 0) return TSDB_CODE_MND_NO_RIGHTS; SCMKillConnMsg *pKill = pMsg->rpcMsg.pCont; SConnObj * pConn = taosCacheAcquireByName(tsMnodeConnCache, pKill->queryId); diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index aab0847a6b..37614047a7 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -103,8 +103,8 @@ static int32_t mnodeUserActionDecode(SSdbOper *pOper) { static int32_t mnodeUserActionRestored() { if (dnodeIsFirstDeploy()) { - SAcctObj *pAcct = mnodeGetAcct("root"); - mnodeCreateUser(pAcct, "root", "taosdata"); + SAcctObj *pAcct = mnodeGetAcct(tsDefaultUser); + mnodeCreateUser(pAcct, tsDefaultUser, tsDefaultPass); mnodeCreateUser(pAcct, "monitor", tsInternalPass); mnodeCreateUser(pAcct, "_root", tsInternalPass); mnodeDecAcctRef(pAcct); @@ -218,7 +218,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass) { pUser->createdTime = taosGetTimestampMs(); pUser->superAuth = 0; pUser->writeAuth = 1; - if (strcmp(pUser->user, "root") == 0 || strcmp(pUser->user, pUser->acct) == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0 || strcmp(pUser->user, pUser->acct) == 0) { pUser->superAuth = 1; } @@ -392,12 +392,12 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) { if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) { bool hasRight = false; - if (strcmp(pOperUser->user, "root") == 0) { + if (strcmp(pOperUser->user, tsDefaultUser) == 0) { hasRight = true; } else if (strcmp(pUser->user, pOperUser->user) == 0) { hasRight = true; } else if (pOperUser->superAuth) { - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { hasRight = false; } else if (strcmp(pOperUser->acct, pUser->acct) != 0) { hasRight = false; @@ -418,16 +418,16 @@ static int32_t mnodeProcessAlterUserMsg(SMnodeMsg *pMsg) { } else if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) { bool hasRight = false; - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { hasRight = false; } else if (strcmp(pUser->user, pUser->acct) == 0) { hasRight = false; - } else if (strcmp(pOperUser->user, "root") == 0) { + } else if (strcmp(pOperUser->user, tsDefaultUser) == 0) { hasRight = true; } else if (strcmp(pUser->user, pOperUser->user) == 0) { hasRight = false; } else if (pOperUser->superAuth) { - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { hasRight = false; } else if (strcmp(pOperUser->acct, pUser->acct) != 0) { hasRight = false; @@ -482,9 +482,9 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg) { } bool hasRight = false; - if (strcmp(pUser->user, "root") == 0) { + if (strcmp(pUser->user, tsDefaultUser) == 0) { hasRight = false; - } else if (strcmp(pOperUser->user, "root") == 0) { + } else if (strcmp(pOperUser->user, tsDefaultUser) == 0) { hasRight = true; } else if (strcmp(pUser->user, pOperUser->user) == 0) { hasRight = false; diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index ff9faa845c..a0dd72936b 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -177,8 +177,8 @@ static void dnodeBuildMonitorSql(char *sql, int32_t cmd) { ") tags (acctId binary(%d))", tsMonitorDbName, TSDB_USER_LEN + 1); } else if (cmd == MONITOR_CMD_CREATE_TB_ACCT_ROOT) { - snprintf(sql, SQL_LENGTH, "create table if not exists %s.acct_%s using %s.acct tags('%s')", tsMonitorDbName, "root", - tsMonitorDbName, "root"); + snprintf(sql, SQL_LENGTH, "create table if not exists %s.acct_%s using %s.acct tags('%s')", tsMonitorDbName, tsDefaultUser, + tsMonitorDbName, tsDefaultUser); } else if (cmd == MONITOR_CMD_CREATE_TB_SLOWQUERY) { snprintf(sql, SQL_LENGTH, "create table if not exists %s.slowquery(ts timestamp, username " From 029fb0269d4f472ef321b3e279fdbe03d578a5a7 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Thu, 11 Jun 2020 13:48:46 +0800 Subject: [PATCH 06/29] feat: add connectiontest --- .../com/taosdata/jdbc/ConnectionTest.java | 56 +++++++++ .../java/com/taosdata/jdbc/StableTest.java | 107 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java new file mode 100644 index 0000000000..ca38765ec5 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java @@ -0,0 +1,56 @@ +package com.taosdata.jdbc; + +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +import static org.junit.Assert.assertTrue; + +public class ConnectionTest { + static Connection connection = null; + static Statement statement = null; + static String dbName = "test"; + static String stbName = "st"; + static String host = "localhost"; + + @Test + public static void createConnection() 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); + + assertTrue(null != connection); + } + + @Test + public void createDatabase() { + try { + statement.executeUpdate("create database if not exists " + dbName); + } catch (SQLException e) { + assert false : "create database error: " + e.getMessage(); + } + } + + @Test + public void close() { + try { + if (!statement.isClosed()) { + statement.executeUpdate("drop database " + dbName); + statement.close(); + connection.close(); + } + } catch (SQLException e) { + assert false : "close connection error: " + e.getMessage(); + } + } +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java index cf44a78b97..b0c5862dec 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java @@ -1,4 +1,111 @@ package com.taosdata.jdbc; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.*; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + public class StableTest { + static Connection connection = null; + static Statement statement = null; + static String dbName = "test"; + static String stbName = "st"; + static String host = "localhost"; + + @BeforeClass + public static void createDatabase() 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("create database if not exists " + dbName); + statement.executeQuery("use " + dbName); + } + + @Test + public void createStable() { + String sql = "create table " + stbName + " (ts timestamp, v1 int, v2 int) tags (tg nchar(20)) "; + + try { + statement.executeUpdate(sql); + } catch (SQLException e) { + assert false : "error create stable" + e.getMessage(); + } + } + + @Test + public void createTable() { + String sql = "create table t1 using " + stbName + " tags (\"beijing\")"; + + try { + statement.executeUpdate(sql); + } catch (SQLException e) { + assert false : "error create table" + e.getMessage(); + } + } + + @Test + public void describeSTable() { + String sql = "describe " + stbName; + int num = 0; + System.out.println("describe stable"); + try { + ResultSet res = statement.executeQuery(sql); + while (res.next()) { + for (int i = 1; i <= res.getMetaData().getColumnCount(); i++) { + System.out.printf("%d: %s\n", i, res.getString(i)); + } + num++; + } + assertEquals(4, num); + } catch (SQLException e) { + assert false : "error describe stable" + e.getMessage(); + } + } + + @Test + public void describeTable() { + String sql = "describe t1"; + int num = 0; + System.out.println("describe table"); + try { + ResultSet res = statement.executeQuery(sql); + while (res.next()) { + for (int i = 1; i <= res.getMetaData().getColumnCount(); i++) { + System.out.printf("%d: %s\n", i, res.getString(i)); + } + num++; + } + assertEquals(4, num); + } catch (SQLException e) { + assert false : "error describe stable" + e.getMessage(); + } + } + + @Test + public void validCreateSql() { + String sql = "create table t2 using " + stbName + " tags (\"beijing\")"; + boolean valid = ((TSDBConnection)connection).getConnection().validateCreateTableSql(sql); + assertEquals(true, valid); + } + + @AfterClass + public static void close() throws Exception { + if (!statement.isClosed()) { + statement.executeUpdate("drop database " + dbName); + statement.close(); + connection.close(); + } + } } From 35c92cc80ef700485d5dea8a67d494b6195c8617 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Thu, 11 Jun 2020 19:12:39 +0800 Subject: [PATCH 07/29] tests: add test --- .../java/com/taosdata/jdbc/TSDBStatement.java | 22 +-- .../com/taosdata/jdbc/ConnectionTest.java | 24 +-- .../java/com/taosdata/jdbc/ResultSetTest.java | 129 +++++++++++++++ .../java/com/taosdata/jdbc/SelectTest.java | 2 + .../java/com/taosdata/jdbc/StatementTest.java | 155 ++++++++++++++++++ .../java/com/taosdata/jdbc/SubscribeTest.java | 6 +- 6 files changed, 314 insertions(+), 24 deletions(-) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index c856c03a83..1cf024f30e 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -51,17 +51,16 @@ public class TSDBStatement implements Statement { if (isClosed) { throw new SQLException("Invalid method call on a closed statement."); } - System.out.println(sql); - long res = this.connecter.executeQuery(sql); + pSql = this.connecter.executeQuery(sql); long resultSetPointer = this.connecter.getResultSet(); if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { - this.connecter.freeResultSet(res); + this.connecter.freeResultSet(pSql); throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); } else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) { // create/insert/update/del/alter - this.connecter.freeResultSet(res); + this.connecter.freeResultSet(pSql); return null; } else { return new TSDBResultSet(this.connecter, resultSetPointer); @@ -72,18 +71,18 @@ public class TSDBStatement implements Statement { if (isClosed) { throw new SQLException("Invalid method call on a closed statement."); } - long res = this.connecter.executeQuery(sql); + pSql = this.connecter.executeQuery(sql); long resultSetPointer = this.connecter.getResultSet(); if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { - this.connecter.freeResultSet(res); + this.connecter.freeResultSet(pSql); throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); } else if (resultSetPointer != TSDBConstants.JNI_NULL_POINTER) { this.connecter.freeResultSet(); throw new SQLException("The executed SQL is not a DML or a DDL"); } else { - int num = this.connecter.getAffectedRows(res); - this.connecter.freeResultSet(res); + int num = this.connecter.getAffectedRows(pSql); + this.connecter.freeResultSet(pSql); return num; } } @@ -151,16 +150,19 @@ public class TSDBStatement implements Statement { throw new SQLException("Invalid method call on a closed statement."); } boolean res = true; - this.connecter.executeQuery(sql); + pSql = this.connecter.executeQuery(sql); long resultSetPointer = this.connecter.getResultSet(); if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) { + this.connecter.freeResultSet(pSql); throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); } else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) { // no result set is retrieved res = false; } - return res; + this.connecter.freeResultSet(pSql); + + return res; } public ResultSet getResultSet() throws SQLException { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java index ca38765ec5..a932f28113 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java @@ -18,7 +18,7 @@ public class ConnectionTest { static String host = "localhost"; @Test - public static void createConnection() throws SQLException { + public void testConnection() throws SQLException { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); } catch (ClassNotFoundException e) { @@ -30,23 +30,25 @@ public class ConnectionTest { , properties); assertTrue(null != connection); - } + statement = connection.createStatement(); + assertTrue(null != statement); + + // try reconnect + connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" + , properties); - @Test - public void createDatabase() { try { - statement.executeUpdate("create database if not exists " + dbName); + statement.execute("create database if not exists " + dbName); } catch (SQLException e) { assert false : "create database error: " + e.getMessage(); } - } - @Test - public void close() { try { - if (!statement.isClosed()) { - statement.executeUpdate("drop database " + dbName); - statement.close(); + if (!connection.isClosed()) { + if (!statement.isClosed()) { + statement.executeUpdate("drop database " + dbName); + statement.close(); + } connection.close(); } } catch (SQLException e) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java new file mode 100644 index 0000000000..a92d8900d7 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java @@ -0,0 +1,129 @@ +package com.taosdata.jdbc; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.*; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class ResultSetTest { + static Connection connection = null; + static Statement statement = null; + static String dbName = "test"; + static String tName = "t0"; + static String host = "localhost"; + static ResultSet resSet = null; + + @BeforeClass + public static 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, k1 int, k2 bigint, k3 float, k4 double, k5 binary(30), k6 smallint, k7 bool, k8 nchar(20))"); + + statement.executeQuery("use " + dbName); + } + + @Test + public void testResultSet() { + String sql = null; + long ts = 1496732686000l; + int v1 = 2147483600; + long v2 = ts + 1000; + float v3 = 3.1415926f; + double v4 = 3.1415926535897; + String v5 = "涛思数据,强~!"; + short v6 = 12; + boolean v7 = false; + String v8 = "TDengine is powerful"; + + sql = "insert into " + dbName + "." + tName + " values (" + ts + "," + v1 + "," + v2 + "," + v3 + "," + v4 + + ",\"" + v5 + "\"," + v6 + "," + v7 + ",\"" + v8 + "\")"; +// System.out.println(sql); + + try { + statement.executeUpdate(sql); + assertEquals(1, statement.getUpdateCount()); + } catch (SQLException e) { + assert false : "insert error " + e.getMessage(); + } + + try { + statement.executeQuery("select * from " + dbName + "." + tName); + resSet = statement.getResultSet(); + System.out.println(((TSDBResultSet) resSet).getRowData()); + while (resSet.next()) { + assertEquals(ts, resSet.getLong(1)); + assertEquals(ts, resSet.getLong("ts")); + + System.out.println(resSet.getTimestamp(1)); + + assertEquals(v1, resSet.getInt(2)); + assertEquals(v1, resSet.getInt("k1")); + + assertEquals(v2, resSet.getLong(3)); + assertEquals(v2, resSet.getLong("k2")); + + assertEquals(v3, resSet.getFloat(4), 7); + assertEquals(v3, resSet.getFloat("k3"), 7); + + assertEquals(v4, resSet.getDouble(5), 13); + assertEquals(v4, resSet.getDouble("k4"), 13); + + assertEquals(v5, resSet.getString(6)); + assertEquals(v5, resSet.getString("k5")); + + assertEquals(v6, resSet.getShort(7)); + assertEquals(v6, resSet.getShort("k6")); + + assertEquals(v7, resSet.getBoolean(8)); + assertEquals(v7, resSet.getBoolean("k7")); + + assertEquals(v8, resSet.getString(9)); + assertEquals(v8, resSet.getString("k8")); + + resSet.getBytes(9); + resSet.getObject(6); + resSet.getObject("k8"); + } + resSet.close(); + } catch (SQLException e) { + assert false : "insert error " + e.getMessage(); + } + } + + @Test + public void testBatch() throws SQLException { + String[] sqls = new String[]{"insert into test.t0 values (1496732686001,2147483600,1496732687000,3.1415925,3.1415926\n" + + "535897,\"涛思数据,强~!\",12,12,\"TDengine is powerful\")", "insert into test.t0 values (1496732686002,2147483600,1496732687000,3.1415925,3.1415926\n" + + "535897,\"涛思数据,强~!\",12,12,\"TDengine is powerful\")"}; + for (String sql : sqls) { + statement.addBatch(sql); + } + int[] res = statement.executeBatch(); + assertEquals(res.length, 2); + statement.clearBatch(); + } + + @AfterClass + public static void close() throws SQLException { + statement.executeUpdate("drop database " + dbName); + statement.close(); + connection.close(); + } + +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java index 4b57131178..077f95318b 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc; +import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -57,6 +58,7 @@ public class SelectTest { assertEquals(num, 50); } + @After public void close() throws SQLException { statement.executeUpdate("drop database " + dbName); statement.close(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java new file mode 100644 index 0000000000..f5e2bcba20 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java @@ -0,0 +1,155 @@ +package com.taosdata.jdbc; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.*; +import java.util.Properties; + +import static org.junit.Assert.assertTrue; + +public class StatementTest { + static Connection connection = null; + static Statement statement = null; + static String dbName = "test"; + static String tName = "t0"; + static String host = "localhost"; + static ResultSet resSet = null; + + @BeforeClass + public static void createConnection() 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); + + } + + @Test + public void createTableAndQuery() throws SQLException { + long ts = System.currentTimeMillis(); + + statement.executeUpdate("create database if not exists " + dbName); + statement.executeUpdate("create table if not exists " + dbName + "." + tName + "(ts timestamp, k1 int)"); + statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)"); + statement.executeQuery("select * from " + dbName + "." + tName); + ResultSet resultSet = statement.getResultSet(); + assertTrue(null != resultSet); + } + + @Test + public void testUnsupport() { +// if(null == resSet) { +// return; +// } + TSDBStatement tsdbStatement = (TSDBStatement) statement; + try { + tsdbStatement.unwrap(null); + } catch (SQLException e) { + } + try { + tsdbStatement.isWrapperFor(null); + } catch (SQLException e) { + } + try { + tsdbStatement.getMaxFieldSize(); + } catch (SQLException e) { + } + try { + tsdbStatement.setMaxFieldSize(0); + } catch (SQLException e) { + } + try { + tsdbStatement.setEscapeProcessing(true); + } catch (SQLException e) { + } + try { + tsdbStatement.cancel(); + } catch (SQLException e) { + } + try { + tsdbStatement.getWarnings(); + } catch (SQLException e) { + } + try { + tsdbStatement.clearWarnings(); + } catch (SQLException e) { + } + try { + tsdbStatement.setCursorName(null); + } catch (SQLException e) { + } + try { + tsdbStatement.getMoreResults(); + } catch (SQLException e) { + } + try { + tsdbStatement.setFetchDirection(0); + } catch (SQLException e) { + } + try { + tsdbStatement.getFetchDirection(); + } catch (SQLException e) { + } + try { + tsdbStatement.getResultSetConcurrency(); + } catch (SQLException e) { + } + try { + tsdbStatement.getResultSetType(); + } catch (SQLException e) { + } + try { + tsdbStatement.getConnection(); + } catch (SQLException e) { + } + try { + tsdbStatement.getMoreResults(); + } catch (SQLException e) { + } + try { + tsdbStatement.getGeneratedKeys(); + } catch (SQLException e) { + } + try { + tsdbStatement.executeUpdate(null, 0); + } catch (SQLException e) { + } + try { + tsdbStatement.executeUpdate(null, new int[]{0}); + } catch (SQLException e) { + } + try { + tsdbStatement.executeUpdate(null, new String[]{"str1", "str2"}); + } catch (SQLException e) { + } + try { + tsdbStatement.getResultSetHoldability(); + } catch (SQLException e) { + } + try { + tsdbStatement.setPoolable(true); + } catch (SQLException e) { + } + try { + tsdbStatement.isPoolable(); + } catch (SQLException e) { + } + try { + tsdbStatement.closeOnCompletion(); + } catch (SQLException e) { + } + try { + tsdbStatement.isCloseOnCompletion(); + } catch (SQLException e) { + } + } +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java index fd18d85476..792ae5f671 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java @@ -20,7 +20,7 @@ public class SubscribeTest { String host = "localhost"; String topic = "test"; - @Before +// @Before public void createDatabase() throws SQLException { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); @@ -42,7 +42,7 @@ public class SubscribeTest { } } - @Test +// @Test public void subscribe() throws Exception { TSDBSubscribe subscribe = null; long subscribId = 0; @@ -81,7 +81,7 @@ public class SubscribeTest { } } - @After +// @After public void close() throws Exception { statement.executeQuery("drop database " + dbName); statement.close(); From 25f54f60ac9d23173887a1723296c31f9c6a9c78 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Fri, 12 Jun 2020 18:55:14 +0800 Subject: [PATCH 08/29] tests --- .../taosdata/jdbc/PreparedStatementTest.java | 161 ++++ .../java/com/taosdata/jdbc/ResultSetTest.java | 697 +++++++++++++++++- .../java/com/taosdata/jdbc/StatementTest.java | 4 + 3 files changed, 860 insertions(+), 2 deletions(-) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java new file mode 100644 index 0000000000..d9aac70bdc --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java @@ -0,0 +1,161 @@ +package com.taosdata.jdbc; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.*; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class PreparedStatementTest { + static Connection connection = null; + static PreparedStatement statement = null; + static String dbName = "test"; + static String tName = "t0"; + static String host = "localhost"; + static ResultSet resSet = null; + + @BeforeClass + public static void createConnection() 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); + + String sql = "drop database if exists " + dbName; + statement = (TSDBPreparedStatement) connection.prepareStatement(sql); + + } + + @Test + public void createTableAndQuery() throws SQLException { + long ts = System.currentTimeMillis(); + + statement.executeUpdate("create database if not exists " + dbName); + statement.executeUpdate("create table if not exists " + dbName + "." + tName + "(ts timestamp, k1 int)"); + statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)"); + + PreparedStatement selectStatement = connection.prepareStatement("select * from " + dbName + "." + tName); + + ResultSet resultSet = selectStatement.executeQuery(); + assertTrue(null != resultSet); + + boolean isClosed = statement.isClosed(); + assertEquals(false, isClosed); + } + + @Test + public void testUnsupport() { +// if(null == resSet) { +// return; +// } + TSDBPreparedStatement tsdbStatement = (TSDBPreparedStatement) statement; + try { + tsdbStatement.unwrap(null); + } catch (SQLException e) { + } + try { + tsdbStatement.isWrapperFor(null); + } catch (SQLException e) { + } + try { + tsdbStatement.getMaxFieldSize(); + } catch (SQLException e) { + } + try { + tsdbStatement.setMaxFieldSize(0); + } catch (SQLException e) { + } + try { + tsdbStatement.setEscapeProcessing(true); + } catch (SQLException e) { + } + try { + tsdbStatement.cancel(); + } catch (SQLException e) { + } + try { + tsdbStatement.getWarnings(); + } catch (SQLException e) { + } + try { + tsdbStatement.clearWarnings(); + } catch (SQLException e) { + } + try { + tsdbStatement.setCursorName(null); + } catch (SQLException e) { + } + try { + tsdbStatement.getMoreResults(); + } catch (SQLException e) { + } + try { + tsdbStatement.setFetchDirection(0); + } catch (SQLException e) { + } + try { + tsdbStatement.getFetchDirection(); + } catch (SQLException e) { + } + try { + tsdbStatement.getResultSetConcurrency(); + } catch (SQLException e) { + } + try { + tsdbStatement.getResultSetType(); + } catch (SQLException e) { + } + try { + tsdbStatement.getConnection(); + } catch (SQLException e) { + } + try { + tsdbStatement.getMoreResults(); + } catch (SQLException e) { + } + try { + tsdbStatement.getGeneratedKeys(); + } catch (SQLException e) { + } + try { + tsdbStatement.executeUpdate(null, 0); + } catch (SQLException e) { + } + try { + tsdbStatement.executeUpdate(null, new int[]{0}); + } catch (SQLException e) { + } + try { + tsdbStatement.executeUpdate(null, new String[]{"str1", "str2"}); + } catch (SQLException e) { + } + try { + tsdbStatement.getResultSetHoldability(); + } catch (SQLException e) { + } + try { + tsdbStatement.setPoolable(true); + } catch (SQLException e) { + } + try { + tsdbStatement.isPoolable(); + } catch (SQLException e) { + } + try { + tsdbStatement.closeOnCompletion(); + } catch (SQLException e) { + } + try { + tsdbStatement.isCloseOnCompletion(); + } catch (SQLException e) { + } + } +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java index a92d8900d7..9d5f5451f2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java @@ -4,10 +4,14 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import javax.sql.rowset.serial.SerialBlob; +import javax.sql.rowset.serial.SerialClob; import java.sql.*; +import java.util.HashMap; import java.util.Properties; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class ResultSetTest { static Connection connection = null; @@ -53,7 +57,6 @@ public class ResultSetTest { sql = "insert into " + dbName + "." + tName + " values (" + ts + "," + v1 + "," + v2 + "," + v3 + "," + v4 + ",\"" + v5 + "\"," + v6 + "," + v7 + ",\"" + v8 + "\")"; -// System.out.println(sql); try { statement.executeUpdate(sql); @@ -100,12 +103,702 @@ public class ResultSetTest { resSet.getObject(6); resSet.getObject("k8"); } - resSet.close(); + if (!resSet.isClosed()) { + resSet.close(); + } } catch (SQLException e) { assert false : "insert error " + e.getMessage(); } } + @Test + public void testUnsupport() throws SQLException { + statement.executeQuery("show databases"); + resSet = statement.getResultSet(); + try { + resSet.unwrap(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.isWrapperFor(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getAsciiStream(0); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getUnicodeStream(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getBinaryStream(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getAsciiStream(""); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getUnicodeStream(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getBinaryStream(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getWarnings(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.clearWarnings(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getCursorName(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getCharacterStream(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getCharacterStream(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.isBeforeFirst(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.isAfterLast(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.isFirst(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.isLast(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.beforeFirst(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.afterLast(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.first(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.last(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getRow(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.absolute(1); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.relative(1); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.previous(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.setFetchDirection(0); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getFetchDirection(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.setFetchSize(0); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getFetchSize(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getConcurrency(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.rowUpdated(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.rowInserted(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.rowDeleted(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateNull(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBoolean(0, true); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateByte(0, (byte) 2); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateShort(0, (short) 1); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateInt(0, 0); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateLong(0, 0l); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateFloat(0, 3.14f); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateDouble(0, 3.1415); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBigDecimal(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateString(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBytes(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateDate(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateTime(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateTimestamp(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateAsciiStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBinaryStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateObject(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateObject(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateNull(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBoolean("", false); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateByte("", (byte) 1); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateShort("", (short) 1); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateInt("", 0); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateLong("", 0l); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateFloat("", 3.14f); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateDouble("", 3.1415); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBigDecimal(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateString(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBytes(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateDate(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateTime(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateTimestamp(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateAsciiStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBinaryStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateObject(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateObject(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.insertRow(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateRow(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.deleteRow(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.refreshRow(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.cancelRowUpdates(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.moveToInsertRow(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.moveToCurrentRow(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getStatement(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getObject(0, new HashMap<>()); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getRef(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getBlob(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getClob(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getArray(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getObject("", new HashMap<>()); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getRef(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getBlob(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getClob(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getArray(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getDate(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getDate(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getTime(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getTime(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getTimestamp(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getTimestamp(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getURL(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getURL(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateRef(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateRef(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBlob(0, new SerialBlob("".getBytes("UTF8"))); + } catch (Exception e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBlob("", new SerialBlob("".getBytes("UTF8"))); + } catch (Exception e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateClob("", new SerialClob("".toCharArray())); + } catch (Exception e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateClob(0, new SerialClob("".toCharArray())); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateArray(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateArray(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getRowId(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getRowId(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateRowId(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateRowId(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getHoldability(); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateNString(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateNString(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + + try { + resSet.getNClob(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getNClob(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getSQLXML(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getSQLXML(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateSQLXML(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateSQLXML(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getNCharacterStream(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.getNCharacterStream(null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateNCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateNCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateAsciiStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBinaryStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateAsciiStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBinaryStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + + try { + resSet.updateNCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateNCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateAsciiStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBinaryStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateAsciiStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateBinaryStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + try { + resSet.updateCharacterStream(null, null); + } catch (SQLException e) { + assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); + } + } + @Test public void testBatch() throws SQLException { String[] sqls = new String[]{"insert into test.t0 values (1496732686001,2147483600,1496732687000,3.1415925,3.1415926\n" + diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java index f5e2bcba20..5141e87405 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java @@ -6,6 +6,7 @@ import org.junit.Test; import java.sql.*; import java.util.Properties; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class StatementTest { @@ -43,6 +44,9 @@ public class StatementTest { statement.executeQuery("select * from " + dbName + "." + tName); ResultSet resultSet = statement.getResultSet(); assertTrue(null != resultSet); + + boolean isClosed = statement.isClosed(); + assertEquals(false, isClosed); } @Test From 1ff6e7c7dd955c8e90d583eaee85a821019c1bc4 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Mon, 15 Jun 2020 11:13:17 +0800 Subject: [PATCH 09/29] update --- .../org.eclipse.core.resources.prefs | 5 - .../jdbc/.settings/org.eclipse.jdt.core.prefs | 13 - .../jdbc/.settings/org.eclipse.m2e.core.prefs | 4 - .../taosdata/jdbc/DatabaseMetaDataTest.java | 231 ++++++++++++++++++ .../taosdata/jdbc/PreparedStatementTest.java | 47 +++- 5 files changed, 271 insertions(+), 29 deletions(-) delete mode 100755 src/connector/jdbc/.settings/org.eclipse.core.resources.prefs delete mode 100755 src/connector/jdbc/.settings/org.eclipse.jdt.core.prefs delete mode 100755 src/connector/jdbc/.settings/org.eclipse.m2e.core.prefs create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java diff --git a/src/connector/jdbc/.settings/org.eclipse.core.resources.prefs b/src/connector/jdbc/.settings/org.eclipse.core.resources.prefs deleted file mode 100755 index 1935ba2ee4..0000000000 --- a/src/connector/jdbc/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -encoding//src/main/java=GBK -encoding//src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java=UTF-8 -encoding//src/main/resources=UTF-8 -encoding/=UTF-8 diff --git a/src/connector/jdbc/.settings/org.eclipse.jdt.core.prefs b/src/connector/jdbc/.settings/org.eclipse.jdt.core.prefs deleted file mode 100755 index 5ce4518899..0000000000 --- a/src/connector/jdbc/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,13 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/src/connector/jdbc/.settings/org.eclipse.m2e.core.prefs b/src/connector/jdbc/.settings/org.eclipse.m2e.core.prefs deleted file mode 100755 index f897a7f1cb..0000000000 --- a/src/connector/jdbc/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java new file mode 100644 index 0000000000..2154079e23 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java @@ -0,0 +1,231 @@ +package com.taosdata.jdbc; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.*; +import java.util.Properties; + +public class DatabaseMetaDataTest { + static Connection connection = null; + static PreparedStatement statement = null; + static String dbName = "test"; + static String tName = "t0"; + static String host = "localhost"; + + @BeforeClass + public static void createConnection() 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); + + String sql = "drop database if exists " + dbName; + statement = (TSDBPreparedStatement) connection.prepareStatement(sql); + 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 testMetaDataTest() throws SQLException { + + DatabaseMetaData databaseMetaData = connection.getMetaData(); + ResultSet resultSet = databaseMetaData.getTables(dbName, "t*", "t*", new String[]{"t"}); + while (resultSet.next()) { + for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) { + System.out.printf("%d: %s\n", i, resultSet.getString(i)); + } + } + databaseMetaData.isWrapperFor(null); + databaseMetaData.allProceduresAreCallable(); + databaseMetaData.allTablesAreSelectable(); + databaseMetaData.getURL(); + databaseMetaData.getUserName(); + databaseMetaData.isReadOnly(); + databaseMetaData.nullsAreSortedHigh(); + databaseMetaData.nullsAreSortedLow(); + databaseMetaData.nullsAreSortedAtStart(); + databaseMetaData.nullsAreSortedAtEnd(); + databaseMetaData.getDatabaseProductName(); + databaseMetaData.getDatabaseProductVersion(); + databaseMetaData.getDriverName(); + databaseMetaData.getDriverVersion(); + databaseMetaData.getDriverMajorVersion(); + databaseMetaData.getDriverMinorVersion(); + databaseMetaData.usesLocalFiles(); + databaseMetaData.usesLocalFilePerTable(); + databaseMetaData.supportsMixedCaseIdentifiers(); + databaseMetaData.storesUpperCaseIdentifiers(); + databaseMetaData.storesLowerCaseIdentifiers(); + databaseMetaData.storesMixedCaseIdentifiers(); + databaseMetaData.supportsMixedCaseQuotedIdentifiers(); + databaseMetaData.storesUpperCaseQuotedIdentifiers(); + databaseMetaData.storesLowerCaseQuotedIdentifiers(); + databaseMetaData.storesMixedCaseQuotedIdentifiers(); + databaseMetaData.getIdentifierQuoteString(); + databaseMetaData.getSQLKeywords(); + databaseMetaData.getNumericFunctions(); + databaseMetaData.getStringFunctions(); + databaseMetaData.getSystemFunctions(); + databaseMetaData.getTimeDateFunctions(); + databaseMetaData.getSearchStringEscape(); + databaseMetaData.getExtraNameCharacters(); + databaseMetaData.supportsAlterTableWithAddColumn(); + databaseMetaData.supportsAlterTableWithDropColumn(); + databaseMetaData.supportsColumnAliasing(); + databaseMetaData.nullPlusNonNullIsNull(); + databaseMetaData.supportsConvert(); + databaseMetaData.supportsConvert(0, 0); + databaseMetaData.supportsTableCorrelationNames(); + databaseMetaData.supportsDifferentTableCorrelationNames(); + databaseMetaData.supportsExpressionsInOrderBy(); + databaseMetaData.supportsOrderByUnrelated(); + databaseMetaData.supportsGroupBy(); + databaseMetaData.supportsGroupByUnrelated(); + databaseMetaData.supportsGroupByBeyondSelect(); + databaseMetaData.supportsLikeEscapeClause(); + databaseMetaData.supportsMultipleResultSets(); + databaseMetaData.supportsMultipleTransactions(); + databaseMetaData.supportsNonNullableColumns(); + databaseMetaData.supportsMinimumSQLGrammar(); + databaseMetaData.supportsCoreSQLGrammar(); + databaseMetaData.supportsExtendedSQLGrammar(); + databaseMetaData.supportsANSI92EntryLevelSQL(); + databaseMetaData.supportsANSI92IntermediateSQL(); + databaseMetaData.supportsANSI92FullSQL(); + databaseMetaData.supportsIntegrityEnhancementFacility(); + databaseMetaData.supportsOuterJoins(); + databaseMetaData.supportsFullOuterJoins(); + databaseMetaData.supportsLimitedOuterJoins(); + databaseMetaData.getSchemaTerm(); + databaseMetaData.getProcedureTerm(); + databaseMetaData.getCatalogTerm(); + databaseMetaData.isCatalogAtStart(); + databaseMetaData.getCatalogSeparator(); + databaseMetaData.supportsSchemasInDataManipulation(); + databaseMetaData.supportsSchemasInProcedureCalls(); + databaseMetaData.supportsSchemasInTableDefinitions(); + databaseMetaData.supportsSchemasInIndexDefinitions(); + databaseMetaData.supportsSchemasInPrivilegeDefinitions(); + databaseMetaData.supportsCatalogsInDataManipulation(); + databaseMetaData.supportsCatalogsInProcedureCalls(); + databaseMetaData.supportsCatalogsInTableDefinitions(); + databaseMetaData.supportsCatalogsInIndexDefinitions(); + databaseMetaData.supportsCatalogsInPrivilegeDefinitions(); + databaseMetaData.supportsPositionedDelete(); + databaseMetaData.supportsPositionedUpdate(); + databaseMetaData.supportsSelectForUpdate(); + databaseMetaData.supportsStoredProcedures(); + databaseMetaData.supportsSubqueriesInComparisons(); + databaseMetaData.supportsSubqueriesInExists(); + databaseMetaData.supportsSubqueriesInIns(); + databaseMetaData.supportsSubqueriesInQuantifieds(); + databaseMetaData.supportsCorrelatedSubqueries(); + databaseMetaData.supportsUnion(); + databaseMetaData.supportsUnionAll(); + databaseMetaData.supportsOpenCursorsAcrossCommit(); + databaseMetaData.supportsOpenCursorsAcrossRollback(); + databaseMetaData.supportsOpenStatementsAcrossCommit(); + databaseMetaData.supportsOpenStatementsAcrossRollback(); + databaseMetaData.getMaxBinaryLiteralLength(); + databaseMetaData.getMaxCharLiteralLength(); + databaseMetaData.getMaxColumnNameLength(); + databaseMetaData.getMaxColumnsInGroupBy(); + databaseMetaData.getMaxColumnsInIndex(); + databaseMetaData.getMaxColumnsInOrderBy(); + databaseMetaData.getMaxColumnsInSelect(); + databaseMetaData.getMaxColumnsInTable(); + databaseMetaData.getMaxConnections(); + databaseMetaData.getMaxCursorNameLength(); + databaseMetaData.getMaxIndexLength(); + databaseMetaData.getMaxSchemaNameLength(); + databaseMetaData.getMaxProcedureNameLength(); + databaseMetaData.getMaxCatalogNameLength(); + databaseMetaData.getMaxRowSize(); + databaseMetaData.doesMaxRowSizeIncludeBlobs(); + databaseMetaData.getMaxStatementLength(); + databaseMetaData.getMaxStatements(); + databaseMetaData.getMaxTableNameLength(); + databaseMetaData.getMaxTablesInSelect(); + databaseMetaData.getMaxUserNameLength(); + databaseMetaData.getDefaultTransactionIsolation(); + databaseMetaData.supportsTransactions(); + databaseMetaData.supportsTransactionIsolationLevel(0); + databaseMetaData.supportsDataDefinitionAndDataManipulationTransactions(); + databaseMetaData.supportsDataManipulationTransactionsOnly(); + databaseMetaData.dataDefinitionCausesTransactionCommit(); + databaseMetaData.dataDefinitionIgnoredInTransactions(); + try { + databaseMetaData.getProcedures("", "", ""); + } catch (Exception e) { + } + try { + databaseMetaData.getProcedureColumns("", "", "", ""); + } catch (Exception e) { + } + try { + databaseMetaData.getTables("", "", "", new String[]{""}); + } catch (Exception e) { + } + databaseMetaData.getSchemas(); + databaseMetaData.getCatalogs(); +// databaseMetaData.getTableTypes(); + + databaseMetaData.getColumns("", "", "", ""); + databaseMetaData.getColumnPrivileges("", "", "", ""); + databaseMetaData.getTablePrivileges("", "", ""); + databaseMetaData.getBestRowIdentifier("", "", "", 0, false); + databaseMetaData.getVersionColumns("", "", ""); + databaseMetaData.getPrimaryKeys("", "", ""); + databaseMetaData.getImportedKeys("", "", ""); + databaseMetaData.getExportedKeys("", "", ""); + databaseMetaData.getCrossReference("", "", "", "", "", ""); + databaseMetaData.getTypeInfo(); + databaseMetaData.getIndexInfo("", "", "", false, false); + databaseMetaData.supportsResultSetType(0); + databaseMetaData.supportsResultSetConcurrency(0, 0); + databaseMetaData.ownUpdatesAreVisible(0); + databaseMetaData.ownDeletesAreVisible(0); + databaseMetaData.ownInsertsAreVisible(0); + databaseMetaData.othersUpdatesAreVisible(0); + databaseMetaData.othersDeletesAreVisible(0); + databaseMetaData.othersInsertsAreVisible(0); + databaseMetaData.updatesAreDetected(0); + databaseMetaData.deletesAreDetected(0); + databaseMetaData.insertsAreDetected(0); + databaseMetaData.supportsBatchUpdates(); + databaseMetaData.getUDTs("", "", "", new int[]{0}); + databaseMetaData.getConnection(); + databaseMetaData.supportsSavepoints(); + databaseMetaData.supportsNamedParameters(); + databaseMetaData.supportsMultipleOpenResults(); + databaseMetaData.supportsGetGeneratedKeys(); + databaseMetaData.getSuperTypes("", "", ""); + databaseMetaData.getSuperTables("", "", ""); + databaseMetaData.getAttributes("", "", "", ""); + databaseMetaData.supportsResultSetHoldability(0); + databaseMetaData.getResultSetHoldability(); + databaseMetaData.getDatabaseMajorVersion(); + databaseMetaData.getDatabaseMinorVersion(); + databaseMetaData.getJDBCMajorVersion(); + databaseMetaData.getJDBCMinorVersion(); + databaseMetaData.getSQLStateType(); + databaseMetaData.locatorsUpdateCopy(); + databaseMetaData.supportsStatementPooling(); + databaseMetaData.getRowIdLifetime(); + databaseMetaData.getSchemas("", ""); + databaseMetaData.supportsStoredFunctionsUsingCallSyntax(); + databaseMetaData.autoCommitFailureClosesAllResultSets(); + databaseMetaData.getClientInfoProperties(); + databaseMetaData.getFunctions("", "", ""); + databaseMetaData.getFunctionColumns("", "", "", ""); + databaseMetaData.getPseudoColumns("", "", "", ""); + databaseMetaData.generatedKeyAlwaysReturned(); + + } +} diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java index d9aac70bdc..dc26f7d9df 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java @@ -1,9 +1,11 @@ package com.taosdata.jdbc; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import java.sql.*; +import java.util.ArrayList; import java.util.Properties; import static org.junit.Assert.assertEquals; @@ -26,8 +28,8 @@ public class PreparedStatementTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" - , properties); + connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata", + properties); String sql = "drop database if exists " + dbName; statement = (TSDBPreparedStatement) connection.prepareStatement(sql); @@ -51,11 +53,34 @@ public class PreparedStatementTest { assertEquals(false, isClosed); } + @Test + public void testPreparedStatement() throws SQLException { + long ts = System.currentTimeMillis(); + PreparedStatement saveStatement = connection + .prepareStatement("insert into " + dbName + "." + tName + " values (" + ts + ", 1)"); + + int affectedRows = saveStatement.executeUpdate(); + assertTrue(1 == affectedRows); + } + + @Test + public void testSavedPreparedStatement() throws SQLException { + long ts = System.currentTimeMillis(); + + TSDBPreparedStatement saveStatement = (TSDBPreparedStatement) connection + .prepareStatement("insert into " + dbName + "." + tName + " values (?, ?)"); + + saveStatement.setObject(1, ts + 100); + saveStatement.setObject(2, 3); + int rows = saveStatement.executeUpdate(); + assertEquals(1, rows); + } + @Test public void testUnsupport() { -// if(null == resSet) { -// return; -// } + // if(null == resSet) { + // return; + // } TSDBPreparedStatement tsdbStatement = (TSDBPreparedStatement) statement; try { tsdbStatement.unwrap(null); @@ -130,11 +155,11 @@ public class PreparedStatementTest { } catch (SQLException e) { } try { - tsdbStatement.executeUpdate(null, new int[]{0}); + tsdbStatement.executeUpdate(null, new int[] { 0 }); } catch (SQLException e) { } try { - tsdbStatement.executeUpdate(null, new String[]{"str1", "str2"}); + tsdbStatement.executeUpdate(null, new String[] { "str1", "str2" }); } catch (SQLException e) { } try { @@ -158,4 +183,12 @@ public class PreparedStatementTest { } catch (SQLException e) { } } + + @AfterClass + public static void close() throws SQLException { + statement.executeUpdate("drop database " + dbName); + statement.close(); + connection.close(); + } + } From bfe2a9aac128b6376da3c97f94060fa6b3f04bab Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Mon, 15 Jun 2020 16:57:04 +0800 Subject: [PATCH 10/29] fix: scan3 bug --- .../taosdata/jdbc/TSDBDatabaseMetaData.java | 5 +++-- .../com/taosdata/jdbc/TSDBJNIConnector.java | 2 +- .../java/com/taosdata/jdbc/TSDBSubscribe.java | 3 +-- .../src/test/java/TestAsyncTSDBSubscribe.java | 9 +++++--- .../src/test/java/TestPreparedStatement.java | 11 ++++++---- .../test/java/TestTSDBDatabaseMetaData.java | 22 +++++++++++-------- .../jdbc/src/test/java/TestTSDBSubscribe.java | 3 ++- .../com/taosdata/jdbc/AsyncSubscribeTest.java | 2 +- .../taosdata/jdbc/DatabaseMetaDataTest.java | 9 ++++++++ .../taosdata/jdbc/PreparedStatementTest.java | 4 ++-- .../java/com/taosdata/jdbc/SubscribeTest.java | 10 ++++----- 11 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java index 6cb3263e56..804e09c6b3 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDatabaseMetaData.java @@ -527,8 +527,9 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData { public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) throws SQLException { - if (conn != null && !conn.isClosed()) { - Statement stmt = conn.createStatement(); + Statement stmt = null; + if (null != conn && !conn.isClosed()) { + stmt = conn.createStatement(); if (catalog == null || catalog.length() < 1) { catalog = conn.getCatalog(); } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index 46158210b1..e9acffe0e3 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -19,7 +19,7 @@ import java.sql.SQLWarning; import java.util.List; public class TSDBJNIConnector { - static volatile Boolean isInitialized = false; + private static volatile Boolean isInitialized = false; static { System.loadLibrary("taos"); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java index 3b479aafc3..e20c6a815c 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBSubscribe.java @@ -171,8 +171,7 @@ public class TSDBSubscribe { state = 1; try { - TSDBResultSet resultSet = consume(subscription); - callBack.invoke(resultSet); + callBack.invoke(consume(subscription)); } catch (Exception e) { this.cancel(); throw new RuntimeException(e); diff --git a/src/connector/jdbc/src/test/java/TestAsyncTSDBSubscribe.java b/src/connector/jdbc/src/test/java/TestAsyncTSDBSubscribe.java index 5b2b6367ec..6e7cd19888 100644 --- a/src/connector/jdbc/src/test/java/TestAsyncTSDBSubscribe.java +++ b/src/connector/jdbc/src/test/java/TestAsyncTSDBSubscribe.java @@ -3,10 +3,11 @@ import org.apache.commons.lang3.StringUtils; import java.sql.Connection; import java.sql.DriverManager; +import java.sql.SQLException; import java.util.Properties; public class TestAsyncTSDBSubscribe { - public static void main(String[] args) { + public static void main(String[] args) throws SQLException { String usage = "java -cp taos-jdbcdriver-1.0.3_dev-dist.jar com.taosdata.jdbc.TSDBSubscribe -db dbName -topic topicName " + "-tname tableName -h host"; if (args.length < 2) { @@ -38,7 +39,6 @@ public class TestAsyncTSDBSubscribe { } Connection connection = null; - TSDBSubscribe subscribe = null; long subscribId = 0; try { Class.forName("com.taosdata.jdbc.TSDBDriver"); @@ -46,7 +46,7 @@ public class TestAsyncTSDBSubscribe { properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + dbName + "?user=root&password=taosdata", properties); String rawSql = "select * from " + tName + ";"; - subscribe = ((TSDBConnection) connection).createSubscribe(); + TSDBSubscribe subscribe = ((TSDBConnection) connection).createSubscribe(); subscribId = subscribe.subscribe(topic, rawSql, false, 1000, new CallBack("first")); long subscribId2 = subscribe.subscribe("test", rawSql, false, 1000, new CallBack("second")); int a = 0; @@ -55,6 +55,9 @@ public class TestAsyncTSDBSubscribe { System.err.println("cancel subscribe"); } catch (Exception e) { e.printStackTrace(); + if (null != connection && !connection.isClosed()) { + connection.close(); + } } } diff --git a/src/connector/jdbc/src/test/java/TestPreparedStatement.java b/src/connector/jdbc/src/test/java/TestPreparedStatement.java index aabc34549b..2e387206a4 100644 --- a/src/connector/jdbc/src/test/java/TestPreparedStatement.java +++ b/src/connector/jdbc/src/test/java/TestPreparedStatement.java @@ -6,19 +6,20 @@ import java.util.Properties; public class TestPreparedStatement { - public static void main(String[] args) { + public static void main(String[] args) throws SQLException { + Connection connection = null; try { Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, "localhost"); - Connection connection = DriverManager.getConnection("jdbc:TAOS://localhost:0/?user=root&password=taosdata", properties); + connection = DriverManager.getConnection("jdbc:TAOS://localhost:0/?user=root&password=taosdata", properties); String rawSql = "select * from test.log0601"; // String[] params = new String[]{"ts", "c1"}; PreparedStatement pstmt = (TSDBPreparedStatement) connection.prepareStatement(rawSql); ResultSet resSet = pstmt.executeQuery(); while(resSet.next()) { for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) { - System.out.printf("%d: %s\n", i, resSet.getString(i)); + System.out.printf("%d: %s \n", i, resSet.getString(i)); } } resSet.close(); @@ -27,7 +28,9 @@ public class TestPreparedStatement { } catch (Exception e) { e.printStackTrace(); - + if (null != connection) { + connection.close(); + } } } } diff --git a/src/connector/jdbc/src/test/java/TestTSDBDatabaseMetaData.java b/src/connector/jdbc/src/test/java/TestTSDBDatabaseMetaData.java index 519d7c6ab1..f7e0e78441 100644 --- a/src/connector/jdbc/src/test/java/TestTSDBDatabaseMetaData.java +++ b/src/connector/jdbc/src/test/java/TestTSDBDatabaseMetaData.java @@ -1,29 +1,33 @@ import com.taosdata.jdbc.TSDBDriver; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.DriverManager; -import java.sql.ResultSet; +import java.sql.*; import java.util.Properties; public class TestTSDBDatabaseMetaData { - public static void main(String[] args) { + public static void main(String[] args) throws SQLException { + Connection connection = null; + DatabaseMetaData dbMetaData = null; + ResultSet resSet = null; try { Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, "192.168.1.114"); - Connection connection = DriverManager.getConnection("jdbc:TAOS://192.168.1.114:0/?user=root&password=taosdata", properties); - DatabaseMetaData dbMetaData = connection.getMetaData(); - ResultSet resSet = dbMetaData.getCatalogs(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, "localhost"); + connection = DriverManager.getConnection("jdbc:TAOS://localhost:0/?user=root&password=taosdata", properties); + dbMetaData = connection.getMetaData(); + resSet = dbMetaData.getCatalogs(); while(resSet.next()) { for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) { System.out.printf("dbMetaData.getCatalogs(%d) = %s\n", i, resSet.getString(i)); } } + resSet.close(); } catch (Exception e) { e.printStackTrace(); + if (null != connection) { + connection.close(); + } } } } diff --git a/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java b/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java index f12924c8a6..a30339eb53 100644 --- a/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java +++ b/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java @@ -53,9 +53,10 @@ public class TestTSDBSubscribe { subscribe = ((TSDBConnection) connection).createSubscribe(); subscribId = subscribe.subscribe(topic, rawSql, false, 1000); int a = 0; + TSDBResultSet resSet = null; while (true) { Thread.sleep(900); - TSDBResultSet resSet = subscribe.consume(subscribId); + resSet = subscribe.consume(subscribId); while (resSet.next()) { for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java index a7b6848f1e..b613cd4867 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java @@ -37,7 +37,7 @@ public class AsyncSubscribeTest { statement.executeUpdate("create database if not exists " + dbName); statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); long ts = System.currentTimeMillis(); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 2; i++) { ts += i; statement.executeUpdate("insert into \" + dbName + \".\" + tName + \" values (" + ts + ", " + (100 + i) + ", " + i + ")"); } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java index 2154079e23..064279404b 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -41,6 +42,7 @@ public class DatabaseMetaDataTest { System.out.printf("%d: %s\n", i, resultSet.getString(i)); } } + resultSet.close(); databaseMetaData.isWrapperFor(null); databaseMetaData.allProceduresAreCallable(); databaseMetaData.allTablesAreSelectable(); @@ -228,4 +230,11 @@ public class DatabaseMetaDataTest { databaseMetaData.generatedKeyAlwaysReturned(); } + + @AfterClass + public static void close() throws SQLException { + statement.executeUpdate("drop database " + dbName); + statement.close(); + connection.close(); + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java index dc26f7d9df..36b8731175 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java @@ -55,7 +55,7 @@ public class PreparedStatementTest { @Test public void testPreparedStatement() throws SQLException { - long ts = System.currentTimeMillis(); + long ts = System.currentTimeMillis() + 20000; PreparedStatement saveStatement = connection .prepareStatement("insert into " + dbName + "." + tName + " values (" + ts + ", 1)"); @@ -70,7 +70,7 @@ public class PreparedStatementTest { TSDBPreparedStatement saveStatement = (TSDBPreparedStatement) connection .prepareStatement("insert into " + dbName + "." + tName + " values (?, ?)"); - saveStatement.setObject(1, ts + 100); + saveStatement.setObject(1, ts + 10000); saveStatement.setObject(2, 3); int rows = saveStatement.executeUpdate(); assertEquals(1, rows); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java index 792ae5f671..35999ea59a 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java @@ -20,7 +20,7 @@ public class SubscribeTest { String host = "localhost"; String topic = "test"; -// @Before + @Before public void createDatabase() throws SQLException { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); @@ -36,13 +36,13 @@ public class SubscribeTest { statement.executeUpdate("create database if not exists " + dbName); statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); long ts = System.currentTimeMillis(); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 2; i++) { ts += i; statement.executeUpdate("insert into \" + dbName + \".\" + tName + \" values (" + ts + ", " + (100 + i) + ", " + i + ")"); } } -// @Test + @Test public void subscribe() throws Exception { TSDBSubscribe subscribe = null; long subscribId = 0; @@ -68,7 +68,7 @@ public class SubscribeTest { } resSet.close(); a++; - if (a >= 3) { + if (a >= 2) { break; } } @@ -81,7 +81,7 @@ public class SubscribeTest { } } -// @After + @After public void close() throws Exception { statement.executeQuery("drop database " + dbName); statement.close(); From 367c5a8e7b427c752904cd3b50451b482cc754d8 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Thu, 18 Jun 2020 00:10:23 +0800 Subject: [PATCH 11/29] fix: coverity's bug --- src/client/src/TSDBJNIConnector.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index fec239ef9c..459b180881 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -192,7 +192,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv const char *tz1 = (*env)->GetStringUTFChars(env, optionValue, NULL); if (tz1 && strlen(tz1) != 0) { res = taos_options(TSDB_OPTION_TIMEZONE, tz1); - jniTrace("set timezone to %s, result:%d", timezone, res); + jniTrace("set timezone to %s, result:%d", tz1, res); } else { jniTrace("input timezone is empty"); } @@ -385,7 +385,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getAffectedRowsIm } jint ret = taos_affected_rows((SSqlObj *)res); - jniTrace("jobj:%p, conn:%p, sql:%p, affect rows:%d", jobj, tscon, (void *)con, res, ret); + jniTrace("jobj:%p, conn:%p, sql:%p, res: %p, affect rows:%d", jobj, tscon, (void *)con, (void *)res, ret); return ret; } @@ -411,10 +411,10 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_getSchemaMetaData // jobject arrayListObj = (*env)->NewObject(env, g_arrayListClass, g_arrayListConstructFp, ""); if (num_fields == 0) { - jniError("jobj:%p, conn:%p, resultset:%p, fields size is %d", jobj, tscon, res, num_fields); + jniError("jobj:%p, conn:%p, resultset:%p, fields size is %d", jobj, tscon, (void *)res, num_fields); return JNI_NUM_OF_FIELDS_0; } else { - jniTrace("jobj:%p, conn:%p, resultset:%p, fields size is %d", jobj, tscon, res, num_fields); + jniTrace("jobj:%p, conn:%p, resultset:%p, fields size is %d", jobj, tscon, (void *)res, num_fields); for (int i = 0; i < num_fields; ++i) { jobject metadataObj = (*env)->NewObject(env, g_metadataClass, g_metadataConstructFp); (*env)->SetIntField(env, metadataObj, g_metadataColtypeField, fields[i].type); @@ -465,7 +465,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn int num_fields = taos_num_fields(result); if (num_fields == 0) { - jniError("jobj:%p, conn:%p, resultset:%p, fields size is %d", jobj, tscon, res, num_fields); + jniError("jobj:%p, conn:%p, resultset:%p, fields size is %d", jobj, tscon, (void *)res, num_fields); return JNI_NUM_OF_FIELDS_0; } @@ -473,7 +473,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_fetchRowImp(JNIEn if (row == NULL) { int tserrno = taos_errno(result); if (tserrno == 0) { - jniTrace("jobj:%p, conn:%p, resultset:%p, fields size is %d, fetch row to the end", jobj, tscon, res, num_fields); + jniTrace("jobj:%p, conn:%p, resultset:%p, fields size is %d, fetch row to the end", jobj, tscon, (void *)res, num_fields); return JNI_FETCH_END; } else { jniTrace("jobj:%p, conn:%p, interruptted query", jobj, tscon); From 1980eceabed720dc2cd337c9b85ea1f3d593915c Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 19 Jun 2020 10:30:54 +0800 Subject: [PATCH 12/29] make pytest find so lib automatically [TD-693] --- tests/test-all.sh | 65 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/tests/test-all.sh b/tests/test-all.sh index 0c91229120..90ab0b0bea 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -1,22 +1,5 @@ #!/bin/bash -function runSimCaseOneByOne { - while read -r line; do - if [[ $line =~ ^run.* ]]; then - case=`echo $line | awk '{print $2}'` - ./test.sh -f $case 2>&1 | grep 'success\|failed\|fault' | grep -v 'default' | tee -a out.log - fi - done < $1 -} - -function runPyCaseOneByOne { - while read -r line; do - if [[ $line =~ ^python.* ]]; then - $line 2>&1 | grep 'successfully executed\|failed\|fault' | grep -v 'default'| tee -a pytest-out.log - fi - done < $1 -} - # Color setting RED='\033[0;31m' GREEN='\033[1;32m' @@ -24,10 +7,35 @@ GREEN_DARK='\033[0;32m' GREEN_UNDERLINE='\033[4;32m' NC='\033[0m' +function runSimCaseOneByOne { + while read -r line; do + if [[ $line =~ ^run.* ]]; then + case=`echo $line | awk '{print $NF}'` + ./test.sh -f $case > /dev/null && \ + echo -e "${GREEN}$case success${NC}" || \ + echo -e "${RED}$case failed${NC}" | tee -a out.log + fi + done < $1 +} + +function runPyCaseOneByOne { + while read -r line; do + if [[ $line =~ ^python.* ]]; then + if [[ $line != *sleep* ]]; then + case=`echo $line|awk '{print $NF}'` + $line > /dev/null 2>&1 && \ + echo -e "${GREEN}$case success${NC}" || \ + echo -e "${RED}$case failed${NC}" | tee -a pytest-out.log + else + $line > /dev/null 2>&1 + fi + fi + done < $1 +} + totalFailed=0 totalPyFailed=0 - current_dir=`pwd` if [ "$2" != "python" ]; then @@ -67,6 +75,25 @@ fi if [ "$2" != "sim" ]; then echo "### run Python test case ###" + + IN_TDINTERNAL="community" + + if [[ "$current_dir" == *"$IN_TDINTERNAL"* ]]; then + cd ../.. + else + cd ../ + fi + + TOP_DIR=`pwd` + TAOSLIB_DIR=`find . -name "libtaos.so"|grep -w lib|head -n1` + if [[ "$TAOSLIB_DIR" == *"$IN_TDINTERNAL"* ]]; then + LIB_DIR=`find . -name "libtaos.so"|grep -w lib|head -n1|cut -d '/' --fields=2,3,4,5` + else + LIB_DIR=`find . -name "libtaos.so"|grep -w lib|head -n1|cut -d '/' --fields=2,3,4` + fi + + export LD_LIBRARY_PATH=$TOP_DIR/$LIB_DIR:$LD_LIBRARY_PATH + cd $current_dir/pytest [ -f pytest-out.log ] && rm -f pytest-out.log @@ -81,7 +108,7 @@ if [ "$2" != "sim" ]; then echo "### run Python smoke test ###" runPyCaseOneByOne smoketest.sh fi - totalPySuccess=`grep 'successfully executed' pytest-out.log | wc -l` + totalPySuccess=`grep 'success' pytest-out.log | wc -l` if [ "$totalPySuccess" -gt "0" ]; then echo -e "${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}" From 9c737612d50424037a61d34258eacdd2db113415 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 19 Jun 2020 11:07:10 +0800 Subject: [PATCH 13/29] [td-225] update the error code when system related error happens. --- src/query/inc/qextbuffer.h | 2 +- src/query/src/qextbuffer.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/query/inc/qextbuffer.h b/src/query/inc/qextbuffer.h index 23b67083e5..2cbef2b1be 100644 --- a/src/query/inc/qextbuffer.h +++ b/src/query/inc/qextbuffer.h @@ -149,7 +149,7 @@ int16_t tExtMemBufferPut(tExtMemBuffer *pMemBuffer, void *data, int32_t numOfRow * @param pMemBuffer * @return */ -bool tExtMemBufferFlush(tExtMemBuffer *pMemBuffer); +int32_t tExtMemBufferFlush(tExtMemBuffer *pMemBuffer); /** * diff --git a/src/query/src/qextbuffer.c b/src/query/src/qextbuffer.c index e0a90e0408..35f5e22ed5 100644 --- a/src/query/src/qextbuffer.c +++ b/src/query/src/qextbuffer.c @@ -245,30 +245,29 @@ static void tExtMemBufferClearFlushoutInfo(tExtMemBuffer *pMemBuffer) { memset(pFileMeta->flushoutData.pFlushoutInfo, 0, sizeof(tFlushoutInfo) * pFileMeta->flushoutData.nAllocSize); } -bool tExtMemBufferFlush(tExtMemBuffer *pMemBuffer) { +int32_t tExtMemBufferFlush(tExtMemBuffer *pMemBuffer) { + int32_t ret = 0; if (pMemBuffer->numOfTotalElems == 0) { - return true; + return ret; } if (pMemBuffer->file == NULL) { if ((pMemBuffer->file = fopen(pMemBuffer->path, "wb+")) == NULL) { - return false; + ret = TAOS_SYSTEM_ERROR(errno); + return ret; } } /* all data has been flushed to disk, ignore flush operation */ if (pMemBuffer->numOfElemsInBuffer == 0) { - return true; + return ret; } - bool ret = true; - tFilePagesItem *first = pMemBuffer->pHead; - while (first != NULL) { size_t retVal = fwrite((char *)&(first->item), pMemBuffer->pageSize, 1, pMemBuffer->file); if (retVal <= 0) { // failed to write to buffer, may be not enough space - ret = false; + ret = TAOS_SYSTEM_ERROR(errno); } pMemBuffer->fileMeta.numOfElemsInFile += first->item.num; From 8754b640cd6b85c1b3f88bb13e0f764d419e01b6 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 19 Jun 2020 11:08:22 +0800 Subject: [PATCH 14/29] make sim test output redirect stderr to null too. --- tests/test-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-all.sh b/tests/test-all.sh index 90ab0b0bea..c4988c31c6 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -11,7 +11,7 @@ function runSimCaseOneByOne { while read -r line; do if [[ $line =~ ^run.* ]]; then case=`echo $line | awk '{print $NF}'` - ./test.sh -f $case > /dev/null && \ + ./test.sh -f $case > /dev/null 2>&1 && \ echo -e "${GREEN}$case success${NC}" || \ echo -e "${RED}$case failed${NC}" | tee -a out.log fi From b1a560497ac920b0e62dc2afeac78cdf5974c60f Mon Sep 17 00:00:00 2001 From: Hui Li Date: Fri, 19 Jun 2020 11:31:35 +0800 Subject: [PATCH 15/29] [TD-682] --- src/mnode/inc/mnodeDef.h | 88 ++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index 80a638a21e..937e5d6655 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -29,21 +29,28 @@ struct SAcctObj; struct SUserObj; struct SMnodeObj; +/* +struct define notes: +1. The first field must be the xxxxId field or name field , e.g. 'int32_t dnodeId', 'int32_t mnodeId', 'char name[]', 'char user[]', ... +2. From the dnodeId field to the updataEnd field, these information will be falled disc; +3. The fields behind the updataEnd field are changing; +*/ + typedef struct SDnodeObj { int32_t dnodeId; + int32_t openVnodes; + int64_t createdTime; + int32_t totalVnodes; // from dnode status msg, config information + int32_t customScore; // config by user + uint32_t lastAccess; + uint16_t numOfCores; // from dnode status msg uint16_t dnodePort; char dnodeFqdn[TSDB_FQDN_LEN]; char dnodeEp[TSDB_EP_LEN]; - int64_t createdTime; - uint32_t lastAccess; - int32_t openVnodes; - int32_t totalVnodes; // from dnode status msg, config information - int32_t customScore; // config by user - uint16_t numOfCores; // from dnode status msg int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode int8_t status; // set in balance function int8_t isMgmt; - int8_t reserved[15]; + int8_t reserved0[14]; int8_t updateEnd[1]; int32_t refCount; uint32_t moduleStatus; @@ -54,20 +61,24 @@ typedef struct SDnodeObj { int16_t cpuAvgUsage; // calc from sys.cpu int16_t memoryAvgUsage; // calc from sys.mem int16_t bandwidthUsage; // calc from sys.band + int8_t reserved1[2]; } SDnodeObj; typedef struct SMnodeObj { int32_t mnodeId; + int8_t reserved0[4]; int64_t createdTime; - int8_t reserved[14]; + int8_t reserved1[7]; int8_t updateEnd[1]; int32_t refCount; int8_t role; + int8_t reserved2[3]; } SMnodeObj; typedef struct STableObj { char *tableId; int8_t type; + int8_t reserved[7]; } STableObj; typedef struct SSuperTableObj { @@ -78,29 +89,31 @@ typedef struct SSuperTableObj { int32_t tversion; int32_t numOfColumns; int32_t numOfTags; - int8_t reserved[15]; + int8_t reserved0[15]; int8_t updateEnd[1]; int32_t refCount; int32_t numOfTables; - int16_t nextColId; SSchema * schema; void * vgHash; + int16_t nextColId; + int8_t reserved1[6]; } SSuperTableObj; typedef struct { STableObj info; uint64_t uid; + uint64_t suid; int64_t createdTime; int32_t sversion; //used by normal table int32_t numOfColumns; //used by normal table int32_t sid; int32_t vgId; - uint64_t suid; int32_t sqlLen; - int8_t reserved[1]; + int8_t reserved0[3]; int8_t updateEnd[1]; - int16_t nextColId; //used by normal table int32_t refCount; + int16_t nextColId; //used by normal table + int8_t reserved1[2]; char* sql; //used by normal table SSchema* schema; //used by normal table SSuperTableObj *superTable; @@ -115,23 +128,24 @@ typedef struct { typedef struct SVgObj { uint32_t vgId; - char dbName[TSDB_DB_NAME_LEN]; - int64_t createdTime; - SVnodeGid vnodeGid[TSDB_MAX_REPLICA]; int32_t numOfVnodes; + int64_t createdTime; int32_t lbDnodeId; int32_t lbTime; + char dbName[TSDB_DB_NAME_LEN]; int8_t inUse; int8_t accessState; - int8_t reserved[12]; + int8_t reserved0[5]; + SVnodeGid vnodeGid[TSDB_MAX_REPLICA]; + int8_t reserved1[7]; int8_t updateEnd[1]; int32_t refCount; - struct SVgObj *prev, *next; - struct SDbObj *pDb; int32_t numOfTables; int64_t totalStorage; int64_t compStorage; int64_t pointsWritten; + struct SVgObj *prev, *next; + struct SDbObj *pDb; void * idPool; SChildTableObj **tableList; } SVgObj; @@ -151,17 +165,18 @@ typedef struct { int8_t compression; int8_t walLevel; int8_t replications; - int8_t reserved[16]; + int8_t reserved[12]; } SDbCfg; typedef struct SDbObj { char name[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; + int8_t reserved0[4]; char acct[TSDB_USER_LEN]; int64_t createdTime; int32_t cfgVersion; SDbCfg cfg; int8_t status; - int8_t reserved[14]; + int8_t reserved1[14]; int8_t updateEnd[1]; int32_t refCount; int32_t numOfVgroups; @@ -186,13 +201,6 @@ typedef struct SUserObj { } SUserObj; typedef struct { - int32_t numOfUsers; - int32_t numOfDbs; - int32_t numOfTimeSeries; - int32_t numOfPointsPerSecond; - int32_t numOfConns; - int32_t numOfQueries; - int32_t numOfStreams; int64_t totalStorage; // Total storage wrtten from this account int64_t compStorage; // Compressed storage on disk int64_t queryTime; @@ -200,34 +208,44 @@ typedef struct { int64_t inblound; int64_t outbound; int64_t sKey; + int32_t numOfUsers; + int32_t numOfDbs; + int32_t numOfTimeSeries; + int32_t numOfPointsPerSecond; + int32_t numOfConns; + int32_t numOfQueries; + int32_t numOfStreams; int8_t accessState; // Checked by mgmt heartbeat message + int8_t reserved[3]; } SAcctInfo; typedef struct SAcctObj { char user[TSDB_USER_LEN]; char pass[TSDB_KEY_LEN]; SAcctCfg cfg; - int32_t acctId; int64_t createdTime; + int32_t acctId; int8_t status; - int8_t reserved[14]; + int8_t reserved0[10]; int8_t updateEnd[1]; - int32_t refCount; SAcctInfo acctInfo; + int32_t refCount; + int8_t reserved1[4]; pthread_mutex_t mutex; } SAcctObj; typedef struct { - int8_t type; - int32_t index; char db[TSDB_DB_NAME_LEN]; - void * pIter; + int8_t type; int16_t numOfColumns; + int32_t index; int32_t rowSize; int32_t numOfRows; - int32_t numOfReads; + void * pIter; int16_t offset[TSDB_MAX_COLUMNS]; int16_t bytes[TSDB_MAX_COLUMNS]; + int32_t numOfReads; + int8_t reserved0[2]; uint16_t payloadLen; char payload[]; } SShowObj; From 4674475509c97e6199c47596b6180d7f5f18da30 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 19 Jun 2020 11:32:42 +0800 Subject: [PATCH 16/29] [td-225] update the error code info --- src/client/src/tscLocalMerge.c | 10 +++++----- src/client/src/tscSubquery.c | 11 +++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index f64287bdc4..19395d6af8 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -413,13 +413,13 @@ static int32_t tscFlushTmpBufferImpl(tExtMemBuffer *pMemoryBuf, tOrderDescriptor } int32_t tscFlushTmpBuffer(tExtMemBuffer *pMemoryBuf, tOrderDescriptor *pDesc, tFilePage *pPage, int32_t orderType) { - int32_t ret = tscFlushTmpBufferImpl(pMemoryBuf, pDesc, pPage, orderType); - if (ret != 0) { - return -1; + int32_t ret = 0; + if ((ret = tscFlushTmpBufferImpl(pMemoryBuf, pDesc, pPage, orderType)) != 0) { + return ret; } - if (!tExtMemBufferFlush(pMemoryBuf)) { - return -1; + if ((ret = tExtMemBufferFlush(pMemoryBuf)) != 0) { + return ret; } return 0; diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 42a5d1d09b..425010649c 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1492,7 +1492,7 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES tscError("sub:%p failed to flush data to disk:reason:%s", tres, lpMsgBuf); LocalFree(lpMsgBuf); #else - tscError("sub:%p failed to flush data to disk:reason:%s", tres, strerror(errno)); + tscError("sub:%p failed to flush data to disk, reason:%s", tres, tstrerror(code)); #endif SSqlObj* pParentSql = trsupport->pParentSqlObj; @@ -1630,10 +1630,9 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p // each result for a vnode is ordered as an independant list, // then used as an input of loser tree for disk-based merge routine - int32_t ret = tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, - pQueryInfo->groupbyExpr.orderType); + int32_t ret = tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pQueryInfo->groupbyExpr.orderType); if (ret != 0) { // set no disk space error info, and abort retry - return tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_TSC_NO_DISKSPACE); + return tscAbortFurtherRetryRetrieval(trsupport, pSql, ret); } int32_t remain = -1; @@ -1704,7 +1703,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR tscTrace("%p sub:%p retrieve numOfRows:%" PRId64 " totalNumOfRows:%" PRIu64 " from ip:%s, orderOfSub:%d", pPObj, pSql, pRes->numOfRows, pState->numOfRetrievedRows, pSql->ipList.fqdn[pSql->ipList.inUse], idx); - + if (num > tsMaxNumOfOrderedResults && tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId32 " , current:%" PRId64, pPObj, pSql, tsMaxNumOfOrderedResults, num); @@ -1729,7 +1728,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR int32_t ret = saveToBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pRes->data, pRes->numOfRows, pQueryInfo->groupbyExpr.orderType); - if (ret < 0) { // set no disk space error info, and abort retry + if (ret != 0) { // set no disk space error info, and abort retry tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE); pthread_mutex_unlock(&trsupport->queryMutex); From 29f52213c106fb150abc297fc192a083474e6c0b Mon Sep 17 00:00:00 2001 From: Hui Li Date: Fri, 19 Jun 2020 11:33:49 +0800 Subject: [PATCH 17/29] [TD-682] --- src/mnode/inc/mnodeDef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index 937e5d6655..3d83e18216 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -33,7 +33,7 @@ struct SMnodeObj; struct define notes: 1. The first field must be the xxxxId field or name field , e.g. 'int32_t dnodeId', 'int32_t mnodeId', 'char name[]', 'char user[]', ... 2. From the dnodeId field to the updataEnd field, these information will be falled disc; -3. The fields behind the updataEnd field are changing; +3. The fields behind the updataEnd field can be changed; */ typedef struct SDnodeObj { From 516d9d35d1e0213580ca73dc755c3d0d5ad54ccd Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 19 Jun 2020 11:38:10 +0800 Subject: [PATCH 18/29] [td-225] update the error code info --- src/client/src/tscLocalMerge.c | 10 +++++----- src/client/src/tscSubquery.c | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index 19395d6af8..bc3c33423f 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -440,9 +440,9 @@ int32_t saveToBuffer(tExtMemBuffer *pMemoryBuf, tOrderDescriptor *pDesc, tFilePa // current buffer is full, need to flushed to disk assert(pPage->num == pModel->capacity); - int32_t ret = tscFlushTmpBuffer(pMemoryBuf, pDesc, pPage, orderType); - if (ret != 0) { - return -1; + int32_t code = tscFlushTmpBuffer(pMemoryBuf, pDesc, pPage, orderType); + if (code != 0) { + return code; } int32_t remain = numOfRows - numOfRemainEntries; @@ -458,8 +458,8 @@ int32_t saveToBuffer(tExtMemBuffer *pMemoryBuf, tOrderDescriptor *pDesc, tFilePa tColModelAppend(pModel, pPage, data, numOfRows - remain, numOfWriteElems, numOfRows); if (pPage->num == pModel->capacity) { - if (tscFlushTmpBuffer(pMemoryBuf, pDesc, pPage, orderType) != TSDB_CODE_SUCCESS) { - return -1; + if ((code = tscFlushTmpBuffer(pMemoryBuf, pDesc, pPage, orderType)) != TSDB_CODE_SUCCESS) { + return code; } } else { pPage->num = numOfWriteElems; diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 425010649c..a05be259bc 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1501,7 +1501,6 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; pthread_mutex_unlock(&trsupport->queryMutex); - tscHandleSubqueryError(trsupport, tres, pParentSql->res.code); } @@ -1630,9 +1629,9 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p // each result for a vnode is ordered as an independant list, // then used as an input of loser tree for disk-based merge routine - int32_t ret = tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pQueryInfo->groupbyExpr.orderType); - if (ret != 0) { // set no disk space error info, and abort retry - return tscAbortFurtherRetryRetrieval(trsupport, pSql, ret); + int32_t code = tscFlushTmpBuffer(trsupport->pExtMemBuffer[idx], pDesc, trsupport->localBuffer, pQueryInfo->groupbyExpr.orderType); + if (code != 0) { // set no disk space error info, and abort retry + return tscAbortFurtherRetryRetrieval(trsupport, pSql, code); } int32_t remain = -1; From ce7b4e5dc6ea328b806a5cb272b23eb883602ab4 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Fri, 19 Jun 2020 11:52:32 +0800 Subject: [PATCH 19/29] [TD-682] --- src/mnode/inc/mnodeDef.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index 3d83e18216..a6a31c7641 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -78,18 +78,18 @@ typedef struct SMnodeObj { typedef struct STableObj { char *tableId; int8_t type; - int8_t reserved[7]; } STableObj; typedef struct SSuperTableObj { - STableObj info; + STableObj info; + int8_t reserved0[3]; // for fill struct STableObj to 4byte align + int32_t sversion; uint64_t uid; int64_t createdTime; - int32_t sversion; int32_t tversion; int32_t numOfColumns; int32_t numOfTags; - int8_t reserved0[15]; + int8_t reserved0[3]; int8_t updateEnd[1]; int32_t refCount; int32_t numOfTables; @@ -100,20 +100,20 @@ typedef struct SSuperTableObj { } SSuperTableObj; typedef struct { - STableObj info; + STableObj info; + int8_t reserved0[3]; // for fill struct STableObj to 4byte align + int32_t sversion; //used by normal table uint64_t uid; uint64_t suid; int64_t createdTime; - int32_t sversion; //used by normal table int32_t numOfColumns; //used by normal table int32_t sid; int32_t vgId; int32_t sqlLen; - int8_t reserved0[3]; int8_t updateEnd[1]; - int32_t refCount; + int8_t reserved1[1]; int16_t nextColId; //used by normal table - int8_t reserved1[2]; + int32_t refCount; char* sql; //used by normal table SSchema* schema; //used by normal table SSuperTableObj *superTable; From 93cce2d0fe408660791dd2afd5d387adb0309ceb Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 19 Jun 2020 12:10:39 +0800 Subject: [PATCH 20/29] [td-688] --- src/client/src/tscSubquery.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index a05be259bc..a3e655a971 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1986,6 +1986,7 @@ void tscBuildResFromSubqueries(SSqlObj *pSql) { SColumnIndex* pIndex = &pRes->pColumnIndex[i]; SSqlRes *pRes1 = &pSql->pSubs[pIndex->tableIndex]->res; pRes->tsrow[i] = pRes1->tsrow[pIndex->columnIndex]; + pRes->length[i] = pRes1->length[pIndex->columnIndex]; } pRes->numOfClauseTotal++; From 4855d16dedde4e7ce9a43c09242ae024a091de3a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 19 Jun 2020 12:12:06 +0800 Subject: [PATCH 21/29] [td-225] fix invalid read --- src/client/src/tscSQLParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 788d53e00a..6164c005b9 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2622,7 +2622,7 @@ static int32_t doExtractColumnFilterInfo(SQueryInfo* pQueryInfo, SColumnFilterIn tVariantDump(&pRight->val, (char*)&pColumnFilter->upperBndd, colType, false); } else { // TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd if (colType == TSDB_DATA_TYPE_BINARY) { - pColumnFilter->pz = (int64_t)calloc(1, pRight->val.nLen + 1); + pColumnFilter->pz = (int64_t)calloc(1, pRight->val.nLen + TSDB_NCHAR_SIZE); pColumnFilter->len = pRight->val.nLen; tVariantDump(&pRight->val, (char*)pColumnFilter->pz, colType, false); From bdfe4c6066a016d9e5e2b59e03bb7d0420da01a1 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 19 Jun 2020 12:13:08 +0800 Subject: [PATCH 22/29] [td-225]fix error in global variables. --- src/kit/shell/src/shellEngine.c | 43 +++++++++++++++++++-------------- src/kit/shell/src/shellMain.c | 9 ------- src/kit/taosdump/taosdump.c | 27 ++++++++++++--------- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 7705db4b27..a668524352 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -276,6 +276,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { st = taosGetTimestampUs(); TAOS_RES* pSql = taos_query(con, command); + result = pSql; // set it into the global variable + if (taos_errno(pSql)) { taos_error(pSql); return; @@ -284,7 +286,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { if (regex_match(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) { fprintf(stdout, "Database changed.\n\n"); fflush(stdout); - + + result = NULL; taos_free_result(pSql); return; } @@ -294,6 +297,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { int error_no = 0; int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode); if (numOfRows < 0) { + result = NULL; taos_free_result(pSql); return; } @@ -315,7 +319,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { if (fname != NULL) { wordfree(&full_path); } - + + result = NULL; taos_free_result(pSql); } @@ -419,8 +424,8 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_ } } -static int dumpResultToFile(const char* fname, TAOS_RES* result) { - TAOS_ROW row = taos_fetch_row(result); +static int dumpResultToFile(const char* fname, TAOS_RES* tres) { + TAOS_ROW row = taos_fetch_row(tres); if (row == NULL) { return 0; } @@ -441,9 +446,9 @@ static int dumpResultToFile(const char* fname, TAOS_RES* result) { wordfree(&full_path); - int num_fields = taos_num_fields(result); - TAOS_FIELD *fields = taos_fetch_fields(result); - int precision = taos_result_precision(result); + int num_fields = taos_num_fields(tres); + TAOS_FIELD *fields = taos_fetch_fields(tres); + int precision = taos_result_precision(tres); for (int col = 0; col < num_fields; col++) { if (col > 0) { @@ -455,7 +460,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* result) { int numOfRows = 0; do { - int32_t* length = taos_fetch_lengths(result); + int32_t* length = taos_fetch_lengths(tres); for (int i = 0; i < num_fields; i++) { if (i > 0) { fputc(',', fp); @@ -465,10 +470,13 @@ static int dumpResultToFile(const char* fname, TAOS_RES* result) { fputc('\n', fp); numOfRows++; - row = taos_fetch_row(result); + row = taos_fetch_row(tres); } while( row != NULL); + result = NULL; + taos_free_result(tres); fclose(fp); + return numOfRows; } @@ -769,8 +777,7 @@ void write_history() { void taos_error(TAOS_RES *tres) { fprintf(stderr, "\nDB error: %s\n", taos_errstr(tres)); - - /* free local resouce: allocated memory/metric-meta refcnt */ + result = NULL; taos_free_result(tres); } @@ -845,9 +852,9 @@ void shellGetGrantInfo(void *con) { char sql[] = "show grants"; - result = taos_query(con, sql); + TAOS_RES* tres = taos_query(con, sql); - int code = taos_errno(result); + int code = taos_errno(tres); if (code != TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_COM_OPS_NOT_SUPPORT) { fprintf(stdout, "Server is Community Edition, version is %s\n\n", taos_get_server_info(con)); @@ -857,18 +864,18 @@ void shellGetGrantInfo(void *con) { return; } - int num_fields = taos_field_count(result); + int num_fields = taos_field_count(tres); if (num_fields == 0) { fprintf(stderr, "\nInvalid grant information.\n"); exit(0); } else { - if (result == NULL) { + if (tres == NULL) { fprintf(stderr, "\nGrant information is null.\n"); exit(0); } - TAOS_FIELD *fields = taos_fetch_fields(result); - TAOS_ROW row = taos_fetch_row(result); + TAOS_FIELD *fields = taos_fetch_fields(tres); + TAOS_ROW row = taos_fetch_row(tres); if (row == NULL) { fprintf(stderr, "\nFailed to get grant information from server. Abort.\n"); exit(0); @@ -888,8 +895,8 @@ void shellGetGrantInfo(void *con) { fprintf(stdout, "Server is Enterprise %s Edition, version is %s and will expire at %s.\n", serverVersion, taos_get_server_info(con), expiretime); } - taos_free_result(result); result = NULL; + taos_free_result(tres); } fprintf(stdout, "\n"); diff --git a/src/kit/shell/src/shellMain.c b/src/kit/shell/src/shellMain.c index 92474bdd03..8481f498dd 100644 --- a/src/kit/shell/src/shellMain.c +++ b/src/kit/shell/src/shellMain.c @@ -15,7 +15,6 @@ #include "os.h" #include "shell.h" -#include "tsclient.h" pthread_t pid; @@ -23,14 +22,6 @@ pthread_t pid; void interruptHandler(int signum) { #ifdef LINUX taos_stop_query(result); - if (result != NULL) { - /* - * we need to free result in async model, in order to avoid free - * results while the master thread is waiting for server response. - */ - tscQueueAsyncFreeResult(result); - } - result = NULL; #else printf("\nReceive ctrl+c or other signal, quit shell.\n"); diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index ee792c5116..6ae78f6f73 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -293,7 +293,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { static struct argp argp = {options, parse_opt, args_doc, doc}; TAOS *taos = NULL; -TAOS_RES *result = NULL; char *command = NULL; char *lcommand = NULL; char *buffer = NULL; @@ -463,10 +462,10 @@ int taosDumpOut(SDumpArguments *arguments) { taosDumpCharset(fp); sprintf(command, "show databases"); - result = taos_query(taos, command); + TAOS_RES* result = taos_query(taos, command); int32_t code = taos_errno(result); if (code != 0) { - fprintf(stderr, "failed to run command: %s, reason: %s\n", command, taos_errstr(taos)); + fprintf(stderr, "failed to run command: %s, reason: %s\n", command, taos_errstr(result)); taos_free_result(result); goto _exit_failure; } @@ -613,7 +612,7 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) { fprintf(fp, "USE %s\n\n", dbInfo->name); sprintf(command, "show tables"); - result = taos_query(taos,command); + TAOS_RES* result = taos_query(taos,command); int32_t code = taos_errno(result); if (code != 0) { fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result)); @@ -717,7 +716,7 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols sprintf(command, "select %s from %s limit 1", tableDes->cols[counter].field, tableDes->name); - result = taos_query(taos, command); + TAOS_RES* result = taos_query(taos, command); int32_t code = taos_errno(result); if (code != 0) { fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result)); @@ -795,7 +794,7 @@ int taosGetTableDes(char *table, STableDef *tableDes) { sprintf(command, "describe %s", table); - result = taos_query(taos, command); + TAOS_RES* result = taos_query(taos, command); int32_t code = taos_errno(result); if (code != 0) { fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result)); @@ -875,7 +874,7 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) { tstrncpy(tableRecord.metric, metric, TSDB_TABLE_NAME_LEN); sprintf(command, "select tbname from %s", metric); - result = taos_query(taos, command); + TAOS_RES* result = taos_query(taos, command); int32_t code = taos_errno(result); if (code != 0) { fprintf(stderr, "failed to run command %s, error: %s\n", command, taos_errstr(result)); @@ -928,7 +927,7 @@ int taosDumpTableData(FILE *fp, char *tbname, SDumpArguments *arguments) { sprintf(command, "select * from %s where _c0 >= %" PRId64 " and _c0 <= %" PRId64 " order by _c0 asc", tbname, arguments->start_time, arguments->end_time); - result = taos_query(taos, command); + TAOS_RES* result = taos_query(taos, command); int32_t code = taos_errno(result); if (code != 0) { fprintf(stderr, "failed to run command %s, reason: %s\n", command, taos_errstr(result)); @@ -1177,9 +1176,13 @@ int taosDumpIn(SDumpArguments *arguments) { tcommand = command; } taosReplaceCtrlChar(tcommand); - if (taos_query(taos, tcommand) == NULL) + + TAOS_RES* result = taos_query(taos, tcommand); + if (taos_errno(result) != 0){ fprintf(stderr, "linenu: %" PRId64 " failed to run command %s reason:%s \ncontinue...\n", linenu, command, - taos_errstr(taos)); + taos_errstr(result)); + taos_free_result(result); + } pstr = command; pstr[0] = '\0'; @@ -1225,12 +1228,12 @@ int taosDumpIn(SDumpArguments *arguments) { tcommand = command; } taosReplaceCtrlChar(tcommand); - result = taos_query(taos, tcommand); + TAOS_RES* result = taos_query(taos, tcommand); int32_t code = taos_errno(result); if (code != 0) { fprintf(stderr, "linenu:%" PRId64 " failed to run command %s reason: %s \ncontinue...\n", linenu, command, - taos_errstr(taos)); + taos_errstr(result)); } taos_free_result(result); } From 325261a47377835cce80006afe3cf9106063ccf7 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 19 Jun 2020 12:13:47 +0800 Subject: [PATCH 23/29] [td-225]fix error in global variables. --- src/client/src/tscServer.c | 3 ++- src/client/src/tscSql.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index e15a5e618a..1384dcecff 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -198,6 +198,8 @@ int tscSendMsgToServer(SSqlObj *pSql) { }; pSql->SRpcReqContext = rpcSendRequest(pObj->pDnodeConn, &pSql->ipList, &rpcMsg); + assert(pSql->SRpcReqContext != NULL); + return TSDB_CODE_SUCCESS; } @@ -412,7 +414,6 @@ void tscKillSTableQuery(SSqlObj *pSql) { for (int i = 0; i < pSql->numOfSubs; ++i) { SSqlObj *pSub = pSql->pSubs[i]; - if (pSub == NULL) { continue; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 0be7db435d..6d4337e032 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -607,7 +607,9 @@ int* taos_fetch_lengths(TAOS_RES *res) { char *taos_get_client_info() { return version; } void taos_stop_query(TAOS_RES *res) { - if (res == NULL) return; + if (res == NULL) { + return; + } SSqlObj *pSql = (SSqlObj *)res; SSqlCmd *pCmd = &pSql->cmd; From 9cb883f35933ea8286b2bd7408b8c7bbe98510cb Mon Sep 17 00:00:00 2001 From: Hui Li Date: Fri, 19 Jun 2020 13:28:38 +0800 Subject: [PATCH 24/29] [TD-682j] --- src/mnode/inc/mnodeDef.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index a6a31c7641..67159ecea7 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -89,14 +89,14 @@ typedef struct SSuperTableObj { int32_t tversion; int32_t numOfColumns; int32_t numOfTags; - int8_t reserved0[3]; + int8_t reserved1[3]; int8_t updateEnd[1]; int32_t refCount; int32_t numOfTables; SSchema * schema; void * vgHash; int16_t nextColId; - int8_t reserved1[6]; + int8_t reserved2[6]; } SSuperTableObj; typedef struct { From 4819a63ea8cb949bc4d5057dd498c16fb28553a4 Mon Sep 17 00:00:00 2001 From: Shuaiqiang Chang Date: Fri, 19 Jun 2020 13:54:28 +0800 Subject: [PATCH 25/29] refactor: fix test order --- src/connector/jdbc/.classpath | 49 ++++++++++++++ src/connector/jdbc/.project | 23 +++++++ src/connector/jdbc/pom.xml | 12 ++-- .../src/test/java/TestAsyncTSDBSubscribe.java | 6 +- .../jdbc/src/test/java/TestTSDBSubscribe.java | 5 +- .../com/taosdata/jdbc/AsyncSubscribeTest.java | 4 ++ .../com/taosdata/jdbc/ConnectionTest.java | 6 +- .../taosdata/jdbc/DatabaseMetaDataTest.java | 7 +- .../java/com/taosdata/jdbc/ImportTest.java | 7 +- .../taosdata/jdbc/PreparedStatementTest.java | 15 +++-- .../java/com/taosdata/jdbc/ResultSetTest.java | 9 ++- .../java/com/taosdata/jdbc/SelectTest.java | 7 +- .../java/com/taosdata/jdbc/StableTest.java | 20 ++++-- .../java/com/taosdata/jdbc/StatementTest.java | 15 +++++ .../java/com/taosdata/jdbc/SubscribeTest.java | 4 ++ src/kit/taosnetwork/client.c | 48 ++++++++++++-- src/kit/taosnetwork/server.c | 58 +++++++++++++--- src/kit/taosnetwork/taosnetwork_client.c | 66 ------------------- src/kit/taosnetwork/taosnetwork_server.c | 57 ---------------- src/kit/taosnetwork/test_client.c | 50 -------------- src/kit/taosnetwork/test_server.c | 63 ------------------ 21 files changed, 258 insertions(+), 273 deletions(-) create mode 100644 src/connector/jdbc/.classpath create mode 100644 src/connector/jdbc/.project delete mode 100644 src/kit/taosnetwork/taosnetwork_client.c delete mode 100644 src/kit/taosnetwork/taosnetwork_server.c delete mode 100644 src/kit/taosnetwork/test_client.c delete mode 100644 src/kit/taosnetwork/test_server.c diff --git a/src/connector/jdbc/.classpath b/src/connector/jdbc/.classpath new file mode 100644 index 0000000000..39abf1c5e9 --- /dev/null +++ b/src/connector/jdbc/.classpath @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/connector/jdbc/.project b/src/connector/jdbc/.project new file mode 100644 index 0000000000..656ab58d20 --- /dev/null +++ b/src/connector/jdbc/.project @@ -0,0 +1,23 @@ + + + taos-jdbcdriver + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 456c9e6423..5aa4f6a2e3 100755 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -53,17 +53,17 @@ commons-lang3 ${commons-lang3.version} - - junit - junit - 4.8.2 - test - org.jacoco jacoco-maven-plugin 0.8.3 + + junit + junit + 4.13 + test + diff --git a/src/connector/jdbc/src/test/java/TestAsyncTSDBSubscribe.java b/src/connector/jdbc/src/test/java/TestAsyncTSDBSubscribe.java index 6e7cd19888..55ab2fdc52 100644 --- a/src/connector/jdbc/src/test/java/TestAsyncTSDBSubscribe.java +++ b/src/connector/jdbc/src/test/java/TestAsyncTSDBSubscribe.java @@ -43,7 +43,11 @@ public class TestAsyncTSDBSubscribe { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + dbName + "?user=root&password=taosdata", properties); String rawSql = "select * from " + tName + ";"; TSDBSubscribe subscribe = ((TSDBConnection) connection).createSubscribe(); diff --git a/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java b/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java index a30339eb53..f628f3cada 100644 --- a/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java +++ b/src/connector/jdbc/src/test/java/TestTSDBSubscribe.java @@ -46,7 +46,10 @@ public class TestTSDBSubscribe { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + dbName + "?user=root&password=taosdata" , properties); String rawSql = "select * from " + tName + ";"; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java index b613cd4867..98b0d38b8d 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/AsyncSubscribeTest.java @@ -30,6 +30,9 @@ public class AsyncSubscribeTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" , properties); @@ -91,5 +94,6 @@ public class AsyncSubscribeTest { statement.executeQuery("drop database test"); statement.close(); connection.close(); + Thread.sleep(10); } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java index a932f28113..5e5dabfe81 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ConnectionTest.java @@ -26,6 +26,9 @@ public class ConnectionTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" , properties); @@ -50,8 +53,9 @@ public class ConnectionTest { statement.close(); } connection.close(); + Thread.sleep(10); } - } catch (SQLException e) { + } catch (Exception e) { assert false : "close connection error: " + e.getMessage(); } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java index 064279404b..20ebc093ec 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/DatabaseMetaDataTest.java @@ -23,6 +23,9 @@ public class DatabaseMetaDataTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata", properties); @@ -232,9 +235,11 @@ public class DatabaseMetaDataTest { } @AfterClass - public static void close() throws SQLException { + public static void close() throws Exception { statement.executeUpdate("drop database " + dbName); statement.close(); connection.close(); + Thread.sleep(10); + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ImportTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ImportTest.java index 063046bc74..b42d46aefe 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ImportTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ImportTest.java @@ -25,6 +25,9 @@ public class ImportTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" , properties); @@ -40,7 +43,7 @@ public class ImportTest { long ts = 1496732686000l; for (int i = 0; i < 50; i++) { - ts ++; + 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); @@ -84,5 +87,7 @@ public class ImportTest { statement.executeUpdate("drop database " + dbName); statement.close(); connection.close(); + Thread.sleep(10); + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java index 36b8731175..4c49727a7f 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java @@ -2,15 +2,17 @@ package com.taosdata.jdbc; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; import java.sql.*; -import java.util.ArrayList; import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +@FixMethodOrder(MethodSorters.DEFAULT) public class PreparedStatementTest { static Connection connection = null; static PreparedStatement statement = null; @@ -28,6 +30,9 @@ public class PreparedStatementTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata", properties); @@ -155,11 +160,11 @@ public class PreparedStatementTest { } catch (SQLException e) { } try { - tsdbStatement.executeUpdate(null, new int[] { 0 }); + tsdbStatement.executeUpdate(null, new int[]{0}); } catch (SQLException e) { } try { - tsdbStatement.executeUpdate(null, new String[] { "str1", "str2" }); + tsdbStatement.executeUpdate(null, new String[]{"str1", "str2"}); } catch (SQLException e) { } try { @@ -185,10 +190,12 @@ public class PreparedStatementTest { } @AfterClass - public static void close() throws SQLException { + public static void close() throws Exception { statement.executeUpdate("drop database " + dbName); statement.close(); connection.close(); + Thread.sleep(10); + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java index 9d5f5451f2..2b74a98db2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java @@ -30,6 +30,11 @@ public class ResultSetTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" , properties); @@ -813,10 +818,12 @@ public class ResultSetTest { } @AfterClass - public static void close() throws SQLException { + public static void close() throws Exception { statement.executeUpdate("drop database " + dbName); statement.close(); connection.close(); + Thread.sleep(10); + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java index 077f95318b..282ca6c1a7 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SelectTest.java @@ -25,6 +25,9 @@ public class SelectTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" , properties); @@ -59,9 +62,11 @@ public class SelectTest { } @After - public void close() throws SQLException { + public void close() throws Exception { statement.executeUpdate("drop database " + dbName); statement.close(); connection.close(); + Thread.sleep(10); + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java index b0c5862dec..b275112e18 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java @@ -2,13 +2,16 @@ package com.taosdata.jdbc; import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; import java.sql.*; import java.util.Properties; import static org.junit.Assert.assertEquals; +@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class StableTest { static Connection connection = null; static Statement statement = null; @@ -25,6 +28,9 @@ public class StableTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" , properties); @@ -33,7 +39,7 @@ public class StableTest { statement.executeQuery("use " + dbName); } - @Test +// @Test public void createStable() { String sql = "create table " + stbName + " (ts timestamp, v1 int, v2 int) tags (tg nchar(20)) "; @@ -44,7 +50,7 @@ public class StableTest { } } - @Test +// @Test public void createTable() { String sql = "create table t1 using " + stbName + " tags (\"beijing\")"; @@ -57,6 +63,7 @@ public class StableTest { @Test public void describeSTable() { + createStable(); String sql = "describe " + stbName; int num = 0; System.out.println("describe stable"); @@ -68,6 +75,7 @@ public class StableTest { } num++; } + res.close(); assertEquals(4, num); } catch (SQLException e) { assert false : "error describe stable" + e.getMessage(); @@ -76,6 +84,7 @@ public class StableTest { @Test public void describeTable() { + createTable(); String sql = "describe t1"; int num = 0; System.out.println("describe table"); @@ -87,16 +96,17 @@ public class StableTest { } num++; } + res.close(); assertEquals(4, num); } catch (SQLException e) { assert false : "error describe stable" + e.getMessage(); } } - @Test + // @Test public void validCreateSql() { String sql = "create table t2 using " + stbName + " tags (\"beijing\")"; - boolean valid = ((TSDBConnection)connection).getConnection().validateCreateTableSql(sql); + boolean valid = ((TSDBConnection) connection).getConnection().validateCreateTableSql(sql); assertEquals(true, valid); } @@ -106,6 +116,8 @@ public class StableTest { statement.executeUpdate("drop database " + dbName); statement.close(); connection.close(); + Thread.sleep(10); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java index 5141e87405..4be68519c5 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java @@ -1,5 +1,6 @@ package com.taosdata.jdbc; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -26,6 +27,9 @@ public class StatementTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" , properties); @@ -156,4 +160,15 @@ public class StatementTest { } catch (SQLException e) { } } + + @AfterClass + public static void close() throws Exception { + if (!statement.isClosed()) { + statement.executeUpdate("drop database " + dbName); + statement.close(); + connection.close(); + Thread.sleep(10); + + } + } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java index 35999ea59a..25f7f7a285 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java @@ -29,6 +29,9 @@ public class SubscribeTest { } Properties properties = new Properties(); properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/" + "?user=root&password=taosdata" , properties); @@ -86,5 +89,6 @@ public class SubscribeTest { statement.executeQuery("drop database " + dbName); statement.close(); connection.close(); + Thread.sleep(10); } } \ No newline at end of file diff --git a/src/kit/taosnetwork/client.c b/src/kit/taosnetwork/client.c index 65b866a99b..b2c7f729b5 100644 --- a/src/kit/taosnetwork/client.c +++ b/src/kit/taosnetwork/client.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -34,6 +35,36 @@ typedef struct { char *host[15]; } info; +typedef struct Arguments { + char * host; + uint16_t port; + uint16_t max_port; +} SArguments; + +static struct argp_option options[] = { + {0, 'h', "host", 0, "The host to connect to TDEngine. Default is localhost.", 0}, + {0, 'p', "port", 0, "The TCP or UDP port number to use for the connection. Default is 6020.", 1}, + {0, 'm', "max port", 0, "The max TCP or UDP port number to use for the connection. Default is 6050.", 2}}; + +static error_t parse_opt(int key, char *arg, struct argp_state *state) { + + SArguments *arguments = state->input; + switch (key) { + case 'h': + arguments->host = arg; + break; + case 'p': + arguments->port = atoi(arg); + break; + case 'm': + arguments->max_port = atoi(arg); + break; + } + return 0; +} + +static struct argp argp = {options, parse_opt, 0, 0}; + void *checkPort(void *sarg) { info *pinfo = (info *)sarg; int port = pinfo->port; @@ -97,7 +128,7 @@ void *checkUPort(void *sarg) { sprintf(sendbuf, "send msg port_%d by udp", port); - socklen_t sin_size = sizeof(*(struct sockaddr*)&serverAddr); + socklen_t sin_size = sizeof(*(struct sockaddr *)&serverAddr); sendto(clientSocket, sendbuf, strlen(sendbuf), 0, (struct sockaddr *)&serverAddr, (int)sin_size); @@ -113,14 +144,19 @@ void *checkUPort(void *sarg) { return NULL; } -int main() { - int port = 6020; - char *host = "127.0.0.1"; +int main(int argc, char *argv[]) { + SArguments arguments = {"127.0.0.1", 6020, 6050}; + + argp_parse(&argp, argc, argv, 0, 0, &arguments); + + printf("host: %s\tport: %d\tmax_port: %d\n", arguments.host, arguments.port, arguments.max_port); + + int port = arguments.port; + char *host = arguments.host; info *tinfo = malloc(sizeof(info)); info *uinfo = malloc(sizeof(info)); - for (size_t i = 0; i < 30; i++) { - port++; + for (; port < arguments.max_port; port++) { printf("For test: %s:%d\n", host, port); *tinfo->host = host; diff --git a/src/kit/taosnetwork/server.c b/src/kit/taosnetwork/server.c index 7dcc9cbeda..c967828f0b 100644 --- a/src/kit/taosnetwork/server.c +++ b/src/kit/taosnetwork/server.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -34,6 +35,36 @@ typedef struct { int type; // 0: tcp, 1: udo, default: 0 } info; +typedef struct Arguments { + char * host; + uint16_t port; + uint16_t max_port; +} SArguments; + +static struct argp_option options[] = { + {0, 'h', "host", 0, "The host to connect to TDEngine. Default is localhost.", 0}, + {0, 'p', "port", 0, "The TCP or UDP port number to use for the connection. Default is 6020.", 1}, + {0, 'm', "max port", 0, "The max TCP or UDP port number to use for the connection. Default is 6050.", 2}}; + +static error_t parse_opt(int key, char *arg, struct argp_state *state) { + + SArguments *arguments = state->input; + switch (key) { + case 'h': + arguments->host = arg; + break; + case 'p': + arguments->port = atoi(arg); + break; + case 'm': + arguments->max_port = atoi(arg); + break; + } + return 0; +} + +static struct argp argp = {options, parse_opt, 0, 0}; + static void *bindPort(void *sarg) { info *pinfo = (info *)sarg; int port = pinfo->port; @@ -170,15 +201,21 @@ static void *bindUPort(void *sarg) { } -int main() { - int port = 6020; - pthread_t *pids = malloc(60 * sizeof(pthread_t)); - info * infos = malloc(30 * sizeof(info)); - info * uinfos = malloc(30 * sizeof(info)); +int main(int argc, char *argv[]) { + SArguments arguments = {"127.0.0.1", 6020, 6050}; + argp_parse(&argp, argc, argv, 0, 0, &arguments); + int port = arguments.port; - for (size_t i = 0; i < 30; i++) { - port++; + int num = arguments.max_port - arguments.port; + if (num < 0) { + num = 1; + } + pthread_t *pids = malloc(2 * num * sizeof(pthread_t)); + info * infos = malloc(num * sizeof(info)); + info * uinfos = malloc(num * sizeof(info)); + + for (size_t i = 0; i < num; i++) { info *pinfo = infos++; pinfo->port = port; @@ -191,14 +228,15 @@ int main() { info *uinfo = uinfos++; uinfo->port = port; uinfo->type = 1; - if (pthread_create(pids + 30 + i, NULL, bindUPort, uinfo) != 0) //创建线程 + port++; + if (pthread_create(pids + num + i, NULL, bindUPort, uinfo) != 0) //创建线程 { //创建线程失败 printf("创建线程失败: %d.\n", port); exit(0); } } - for (int i = 0; i < 30; i++) { + for (int i = 0; i < num; i++) { pthread_join(pids[i], NULL); - pthread_join(pids[(10 + i)], NULL); + pthread_join(pids[(num + i)], NULL); } } diff --git a/src/kit/taosnetwork/taosnetwork_client.c b/src/kit/taosnetwork/taosnetwork_client.c deleted file mode 100644 index 072610a035..0000000000 --- a/src/kit/taosnetwork/taosnetwork_client.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#define SERVER_PORT 8000 -#define SIZE 200 - -int main() { - struct sockaddr_in servaddr, cliaddr; - socklen_t cliaddr_len; - int client_sockfd; - char buf[SIZE]; - char recvbuf[SIZE]; - - int i, n, flag = 0; - - int len, iDataNum; - - client_sockfd = socket(AF_INET, SOCK_STREAM, 0); - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(SERVER_PORT); - - if (connect(client_sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { - printf("Connected error..\n"); - return 0; - } - printf("Connected to server..\n"); - - /*循环的发送接收信息并打印接收信息(可以按需发送)--recv返回接收到的字节数,send返回发送的字节数*/ - while (1) { - printf("Enter string to send:"); - scanf("%s", buf); - if (!strcmp(buf, "quit")) { - break; - } - len = (sizeof buf); - - recvbuf[0] = '\0'; - - iDataNum = recv(client_sockfd, recvbuf, SIZE, 0); - - recvbuf[iDataNum] = '\0'; - - printf("%s\n", recvbuf); - } - return 0; -} diff --git a/src/kit/taosnetwork/taosnetwork_server.c b/src/kit/taosnetwork/taosnetwork_server.c deleted file mode 100644 index 1ec20716fa..0000000000 --- a/src/kit/taosnetwork/taosnetwork_server.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#define SERVER_PORT 8000 -#define SIZE 200 - -int main() { - struct sockaddr_in servaddr, cliaddr; - socklen_t cliaddr_len; - int listenfd, connfd; - char buf[BUFSIZ]; - int i, n, flag = 0; - - listenfd = socket(AF_INET, SOCK_STREAM, 0); - bzero(&servaddr, sizeof(servaddr)); - servaddr.sin_family = AF_INET; - servaddr.sin_addr.s_addr = htonl(INADDR_ANY); - servaddr.sin_port = htons(SERVER_PORT); - bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); - listen(listenfd, 20); - - printf("Accepting connections..\n"); - while (1) { - cliaddr_len = sizeof(cliaddr); - connfd = accept(listenfd, (struct sockaddr *)&cliaddr, - &cliaddr_len); //如果得不到客户端发来的消息,将会被阻塞,一直等到消息到来 - n = read(connfd, buf, SIZE); //如果n<=0,表示客户端已断开 - while (1) { - if (n != 0) { - for (i = 0; i < n; i++) printf("%c", buf[i]); //输出客户端发来的信息 - } else { - printf("Client say close the connection..\n"); - break; - } - n = read(connfd, buf, SIZE); - } - close(connfd); - } -} diff --git a/src/kit/taosnetwork/test_client.c b/src/kit/taosnetwork/test_client.c deleted file mode 100644 index 0c863c6a99..0000000000 --- a/src/kit/taosnetwork/test_client.c +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include -#include -#include - -#define SERVER_PORT 8888 -#define BUFF_LEN 512 -#define SERVER_IP "172.0.5.182" - -void udp_msg_sender(int fd, struct sockaddr* dst) {} - -/* - client: - socket-->sendto-->revcfrom-->close -*/ - -int main(int argc, char* argv[]) { - int client_fd; - struct sockaddr_in ser_addr; - - client_fd = socket(AF_INET, SOCK_DGRAM, 0); - if (client_fd < 0) { - printf("create socket fail!\n"); - return -1; - } - - memset(&ser_addr, 0, sizeof(ser_addr)); - ser_addr.sin_family = AF_INET; - // ser_addr.sin_addr.s_addr = inet_addr(SERVER_IP); - ser_addr.sin_addr.s_addr = htonl(INADDR_ANY); //注意网络序转换 - ser_addr.sin_port = htons(SERVER_PORT); //注意网络序转换 - - socklen_t len; - struct sockaddr_in src; - while (1) { - char buf[BUFF_LEN] = "TEST UDP MSG!\n"; - len = sizeof(*(struct sockaddr*)&ser_addr); - printf("client:%s\n", buf); //打印自己发送的信息 - sendto(client_fd, buf, BUFF_LEN, 0, (struct sockaddr*)&ser_addr, len); - memset(buf, 0, BUFF_LEN); - recvfrom(client_fd, buf, BUFF_LEN, 0, (struct sockaddr*)&src, &len); //接收来自server的信息 - printf("server:%s\n", buf); - sleep(1); //一秒发送一次消息 - } - - close(client_fd); - - return 0; -} \ No newline at end of file diff --git a/src/kit/taosnetwork/test_server.c b/src/kit/taosnetwork/test_server.c deleted file mode 100644 index 3bfbaa4f7c..0000000000 --- a/src/kit/taosnetwork/test_server.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include - -#define SERVER_PORT 8888 -#define BUFF_LEN 1024 - -void handle_udp_msg(int fd) { - char buf[BUFF_LEN]; //接收缓冲区,1024字节 - socklen_t len; - int count; - struct sockaddr_in clent_addr; // clent_addr用于记录发送方的地址信息 - while (1) { - memset(buf, 0, BUFF_LEN); - len = sizeof(clent_addr); - count = - recvfrom(fd, buf, BUFF_LEN, 0, (struct sockaddr*)&clent_addr, &len); // recvfrom是拥塞函数,没有数据就一直拥塞 - if (count == -1) { - printf("recieve data fail!\n"); - return; - } - printf("client:%s\n", buf); //打印client发过来的信息 - memset(buf, 0, BUFF_LEN); - sprintf(buf, "I have recieved %d bytes data!\n", count); //回复client - printf("server:%s\n", buf); //打印自己发送的信息给 - sendto(fd, buf, BUFF_LEN, 0, (struct sockaddr*)&clent_addr, - len); //发送信息给client,注意使用了clent_addr结构体指针 - } -} - -/* - server: - socket-->bind-->recvfrom-->sendto-->close -*/ - -int main(int argc, char* argv[]) { - int server_fd, ret; - struct sockaddr_in ser_addr; - - server_fd = socket(AF_INET, SOCK_DGRAM, 0); // AF_INET:IPV4;SOCK_DGRAM:UDP - if (server_fd < 0) { - printf("create socket fail!\n"); - return -1; - } - - memset(&ser_addr, 0, sizeof(ser_addr)); - ser_addr.sin_family = AF_INET; - ser_addr.sin_addr.s_addr = htonl(INADDR_ANY); // IP地址,需要进行网络序转换,INADDR_ANY:本地地址 - ser_addr.sin_port = htons(SERVER_PORT); //端口号,需要网络序转换 - - ret = bind(server_fd, (struct sockaddr*)&ser_addr, sizeof(ser_addr)); - if (ret < 0) { - printf("socket bind fail!\n"); - return -1; - } - - handle_udp_msg(server_fd); //处理接收到的数据 - - close(server_fd); - return 0; -} \ No newline at end of file From 63503e91fdcbdc29023906b712f253c7436aadaf Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Fri, 19 Jun 2020 14:04:44 +0800 Subject: [PATCH 26/29] add spend time statistics. --- tests/test-all.sh | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/tests/test-all.sh b/tests/test-all.sh index c4988c31c6..275c6b1677 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -11,9 +11,12 @@ function runSimCaseOneByOne { while read -r line; do if [[ $line =~ ^run.* ]]; then case=`echo $line | awk '{print $NF}'` + start_time=`date +%s` ./test.sh -f $case > /dev/null 2>&1 && \ - echo -e "${GREEN}$case success${NC}" || \ + echo -e "${GREEN}$case success${NC}" | tee -a out.log || \ echo -e "${RED}$case failed${NC}" | tee -a out.log + end_time=`date +%s` + echo execution time of $case was `expr $end_time - $start_time`s. | tee -a out.log fi done < $1 } @@ -23,9 +26,12 @@ function runPyCaseOneByOne { if [[ $line =~ ^python.* ]]; then if [[ $line != *sleep* ]]; then case=`echo $line|awk '{print $NF}'` + start_time=`date +%s` $line > /dev/null 2>&1 && \ - echo -e "${GREEN}$case success${NC}" || \ + echo -e "${GREEN}$case success${NC}" | tee -a pytest-out.log || \ echo -e "${RED}$case failed${NC}" | tee -a pytest-out.log + end_time=`date +%s` + echo execution time of $case was `expr $end_time - $start_time`s. | tee -a pytest-out.log else $line > /dev/null 2>&1 fi @@ -36,11 +42,11 @@ function runPyCaseOneByOne { totalFailed=0 totalPyFailed=0 -current_dir=`pwd` +tests_dir=`pwd` if [ "$2" != "python" ]; then echo "### run TSIM test case ###" - cd $current_dir/script + cd $tests_dir/script [ -f out.log ] && rm -f out.log if [ "$1" == "cron" ]; then @@ -61,13 +67,13 @@ if [ "$2" != "python" ]; then totalSuccess=`expr $totalSuccess - $totalBasic` fi - echo -e "${GREEN} ### Total $totalSuccess TSIM case(s) succeed! ### ${NC}" + echo -e "\n${GREEN} ### Total $totalSuccess TSIM case(s) succeed! ### ${NC}" totalFailed=`grep 'failed\|fault' out.log | wc -l` # echo -e "${RED} ### Total $totalFailed TSIM case(s) failed! ### ${NC}" if [ "$totalFailed" -ne "0" ]; then - echo -e "${RED} ### Total $totalFailed TSIM case(s) failed! ### ${NC}" + echo -e "\n${RED} ### Total $totalFailed TSIM case(s) failed! ### ${NC}" # exit $totalFailed fi @@ -76,9 +82,10 @@ fi if [ "$2" != "sim" ]; then echo "### run Python test case ###" + cd $tests_dir IN_TDINTERNAL="community" - if [[ "$current_dir" == *"$IN_TDINTERNAL"* ]]; then + if [[ "$tests_dir" == *"$IN_TDINTERNAL"* ]]; then cd ../.. else cd ../ @@ -94,7 +101,7 @@ if [ "$2" != "sim" ]; then export LD_LIBRARY_PATH=$TOP_DIR/$LIB_DIR:$LD_LIBRARY_PATH - cd $current_dir/pytest + cd $tests_dir/pytest [ -f pytest-out.log ] && rm -f pytest-out.log @@ -111,12 +118,12 @@ if [ "$2" != "sim" ]; then totalPySuccess=`grep 'success' pytest-out.log | wc -l` if [ "$totalPySuccess" -gt "0" ]; then - echo -e "${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}" + echo -e "\n${GREEN} ### Total $totalPySuccess python case(s) succeed! ### ${NC}" fi totalPyFailed=`grep 'failed\|fault' pytest-out.log | wc -l` if [ "$totalPyFailed" -ne "0" ]; then - echo -e "${RED} ### Total $totalPyFailed python case(s) failed! ### ${NC}" + echo -e "\n${RED} ### Total $totalPyFailed python case(s) failed! ### ${NC}" # exit $totalPyFailed fi fi From 56f172b5170e5ca8df9e729a26fce0a358734f62 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Fri, 19 Jun 2020 14:30:29 +0800 Subject: [PATCH 27/29] modify cfg paramert according on confluence. --- packaging/cfg/taos.cfg | 219 +++++++++++++++++++++-------------------- 1 file changed, 112 insertions(+), 107 deletions(-) diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index 45fc6459e9..40b4c43fdd 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -6,10 +6,22 @@ ######################################################## # first full-qualified domain name (FQDN) for TDengine system -# first 127.0.0.1 +# first hostname1:6030 # second full-qualified domain name (FQDN) for TDengine system, for cluster edition only -# second 127.0.0.1 +# second cluster_hostname2:6030 + +# the arbitrator's full-qualified domain name (FQDN) for TDengine system, for cluster edition only +# arbitrator arbitrator_hostname:6030 + +# the full-qualified domain name (FQDN) of dnode +# fqdn hostname:6030 + +# port for MNode connect to Client, default udp[6030-6055] tcp[6030] +# serverPort 6030 + +# http service port, default tcp[6020] +# httpPort 6020 # set socket type ("udp" and "tcp") # the server and client should have the same socket type. Otherwise, connect will fail @@ -30,51 +42,29 @@ # log file's directory # logDir /var/log/taos -# http service port, default tcp[6020] -# httpPort 6020 +# number of management nodes in the system +# numOfMnodes 3 -# port for MNode connect to Client, default udp[6030-6055] tcp[6030] -# serverPort 6030 +# optional roles for dnode. 0 - any, 1 - mnode, 2 - dnode +# alternativeRole 0 # number of threads per CPU core -# numOfThreadsPerCore 1 +# numOfThreadsPerCore 1.0 # number of vnodes per core in DNode # numOfVnodesPerCore 8 +# the ratio of threads responsible for querying in the total thread +# ratioOfQueryThreads 0.5 + # number of total vnodes in DNode # numOfTotalVnodes 0 # max number of tables per vnode # maxtablesPerVnode 1000 -# cache block size -# cache 16384 - -# row of records in file block -# minRows 100 -# maxRows 4096 - -# number of cache blocks per vnode -# blocks 2 - -# interval of system monitor -# monitorInterval 60 - -# the compressed rpc message, option: -# -1 (no compression) -# 0 (all message compressed), -# > 0 (rpc message body which larger than this value will be compressed) -# compressMsgSize -1 - -# RPC re-try timer, millisecond -# rpcTimer 300 - -# RPC maximum time for ack, seconds -# rpcMaxTime 600 - -# commit interval,unit is second -# ctime 3600 +# interval of check load balance when the management node is in normal operation +# balanceInterval 300 # interval of DNode report status to MNode, unit is Second, for cluster version only # statusInterval 1 @@ -82,29 +72,29 @@ # interval of Shell send HB to MNode, unit is Second # shellActivityTimer 3 -# interval of DNode send HB to DNode, unit is Second, for cluster version only -# vnodePeerHBTimer 1 +# interval of system monitor +# monitorInterval 30 -# interval of MNode send HB to MNode, unit is Second, for cluster version only -# mgmtPeerHBTimer 1 +# RPC re-try timer, millisecond +# rpcTimer 300 + +# RPC maximum time for ack, seconds +# rpcMaxTime 600 # duration of to keep tableMeta kept in Cache, seconds # tableMetaKeepTimer 7200 -# max number of users -# maxUsers 1000 +# Minimum sliding window time +# minSlidingTime 10 -# max number of databases -# maxDbs 1000 +# Time window minimum +# minIntervalTime 10 -# max number of tables -# maxTables 650000 +# max length of an SQL +# maxSQLLength 65380 -# max number of Dnodes, for cluster version only -# maxDnodes 1000 - -# Max number of VGroups, for cluster version only -# maxVGroups 1000 +# Support the maximum number of records allowed for super table time sorting +# maxNumOfOrderedRes 100000 # system locale # locale en_US.UTF-8 @@ -121,6 +111,24 @@ # enable/disable async log # asyncLog 1 +# the compressed rpc message, option: +# -1 (no compression) +# 0 (all message compressed), +# > 0 (rpc message body which larger than this value will be compressed) +# compressMsgSize -1 + +# cache block size (Mbyte) +# cache 16 + +# number of cache blocks per vnode +# blocks 4 + +# min row of records in file block +# minRows 100 + +# max row of records in file block +# maxRows 4096 + # enable/disable compression # comp 1 @@ -131,31 +139,25 @@ # keep 3650 # number of replications, for cluster version only -# replications 1 +# replica 1 -# client default database(database should be created) -# defaultDB +# max number of connections from client for dnode +# maxShellConns 5000 -# client default username -# defaultUser root +# max numerber of connections to one database +# maxConnections 5000 -# client default password -# defaultPass taosdata +# Stop writing logs when the disk size of the log folder is less than this value +# minimalLogDirGB 0.1 -# max number of connections from client for mgmt node -# maxShellConns 2000 +# Stop writing temporary files when the disk size of the log folder is less than this value +# minimalTmpDirGB 0.1 -# max numerber of meter Connections -# maxMeterConnections 10000 - -# max connection to management node -# maxMgmtConnections 2000 - -# max connection to Vnode -# maxVnodeConnections 10000 +# Stop writing data when the disk size of the log folder is less than this value +# minimalDataDirGB 0.1 # mnode take into account while balance, for cluster version only -# mnodeEqualVnodeNum 4 +# mnodeEqualVnodeNum 4 # number of seconds allowed for a dnode to be offline, for cluster version only # offlineThreshold 864000 @@ -170,10 +172,10 @@ # mqtt 0 # mqtt uri -# mqttBrokerAddress mqtt://username:password@hostname:1883/taos/ +# mqttBrokerAddress mqtt://username:password@hostname:1883/taos/ # mqtt client name -# mqttBrokerClientId taos_mqtt +# mqttBrokerClientId taos_mqtt # maximum number of rows returned by the restful interface # restfulRowLimit 10240 @@ -181,41 +183,17 @@ # number of threads used to process http requests # httpMaxThreads 2 -# pre-allocated number of http sessions -# httpCacheSessions 100 +# The minimum time to wait before the first stream execution +# maxFirstStreamCompDelay 10000 -# whether to enable HTTP compression transmission -# httpEnableCompress 0 +# Retry wait time benchmark +# retryStreamCompDelay 10 # the delayed time for launching each continuous query. 10% of the whole computing time window by default. # streamCompDelayRatio 0.1 # the max allowed delayed time for launching continuous query. 20ms by default -# tsMaxStreamComputDelay 20000 - -# whether the telegraf table name contains the number of tags and the number of fields -# telegrafUseFieldNum 0 - -# enable table names generated by telegraf can be configured -# use /etc/taos/taos.telegraf.cfg as the configuration file, such as -# { -# "metrics": [ -# { -# "name" : "system", -# "tbname" : "system_uptime", -# "fields": [ -# "uptime" -# ] -# }, -# { -# "name": "system", -# "tbname" : "system_uptime_format", -# "fields": [ -# "uptime_format" -# ] -# } -# ] -# } +# maxStreamCompDelay 20000 # The following parameter is used to limit the maximum number of lines in log files. # max number of rows per log filters @@ -226,35 +204,62 @@ # 131: output warning and error,135: output info, warning and error to log. # 199: output debug, info, warning and error to both screen and file +# debug flag for basic utils +# debugFlag 131 + # debug flag for meta management messages # mDebugFlag 135 # debug flag for dnode messages # dDebugFlag 131 +# debug flag for TDengine SDB +# sDebugFlag 135 + # debug flag for TDengine SDB # sdbDebugFlag 135 # debug flag for RPC # rpcDebugFlag 131 -# debug flag for basic utils -# debugFlag 131 +# debug flag for TAOS TIMER +# tmrDebugFlag 131 # debug flag for TDengine client # cDebugFlag 131 +# debug flag for JNI +# jniDebugflag 131 + +# debug flag for ODBC +# odbcDebugflag 131 + +# debug flag for storage +# uDebugflag 131 + +# debug flag for http server +# httpDebugFlag 131 + +# debug flag for mqtt +# mqttDebugFlag 131 + +# debug flag for monitor +# monitorDebugFlag 131 + # debug flag for query # qDebugflag 131 # debug flag for http server -# httpDebugFlag 131 +# tsdbDebugFlag 131 -# debug flag for system monitor -# monitorDebugFlag 131 +# Record the SQL through restful interface +# httpEnableRecordSql 0 -#debug flag for mqtt client -# mqttDebugFlag 131 +# Record the SQL in taos client +# tscEnableRecordSql 0 -# debug flag for TAOS TIMER -# tmrDebugFlag 131 +# if generate core file when service crash +# enableCoreFile 1 + +# The maximum display width of binary and nchar fields in the shell. The parts exceeding this limit will be hidden +# maxBinaryDisplayWidth 30 \ No newline at end of file From eb9bfffa677e781decd00747266e5fce0d6099f4 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 19 Jun 2020 06:39:49 +0000 Subject: [PATCH 28/29] fix coverity error --- src/client/src/TSDBJNIConnector.c | 6 ++---- src/client/src/tscSql.c | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index 1a4ad8f050..4ee916c184 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -228,11 +228,9 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_connectImp(JNIEn if (user == NULL) { jniTrace("jobj:%p, user is null, use default user %s", jobj, TSDB_DEFAULT_USER); - user = TSDB_DEFAULT_USER; } if (pass == NULL) { jniTrace("jobj:%p, pass is null, use default password", jobj); - pass = TSDB_DEFAULT_PASS; } /* @@ -252,8 +250,8 @@ JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_connectImp(JNIEn if (host != NULL) (*env)->ReleaseStringUTFChars(env, jhost, host); if (dbname != NULL) (*env)->ReleaseStringUTFChars(env, jdbName, dbname); - if (user != NULL && user != (const char *)TSDB_DEFAULT_USER) (*env)->ReleaseStringUTFChars(env, juser, user); - if (pass != NULL && pass != (const char *)TSDB_DEFAULT_PASS) (*env)->ReleaseStringUTFChars(env, jpass, pass); + if (user != NULL) (*env)->ReleaseStringUTFChars(env, juser, user); + if (pass != NULL) (*env)->ReleaseStringUTFChars(env, jpass, pass); return ret; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 6d4337e032..0fa841bc7c 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -147,6 +147,8 @@ static void syncConnCallback(void *param, TAOS_RES *tres, int code) { TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { tscTrace("try to create a connection to %s:%u, user:%s db:%s", ip, port, user, db); + if (user == NULL) user = TSDB_DEFAULT_USER; + if (pass == NULL) pass = TSDB_DEFAULT_PASS; STscObj* pObj = NULL; SSqlObj *pSql = taosConnectImpl(ip, user, pass, db, port, syncConnCallback, NULL, (void**) &pObj); From f26403d1219ebd87f3dc5b95415b49e966074278 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 19 Jun 2020 14:44:08 +0800 Subject: [PATCH 29/29] wrong thread print in log file --- src/client/src/tscServer.c | 2 -- src/util/src/tlog.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 1384dcecff..6e3602b69d 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -198,8 +198,6 @@ int tscSendMsgToServer(SSqlObj *pSql) { }; pSql->SRpcReqContext = rpcSendRequest(pObj->pDnodeConn, &pSql->ipList, &rpcMsg); - assert(pSql->SRpcReqContext != NULL); - return TSDB_CODE_SUCCESS; } diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index f5129c96c0..c4597d86ed 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -327,7 +327,7 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { curTime = timeSecs.tv_sec; ptm = localtime_r(&curTime, &Tm); - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, + len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%" PRIx64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetPthreadId()); len += sprintf(buffer + len, "%s", flags); @@ -414,7 +414,7 @@ void taosPrintLongString(const char *flags, int32_t dflag, const char *format, . curTime = timeSecs.tv_sec; ptm = localtime_r(&curTime, &Tm); - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, + len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%" PRIx64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetPthreadId()); len += sprintf(buffer + len, "%s", flags);