From b4f5b15df91324cf89e8a4f466c8579bef319147 Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Mon, 13 Jan 2025 15:51:15 +0800 Subject: [PATCH 1/8] fix other async create database case --- source/client/test/clientTests.cpp | 12 ++++++++++++ source/client/test/connectOptionsTest.cpp | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 60f0a72e39..54c0e59817 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -532,6 +532,10 @@ TEST(clientCase, create_stable_Test) { taos_free_result(pRes); pRes = taos_query(pConn, "use abc1"); + while (taos_errno(pRes) == TSDB_CODE_MND_DB_IN_CREATING || taos_errno(pRes) == TSDB_CODE_MND_DB_IN_DROPPING) { + taosMsleep(2000); + pRes = taos_query(pConn, "use abc1"); + } taos_free_result(pRes); pRes = taos_query(pConn, "create table if not exists abc1.st1(ts timestamp, k int) tags(a int)"); @@ -664,6 +668,10 @@ TEST(clientCase, create_multiple_tables) { taos_free_result(pRes); pRes = taos_query(pConn, "use abc1"); + while (taos_errno(pRes) == TSDB_CODE_MND_DB_IN_CREATING || taos_errno(pRes) == TSDB_CODE_MND_DB_IN_DROPPING) { + taosMsleep(2000); + pRes = taos_query(pConn, "use abc1"); + } if (taos_errno(pRes) != 0) { (void)printf("failed to use db, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); @@ -1524,6 +1532,10 @@ TEST(clientCase, timezone_Test) { taos_free_result(pRes); pRes = taos_query(pConn, "create table db1.t1 (ts timestamp, v int)"); + while (taos_errno(pRes) == TSDB_CODE_MND_DB_IN_CREATING || taos_errno(pRes) == TSDB_CODE_MND_DB_IN_DROPPING) { + taosMsleep(2000); + pRes = taos_query(pConn, "create table db1.t1 (ts timestamp, v int)"); + } ASSERT_EQ(taos_errno(pRes), TSDB_CODE_SUCCESS); taos_free_result(pRes); diff --git a/source/client/test/connectOptionsTest.cpp b/source/client/test/connectOptionsTest.cpp index 95596e9ed3..4f0dbb579b 100644 --- a/source/client/test/connectOptionsTest.cpp +++ b/source/client/test/connectOptionsTest.cpp @@ -55,7 +55,13 @@ TAOS* getConnWithOption(const char *tz){ void execQuery(TAOS* pConn, const char *sql){ TAOS_RES* pRes = taos_query(pConn, sql); - ASSERT(taos_errno(pRes) == TSDB_CODE_SUCCESS); + int code = taos_errno(pRes); + while (code == TSDB_CODE_MND_DB_IN_CREATING || code == TSDB_CODE_MND_DB_IN_DROPPING) { + taosMsleep(2000); + TAOS_RES* pRes = taos_query(pConn, sql); + code = taos_errno(pRes); + } + ASSERT(code == TSDB_CODE_SUCCESS); taos_free_result(pRes); } From 857ce783abb5e66bfb883b39439bf7e661302519 Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Mon, 13 Jan 2025 10:31:46 +0800 Subject: [PATCH 2/8] fix stmt/stmt2 unit test --- source/client/test/stmt2Test.cpp | 298 ++++++++++++++++++------------- source/client/test/stmtTest.cpp | 72 +++++--- 2 files changed, 213 insertions(+), 157 deletions(-) diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp index 1ce844e98f..3e21721c47 100644 --- a/source/client/test/stmt2Test.cpp +++ b/source/client/test/stmt2Test.cpp @@ -112,6 +112,11 @@ void do_query(TAOS* taos, const char* sql) { TAOS_RES* result = taos_query(taos, sql); // printf("sql: %s\n", sql); int code = taos_errno(result); + while (code == TSDB_CODE_MND_DB_IN_CREATING || code == TSDB_CODE_MND_DB_IN_DROPPING) { + taosMsleep(2000); + result = taos_query(taos, sql); + code = taos_errno(result); + } if (code != TSDB_CODE_SUCCESS) { printf("query failen sql : %s\n errstr : %s\n", sql, taos_errstr(result)); ASSERT_EQ(taos_errno(result), TSDB_CODE_SUCCESS); @@ -122,9 +127,9 @@ void do_query(TAOS* taos, const char* sql) { void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUMS, int ROW_NUMS, int CYC_NUMS, bool hastags, bool createTable) { printf("test sql : %s\n", sql); - do_query(taos, "drop database if exists testdb1"); - do_query(taos, "create database IF NOT EXISTS testdb1"); - do_query(taos, "create stable testdb1.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))"); + do_query(taos, "drop database if exists stmt2_testdb_1"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_1"); + do_query(taos, "create stable stmt2_testdb_1.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))"); TAOS_STMT2* stmt = taos_stmt2_init(taos, option); ASSERT_NE(stmt, nullptr); @@ -139,7 +144,7 @@ void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUM sprintf(tbs[i], "ctb_%d", i); if (createTable) { char* tmp = (char*)taosMemoryMalloc(sizeof(char) * 100); - sprintf(tmp, "create table testdb1.%s using testdb1.stb tags(0, 'after')", tbs[i]); + sprintf(tmp, "create table stmt2_testdb_1.%s using stmt2_testdb_1.stb tags(0, 'after')", tbs[i]); do_query(taos, tmp); } } @@ -235,14 +240,15 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(taos, nullptr); - do_query(taos, "drop database if exists testdb2"); - do_query(taos, "create database IF NOT EXISTS testdb2 PRECISION 'ns'"); + do_query(taos, "drop database if exists stmt2_testdb_2"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_2 PRECISION 'ns'"); do_query(taos, - "create stable testdb2.stb (ts timestamp, b binary(10)) tags(t1 " + "create stable stmt2_testdb_2.stb (ts timestamp, b binary(10)) tags(t1 " "int, t2 binary(10))"); do_query( taos, - "create stable if not exists testdb2.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, " + "create stable if not exists stmt2_testdb_2.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 " + "bigint, " "v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 " "binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 " "smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint " @@ -251,7 +257,7 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { // case 1 : test super table { - const char* sql = "insert into testdb2.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, @@ -263,7 +269,7 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { { // case 2 : no tag - const char* sql = "insert into testdb2.stb(ts,b,tbname) values(?,?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(ts,b,tbname) values(?,?,?)"; TAOS_FIELD_ALL expectedFields[3] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}}; @@ -273,7 +279,7 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { // case 3 : random order { - const char* sql = "insert into testdb2.stb(tbname,ts,t2,b,t1) values(?,?,?,?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(tbname,ts,t2,b,t1) values(?,?,?,?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, @@ -285,7 +291,7 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { // case 4 : random order 2 { - const char* sql = "insert into testdb2.stb(ts,tbname,b,t2,t1) values(?,?,?,?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(ts,tbname,b,t2,t1) values(?,?,?,?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, {"b", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, @@ -297,7 +303,7 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { // case 5 : 'db'.'stb' { - const char* sql = "insert into 'testdb2'.'stb'(t1,t2,ts,b,tbname) values(?,?,?,?,?)"; + const char* sql = "insert into 'stmt2_testdb_2'.'stb'(t1,t2,ts,b,tbname) values(?,?,?,?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, @@ -309,7 +315,7 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { // case 6 : use db { - do_query(taos, "use testdb2"); + do_query(taos, "use stmt2_testdb_2"); const char* sql = "insert into stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, @@ -322,7 +328,7 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { // case 7 : less param { - const char* sql = "insert into testdb2.stb(ts,tbname) values(?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(ts,tbname) values(?,?)"; TAOS_FIELD_ALL expectedFields[2] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, {"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}}; printf("case 7 : %s\n", sql); @@ -378,67 +384,68 @@ TEST(stmt2Case, insert_stb_get_fields_Test) { // case 1 : add in main TD-33353 { - const char* sql = "insert into testdb2.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)"; + const char* sql = "insert into stmt2_testdb_2.stb(t1,t2,ts,b,tbname) values(1,?,?,'abc',?)"; printf("case 1dif : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM); } // case 2 : no pk { - const char* sql = "insert into testdb2.stb(b,tbname) values(?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(b,tbname) values(?,?)"; printf("case 2 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION); } // case 3 : no tbname and tag(not support bind) { - const char* sql = "insert into testdb2.stb(ts,b) values(?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(ts,b) values(?,?)"; printf("case 3 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION); } // case 4 : no col and tag(not support bind) { - const char* sql = "insert into testdb2.stb(tbname) values(?)"; + const char* sql = "insert into stmt2_testdb_2.stb(tbname) values(?)"; printf("case 4 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION); } // case 5 : no field name { - const char* sql = "insert into testdb2.stb(?,?,?,?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(?,?,?,?,?)"; printf("case 5 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR); } // case 6 : test super table not exist { - const char* sql = "insert into testdb2.nstb(?,?,?,?,?)"; + const char* sql = "insert into stmt2_testdb_2.nstb(?,?,?,?,?)"; printf("case 6 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR); } // case 7 : no col { - const char* sql = "insert into testdb2.stb(t1,t2,tbname) values(?,?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(t1,t2,tbname) values(?,?,?)"; printf("case 7 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_TSC_INVALID_OPERATION); } // case 8 : wrong para nums { - const char* sql = "insert into testdb2.stb(ts,b,tbname) values(?,?,?,?,?)"; + const char* sql = "insert into stmt2_testdb_2.stb(ts,b,tbname) values(?,?,?,?,?)"; printf("case 8 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM); } // case 9 : wrong simbol { - const char* sql = "insert into testdb2.stb(t1,t2,ts,b,tbname) values(*,*,*,*,*)"; + const char* sql = "insert into stmt2_testdb_2.stb(t1,t2,ts,b,tbname) values(*,*,*,*,*)"; printf("case 9 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM); } + do_query(taos, "drop database if exists stmt2_testdb_2"); taos_close(taos); } @@ -446,24 +453,25 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(taos, nullptr); - do_query(taos, "drop database if exists testdb3"); - do_query(taos, "create database IF NOT EXISTS testdb3 PRECISION 'ns'"); + do_query(taos, "drop database if exists stmt2_testdb_3"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_3 PRECISION 'ns'"); do_query(taos, - "create stable testdb3.stb (ts timestamp, b binary(10)) tags(t1 " + "create stable stmt2_testdb_3.stb (ts timestamp, b binary(10)) tags(t1 " "int, t2 binary(10))"); do_query( taos, - "create stable if not exists testdb3.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 bigint, " + "create stable if not exists stmt2_testdb_3.all_stb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 " + "bigint, " "v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 double, v12 " "binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20))tags(tts timestamp, tv1 bool, tv2 tinyint, tv3 " "smallint, tv4 int, tv5 bigint, tv6 tinyint unsigned, tv7 smallint unsigned, tv8 int unsigned, tv9 bigint " "unsigned, tv10 float, tv11 double, tv12 binary(20), tv13 varbinary(20), tv14 geometry(100), tv15 nchar(20));"); - do_query(taos, "CREATE TABLE testdb3.t0 USING testdb3.stb (t1,t2) TAGS (7,'Cali');"); + do_query(taos, "CREATE TABLE stmt2_testdb_3.t0 USING stmt2_testdb_3.stb (t1,t2) TAGS (7,'Cali');"); printf("support case \n"); // case 1 : test child table already exist { - const char* sql = "INSERT INTO testdb3.t0(ts,b)using testdb3.stb (t1,t2) TAGS(?,?) VALUES (?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_3.t0(ts,b)using stmt2_testdb_3.stb (t1,t2) TAGS(?,?) VALUES (?,?)"; TAOS_FIELD_ALL expectedFields[4] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, @@ -474,7 +482,7 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // case 2 : insert clause { - const char* sql = "INSERT INTO testdb3.? using testdb3.stb (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_3.? using stmt2_testdb_3.stb (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, @@ -486,7 +494,7 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // case 3 : insert child table not exist { - const char* sql = "INSERT INTO testdb3.d1 using testdb3.stb (t1,t2)TAGS(?,?) (ts,b)VALUES(?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_3.d1 using stmt2_testdb_3.stb (t1,t2)TAGS(?,?) (ts,b)VALUES(?,?)"; TAOS_FIELD_ALL expectedFields[4] = {{"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}, @@ -497,7 +505,7 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // case 4 : random order { - const char* sql = "INSERT INTO testdb3.? using testdb3.stb (t2,t1)TAGS(?,?) (b,ts)VALUES(?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_3.? using stmt2_testdb_3.stb (t2,t1)TAGS(?,?) (b,ts)VALUES(?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, @@ -509,7 +517,7 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // case 5 : less para { - const char* sql = "insert into testdb3.? using testdb3.stb (t2)tags(?) (ts)values(?)"; + const char* sql = "insert into stmt2_testdb_3.? using stmt2_testdb_3.stb (t2)tags(?) (ts)values(?)"; TAOS_FIELD_ALL expectedFields[3] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, {"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}}; @@ -520,7 +528,7 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // case 6 : insert into db.? using db.stb tags(?, ?) values(?,?) // no field name { - const char* sql = "insert into testdb3.? using testdb3.stb tags(?, ?) values(?,?)"; + const char* sql = "insert into stmt2_testdb_3.? using stmt2_testdb_3.stb tags(?, ?) values(?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, @@ -533,7 +541,7 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // case 7 : insert into db.d0 (ts)values(?) // less para { - const char* sql = "insert into testdb3.t0 (ts)values(?)"; + const char* sql = "insert into stmt2_testdb_3.t0 (ts)values(?)"; TAOS_FIELD_ALL expectedFields[1] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 2, 0, 8, TAOS_FIELD_COL}}; printf("case 7 : %s\n", sql); getFieldsSuccess(taos, sql, expectedFields, 1); @@ -541,7 +549,7 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // case 8 : 'db' 'stb' { - const char* sql = "INSERT INTO 'testdb3'.? using 'testdb3'.'stb' (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)"; + const char* sql = "INSERT INTO 'stmt2_testdb_3'.? using 'stmt2_testdb_3'.'stb' (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, {"t2", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_TAG}, @@ -553,7 +561,7 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // case 9 : use db { - do_query(taos, "use testdb3"); + do_query(taos, "use stmt2_testdb_3"); const char* sql = "INSERT INTO ? using stb (t1,t2) TAGS(?,?) (ts,b)VALUES(?,?)"; TAOS_FIELD_ALL expectedFields[5] = {{"tbname", TSDB_DATA_TYPE_BINARY, 0, 0, 271, TAOS_FIELD_TBNAME}, {"t1", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_TAG}, @@ -608,38 +616,40 @@ TEST(stmt2Case, insert_ctb_using_get_fields_Test) { // case 1 : test super table not exist { - const char* sql = "INSERT INTO testdb3.?(ts,b)using testdb3.nstb (t1,t2) TAGS(?,?) VALUES (?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_3.?(ts,b)using stmt2_testdb_3.nstb (t1,t2) TAGS(?,?) VALUES (?,?)"; printf("case 1 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR); } // case 2 : no pk { - const char* sql = "INSERT INTO testdb3.?(ts,b)using testdb3.nstb (t1,t2) TAGS(?,?) (n)VALUES (?)"; + const char* sql = "INSERT INTO stmt2_testdb_3.?(ts,b)using stmt2_testdb_3.nstb (t1,t2) TAGS(?,?) (n)VALUES (?)"; printf("case 2 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR); } // case 3 : less param and no filed name { - const char* sql = "INSERT INTO testdb3.?(ts,b)using testdb3.stb TAGS(?)VALUES (?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_3.?(ts,b)using stmt2_testdb_3.stb TAGS(?)VALUES (?,?)"; printf("case 3 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR); } // case 4 : none para for ctbname { - const char* sql = "INSERT INTO testdb3.d0 using testdb3.stb values(?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_3.d0 using stmt2_testdb_3.stb values(?,?)"; printf("case 4 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR); } // case 5 : none para for ctbname { - const char* sql = "insert into ! using testdb3.stb tags(?, ?) values(?,?)"; + const char* sql = "insert into ! using stmt2_testdb_3.stb tags(?, ?) values(?,?)"; printf("case 5 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_TSC_SQL_SYNTAX_ERROR); } + + do_query(taos, "drop database if exists stmt2_testdb_3"); taos_close(taos); } @@ -647,19 +657,20 @@ TEST(stmt2Case, insert_ntb_get_fields_Test) { TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(taos, nullptr); - do_query(taos, "drop database if exists testdb4"); - do_query(taos, "create database IF NOT EXISTS testdb4 PRECISION 'ms'"); - do_query(taos, "CREATE TABLE testdb4.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);"); - do_query(taos, - "create table if not exists testdb4.all_ntb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 " - "bigint, v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 " - "double, v12 binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20));"); + do_query(taos, "drop database if exists stmt2_testdb_4"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_4 PRECISION 'ms'"); + do_query(taos, "CREATE TABLE stmt2_testdb_4.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);"); + do_query( + taos, + "create table if not exists stmt2_testdb_4.all_ntb(ts timestamp, v1 bool, v2 tinyint, v3 smallint, v4 int, v5 " + "bigint, v6 tinyint unsigned, v7 smallint unsigned, v8 int unsigned, v9 bigint unsigned, v10 float, v11 " + "double, v12 binary(20), v13 varbinary(20), v14 geometry(100), v15 nchar(20));"); printf("support case \n"); // case 1 : test normal table no field name { - const char* sql = "INSERT INTO testdb4.ntb VALUES(?,?,?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_4.ntb VALUES(?,?,?,?)"; TAOS_FIELD_ALL expectedFields[4] = {{"nts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL}, {"nb", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, {"nvc", TSDB_DATA_TYPE_BINARY, 0, 0, 18, TAOS_FIELD_COL}, @@ -670,7 +681,7 @@ TEST(stmt2Case, insert_ntb_get_fields_Test) { // case 2 : test random order { - const char* sql = "INSERT INTO testdb4.ntb (ni,nb,nvc,nts)VALUES(?,?,?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_4.ntb (ni,nb,nvc,nts)VALUES(?,?,?,?)"; TAOS_FIELD_ALL expectedFields[4] = {{"ni", TSDB_DATA_TYPE_INT, 0, 0, 4, TAOS_FIELD_COL}, {"nb", TSDB_DATA_TYPE_BINARY, 0, 0, 12, TAOS_FIELD_COL}, {"nvc", TSDB_DATA_TYPE_BINARY, 0, 0, 18, TAOS_FIELD_COL}, @@ -681,7 +692,7 @@ TEST(stmt2Case, insert_ntb_get_fields_Test) { // case 3 : less param { - const char* sql = "INSERT INTO testdb4.ntb (nts)VALUES(?)"; + const char* sql = "INSERT INTO stmt2_testdb_4.ntb (nts)VALUES(?)"; TAOS_FIELD_ALL expectedFields[1] = {{"nts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL}}; printf("case 3 : %s\n", sql); getFieldsSuccess(taos, sql, expectedFields, 1); @@ -689,7 +700,7 @@ TEST(stmt2Case, insert_ntb_get_fields_Test) { // case 4 : test all types { - const char* sql = "insert into testdb4.all_ntb values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + const char* sql = "insert into stmt2_testdb_4.all_ntb values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; TAOS_FIELD_ALL expectedFields[16] = {{"ts", TSDB_DATA_TYPE_TIMESTAMP, 0, 0, 8, TAOS_FIELD_COL}, {"v1", TSDB_DATA_TYPE_BOOL, 0, 0, 1, TAOS_FIELD_COL}, {"v2", TSDB_DATA_TYPE_TINYINT, 0, 0, 1, TAOS_FIELD_COL}, @@ -721,26 +732,29 @@ TEST(stmt2Case, insert_ntb_get_fields_Test) { // case 2 : normal table must have tbnam { - const char* sql = "insert into testdb4.? values(?,?)"; + const char* sql = "insert into stmt2_testdb_4.? values(?,?)"; printf("case 2 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_TABLE_NOT_EXIST); } // case 3 : wrong para nums { - const char* sql = "insert into testdb4.ntb(nts,ni) values(?,?,?,?,?)"; + const char* sql = "insert into stmt2_testdb_4.ntb(nts,ni) values(?,?,?,?,?)"; printf("case 3 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_INVALID_COLUMNS_NUM); } + + do_query(taos, "drop database if exists stmt2_testdb_4"); + taos_close(taos); } TEST(stmt2Case, select_get_fields_Test) { TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(taos, nullptr); - do_query(taos, "drop database if exists testdb5"); - do_query(taos, "create database IF NOT EXISTS testdb5 PRECISION 'ns'"); - do_query(taos, "use testdb5"); - do_query(taos, "CREATE TABLE testdb5.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);"); + do_query(taos, "drop database if exists stmt2_testdb_5"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_5 PRECISION 'ns'"); + do_query(taos, "use stmt2_testdb_5"); + do_query(taos, "CREATE TABLE stmt2_testdb_5.ntb(nts timestamp, nb binary(10),nvc varchar(16),ni int);"); { // case 1 : const char* sql = "select * from ntb where ts = ?"; @@ -761,6 +775,8 @@ TEST(stmt2Case, select_get_fields_Test) { printf("case 3 : %s\n", sql); getFieldsError(taos, sql, TSDB_CODE_PAR_SYNTAX_ERROR); } + + do_query(taos, "drop database if exists stmt2_testdb_5"); taos_close(taos); } @@ -797,9 +813,9 @@ TEST(stmt2Case, stmt2_init_prepare_Test) { ASSERT_NE(stmt, nullptr); ASSERT_EQ(((STscStmt2*)stmt)->db, nullptr); - code = taos_stmt2_prepare(stmt, "insert into 'testdb5'.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)", 0); + code = taos_stmt2_prepare(stmt, "insert into 'stmt2_testdb_5'.stb(t1,t2,ts,b,tbname) values(?,?,?,?,?)", 0); ASSERT_NE(stmt, nullptr); - ASSERT_STREQ(((STscStmt2*)stmt)->db, "testdb5"); // add in main TD-33332 + ASSERT_STREQ(((STscStmt2*)stmt)->db, "stmt2_testdb_5"); // add in main TD-33332 taos_stmt2_close(stmt); } @@ -824,22 +840,28 @@ TEST(stmt2Case, stmt2_stb_insert) { ASSERT_NE(taos, nullptr); // normal TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL}; - { do_stmt(taos, &option, "insert into `testdb1`.`stb` (tbname,ts,b,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, true); } { - do_stmt(taos, &option, "insert into `testdb1`.? using `testdb1`.`stb` tags(?,?) values(?,?)", 3, 3, 3, true, true); + do_stmt(taos, &option, "insert into `stmt2_testdb_1`.`stb` (tbname,ts,b,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, + true); + } + { + do_stmt(taos, &option, "insert into `stmt2_testdb_1`.? using `stmt2_testdb_1`.`stb` tags(?,?) values(?,?)", 3, 3, 3, + true, true); } // async option = {0, true, true, stmtAsyncQueryCb, NULL}; - { do_stmt(taos, &option, "insert into testdb1.stb (ts,b,tbname,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, true); } { - do_stmt(taos, &option, "insert into testdb1.? using testdb1.stb (t1,t2)tags(?,?) (ts,b)values(?,?)", 3, 3, 3, true, - true); + do_stmt(taos, &option, "insert into stmt2_testdb_1.stb (ts,b,tbname,t1,t2) values(?,?,?,?,?)", 3, 3, 3, true, true); + } + { + do_stmt(taos, &option, "insert into stmt2_testdb_1.? using stmt2_testdb_1.stb (t1,t2)tags(?,?) (ts,b)values(?,?)", + 3, 3, 3, true, true); } // { do_stmt(taos, &option, "insert into db.? values(?,?)", 3, 3, 3, false, true); } // interlace = 0 & use db] - do_query(taos, "use testdb1"); + do_query(taos, "use stmt2_testdb_1"); option = {0, false, false, NULL, NULL}; { do_stmt(taos, &option, "insert into stb (tbname,ts,b) values(?,?,?)", 3, 3, 3, false, true); } { do_stmt(taos, &option, "insert into ? using stb (t1,t2)tags(?,?) (ts,b)values(?,?)", 3, 3, 3, true, true); } @@ -851,6 +873,7 @@ TEST(stmt2Case, stmt2_stb_insert) { option = {0, true, true, NULL, NULL}; { do_stmt(taos, &option, "insert into ? values(?,?)", 3, 3, 3, false, true); } + do_query(taos, "drop database if exists stmt2_testdb_1"); taos_close(taos); } @@ -858,10 +881,10 @@ TEST(stmt2Case, stmt2_stb_insert) { TEST(stmt2Case, stmt2_insert_non_statndard) { TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); ASSERT_NE(taos, nullptr); - do_query(taos, "drop database if exists example_all_type_stmt1"); - do_query(taos, "create database IF NOT EXISTS example_all_type_stmt1"); + do_query(taos, "drop database if exists stmt2_testdb_6"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_6"); do_query(taos, - "create stable example_all_type_stmt1.stb1 (ts timestamp, int_col int,long_col bigint,double_col " + "create stable stmt2_testdb_6.stb1 (ts timestamp, int_col int,long_col bigint,double_col " "double,bool_col bool,binary_col binary(20),nchar_col nchar(20),varbinary_col varbinary(20),geometry_col " "geometry(200)) tags(int_tag int,long_tag bigint,double_tag double,bool_tag bool,binary_tag " "binary(20),nchar_tag nchar(20),varbinary_tag varbinary(20),geometry_tag geometry(200));"); @@ -872,7 +895,7 @@ TEST(stmt2Case, stmt2_insert_non_statndard) { { TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); ASSERT_NE(stmt, nullptr); - const char* sql = "INSERT INTO example_all_type_stmt1.stb1 (ts,int_tag,tbname) VALUES (?,?,?)"; + const char* sql = "INSERT INTO stmt2_testdb_6.stb1 (ts,int_tag,tbname) VALUES (?,?,?)"; int code = taos_stmt2_prepare(stmt, sql, 0); checkError(stmt, code); int total_affect_rows = 0; @@ -912,9 +935,8 @@ TEST(stmt2Case, stmt2_insert_non_statndard) { { TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); ASSERT_NE(stmt, nullptr); - const char* sql = - "INSERT INTO example_all_type_stmt1.stb1 (binary_tag,int_col,tbname,ts,int_tag) VALUES (?,?,?,?,?)"; - int code = taos_stmt2_prepare(stmt, sql, 0); + const char* sql = "INSERT INTO stmt2_testdb_6.stb1 (binary_tag,int_col,tbname,ts,int_tag) VALUES (?,?,?,?,?)"; + int code = taos_stmt2_prepare(stmt, sql, 0); checkError(stmt, code); int tag_i = 0; @@ -954,6 +976,7 @@ TEST(stmt2Case, stmt2_insert_non_statndard) { taos_stmt2_close(stmt); } + do_query(taos, "drop database if exists stmt2_testdb_6"); taos_close(taos); } @@ -961,10 +984,10 @@ TEST(stmt2Case, stmt2_insert_non_statndard) { TEST(stmt2Case, stmt2_insert_db) { TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); ASSERT_NE(taos, nullptr); - do_query(taos, "drop database if exists example_all_type_stmt1"); - do_query(taos, "create database IF NOT EXISTS example_all_type_stmt1"); + do_query(taos, "drop database if exists stmt2_testdb_12"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_12"); do_query(taos, - "create stable `example_all_type_stmt1`.`stb1` (ts timestamp, int_col int,long_col bigint,double_col " + "create stable `stmt2_testdb_12`.`stb1` (ts timestamp, int_col int,long_col bigint,double_col " "double,bool_col bool,binary_col binary(20),nchar_col nchar(20),varbinary_col varbinary(20),geometry_col " "geometry(200)) tags(int_tag int,long_tag bigint,double_tag double,bool_tag bool,binary_tag " "binary(20),nchar_tag nchar(20),varbinary_tag varbinary(20),geometry_tag geometry(200));"); @@ -973,7 +996,7 @@ TEST(stmt2Case, stmt2_insert_db) { TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); ASSERT_NE(stmt, nullptr); - const char* sql = "INSERT INTO `example_all_type_stmt1`.`stb1` (ts,int_tag,tbname) VALUES (?,?,?)"; + const char* sql = "INSERT INTO `stmt2_testdb_12`.`stb1` (ts,int_tag,tbname) VALUES (?,?,?)"; int code = taos_stmt2_prepare(stmt, sql, 0); checkError(stmt, code); @@ -1006,38 +1029,38 @@ TEST(stmt2Case, stmt2_insert_db) { ASSERT_EQ(total_affect_rows, 12); taos_stmt2_close(stmt); + do_query(taos, "drop database if exists stmt2_testdb_12"); taos_close(taos); } TEST(stmt2Case, stmt2_query) { TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); ASSERT_NE(taos, nullptr); - do_query(taos, "drop database if exists testdb7"); - do_query(taos, "create database IF NOT EXISTS testdb7"); - do_query(taos, "create stable testdb7.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))"); + do_query(taos, "drop database if exists stmt2_testdb_7"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_7"); + do_query(taos, "create stable stmt2_testdb_7.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))"); do_query(taos, - "insert into testdb7.tb1 using testdb7.stb tags(1,'abc') values(1591060628000, " + "insert into stmt2_testdb_7.tb1 using stmt2_testdb_7.stb tags(1,'abc') values(1591060628000, " "'abc'),(1591060628001,'def'),(1591060628002, 'hij')"); do_query(taos, - "insert into testdb7.tb2 using testdb7.stb tags(2,'xyz') values(1591060628000, " - "'abc'),(1591060628001,'def'),(1591060628002, 'hij')"); - do_query(taos, "use testdb7"); + "insert into stmt2_testdb_7.tb2 using stmt2_testdb_7.stb tags(2,'xyz') values(1591060628000, " + "'abc'),(1591060628001,'def'),(1591060628004, 'hij')"); + do_query(taos, "use stmt2_testdb_7"); TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL}; TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); ASSERT_NE(stmt, nullptr); - const char* sql = "select * from testdb7.stb where ts = ? and tbname = ?"; + const char* sql = "select * from stmt2_testdb_7.stb where ts = ?"; int code = taos_stmt2_prepare(stmt, sql, 0); checkError(stmt, code); int t64_len[1] = {sizeof(int64_t)}; int b_len[1] = {3}; int64_t ts = 1591060628000; - TAOS_STMT2_BIND params[2] = {{TSDB_DATA_TYPE_TIMESTAMP, &ts, t64_len, NULL, 1}, - {TSDB_DATA_TYPE_BINARY, (void*)"tb1", b_len, NULL, 1}}; - TAOS_STMT2_BIND* paramv = ¶ms[0]; + TAOS_STMT2_BIND params = {TSDB_DATA_TYPE_TIMESTAMP, &ts, t64_len, NULL, 1}; + TAOS_STMT2_BIND* paramv = ¶ms; TAOS_STMT2_BINDV bindv = {1, NULL, NULL, ¶mv}; code = taos_stmt2_bind_param(stmt, &bindv, -1); checkError(stmt, code); @@ -1048,15 +1071,31 @@ TEST(stmt2Case, stmt2_query) { TAOS_RES* pRes = taos_stmt2_result(stmt); ASSERT_NE(pRes, nullptr); - int getRecordCounts = 0; - TAOS_ROW row; - while ((row = taos_fetch_row(pRes))) { + int getRecordCounts = 0; + while ((taos_fetch_row(pRes))) { + getRecordCounts++; + } + ASSERT_EQ(getRecordCounts, 2); + // test 1 result + ts = 1591060628004; + params = {TSDB_DATA_TYPE_TIMESTAMP, &ts, t64_len, NULL, 1}; + code = taos_stmt2_bind_param(stmt, &bindv, -1); + checkError(stmt, code); + + taos_stmt2_exec(stmt, NULL); + checkError(stmt, code); + + pRes = taos_stmt2_result(stmt); + ASSERT_NE(pRes, nullptr); + + getRecordCounts = 0; + while ((taos_fetch_row(pRes))) { getRecordCounts++; } ASSERT_EQ(getRecordCounts, 1); // taos_free_result(pRes); - taos_stmt2_close(stmt); + do_query(taos, "drop database if exists stmt2_testdb_7"); taos_close(taos); } @@ -1064,16 +1103,16 @@ TEST(stmt2Case, stmt2_ntb_insert) { TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); ASSERT_NE(taos, nullptr); TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL}; - do_query(taos, "drop database if exists testdb8"); - do_query(taos, "create database IF NOT EXISTS testdb8"); - do_query(taos, "create table testdb8.ntb(ts timestamp, b binary(10))"); - do_query(taos, "use testdb8"); + do_query(taos, "drop database if exists stmt2_testdb_8"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_8"); + do_query(taos, "create table stmt2_testdb_8.ntb(ts timestamp, b binary(10))"); + do_query(taos, "use stmt2_testdb_8"); TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); ASSERT_NE(stmt, nullptr); int total_affected_rows = 0; - const char* sql = "insert into testdb8.ntb values(?,?)"; + const char* sql = "insert into stmt2_testdb_8.ntb values(?,?)"; int code = taos_stmt2_prepare(stmt, sql, 0); checkError(stmt, code); for (int i = 0; i < 3; i++) { @@ -1101,6 +1140,7 @@ TEST(stmt2Case, stmt2_ntb_insert) { ASSERT_EQ(total_affected_rows, 9); taos_stmt2_close(stmt); + do_query(taos, "drop database if exists stmt2_testdb_8"); taos_close(taos); } @@ -1125,7 +1165,7 @@ TEST(stmt2Case, stmt2_status_Test) { ASSERT_EQ(code, TSDB_CODE_TSC_STMT_API_ERROR); ASSERT_STREQ(taos_stmt2_error(stmt), "Stmt API usage error"); - const char* sql = "insert into testdb9.ntb values(?,?)"; + const char* sql = "insert into stmt2_testdb_9.ntb values(?,?)"; code = taos_stmt2_prepare(stmt, sql, 0); ASSERT_EQ(code, TSDB_CODE_TSC_STMT_API_ERROR); ASSERT_STREQ(taos_stmt2_error(stmt), "Stmt API usage error"); @@ -1136,9 +1176,9 @@ TEST(stmt2Case, stmt2_status_Test) { TEST(stmt2Case, stmt2_nchar) { TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); - do_query(taos, "drop database if exists testdb10;"); - do_query(taos, "create database IF NOT EXISTS testdb10;"); - do_query(taos, "use testdb10;"); + do_query(taos, "drop database if exists stmt2_testdb_10;"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_10;"); + do_query(taos, "use stmt2_testdb_10;"); do_query(taos, "create table m1 (ts timestamp, blob2 nchar(10), blob nchar(10),blob3 nchar(10),blob4 nchar(10),blob5 " "nchar(10))"); @@ -1244,6 +1284,7 @@ TEST(stmt2Case, stmt2_nchar) { ASSERT_EQ(affected_rows, 10); taos_stmt2_close(stmt); + do_query(taos, "drop database if exists stmt2_testdb_10;"); taos_close(taos); taosMemoryFree(blob_len); taosMemoryFree(blob_len2); @@ -1256,11 +1297,12 @@ TEST(stmt2Case, all_type) { TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 0); ASSERT_NE(taos, nullptr); - do_query(taos, "drop database if exists testdb11"); - do_query(taos, "create database IF NOT EXISTS testdb11"); + do_query(taos, "drop database if exists stmt2_testdb_11"); + do_query(taos, "create database IF NOT EXISTS stmt2_testdb_11"); do_query( taos, - "create stable testdb11.stb(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 " + "create stable stmt2_testdb_11.stb(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 " + "smallint, c7 " "tinyint, c8 bool, c9 nchar(8), c10 geometry(256))TAGS(tts timestamp, t1 int, t2 bigint, t3 float, t4 double, t5 " "binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8), t10 geometry(256))"); @@ -1370,7 +1412,7 @@ TEST(stmt2Case, all_type) { params[10].is_null = NULL; params[10].num = 1; - char* stmt_sql = "insert into testdb11.? using stb tags(?,?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?,?)"; + char* stmt_sql = "insert into stmt2_testdb_11.? using stb tags(?,?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt2_prepare(stmt, stmt_sql, 0); checkError(stmt, code); @@ -1388,6 +1430,7 @@ TEST(stmt2Case, all_type) { geosFreeBuffer(outputGeom1); taos_stmt2_close(stmt); + do_query(taos, "drop database if exists stmt2_testdb_11"); taos_close(taos); } @@ -1395,31 +1438,29 @@ TEST(stmt2Case, geometry) { TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(taos, nullptr); - do_query(taos, "DROP DATABASE IF EXISTS testdb15"); - do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb15"); - do_query(taos, "CREATE TABLE testdb15.tb1(ts timestamp,c1 geometry(256))"); + do_query(taos, "DROP DATABASE IF EXISTS stmt2_testdb_13"); + do_query(taos, "CREATE DATABASE IF NOT EXISTS stmt2_testdb_13"); + do_query(taos, "CREATE TABLE stmt2_testdb_13.tb1(ts timestamp,c1 geometry(256))"); TAOS_STMT2_OPTION option = {0}; TAOS_STMT2* stmt = taos_stmt2_init(taos, &option); ASSERT_NE(stmt, nullptr); - unsigned char wkb1[] = { // 1 - 0x01, // 字节顺序:小端字节序 - 0x01, 0x00, 0x00, 0x00, // 几何类型:Point (1) - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, // p1 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, // p2 - // 2 - 0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, - 0x3f, - // 3 - 0x01, - 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, - 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x40}; + unsigned char wkb1[] = { + // 1 + 0x01, // 字节顺序:小端字节序 + 0x01, 0x00, 0x00, 0x00, // 几何类型:Point (1) + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, // p1 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, // p2 + // 2 + 0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf0, 0x3f, + // 3 + 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x40}; // unsigned char* wkb_all[3]{&wkb1[0], &wkb2[0], &wkb3[0]}; int32_t wkb_len[3] = {21, 61, 41}; @@ -1440,7 +1481,7 @@ TEST(stmt2Case, geometry) { params[1].is_null = NULL; params[1].num = 3; - char* stmt_sql = "insert into testdb15.tb1 (ts,c1)values(?,?)"; + char* stmt_sql = "insert into stmt2_testdb_13.tb1 (ts,c1)values(?,?)"; int code = taos_stmt2_prepare(stmt, stmt_sql, 0); checkError(stmt, code); @@ -1455,6 +1496,7 @@ TEST(stmt2Case, geometry) { ASSERT_EQ(affected_rows, 3); taos_stmt2_close(stmt); + do_query(taos, "DROP DATABASE IF EXISTS stmt2_testdb_13"); taos_close(taos); } #pragma GCC diagnostic pop diff --git a/source/client/test/stmtTest.cpp b/source/client/test/stmtTest.cpp index 510322ca87..77130e41db 100644 --- a/source/client/test/stmtTest.cpp +++ b/source/client/test/stmtTest.cpp @@ -52,6 +52,11 @@ void do_query(TAOS *taos, const char *sql) { TAOS_RES *result = taos_query(taos, sql); // printf("sql: %s\n", sql); int code = taos_errno(result); + while (code == TSDB_CODE_MND_DB_IN_CREATING || code == TSDB_CODE_MND_DB_IN_DROPPING) { + taosMsleep(2000); + result = taos_query(taos, sql); + code = taos_errno(result); + } if (code != TSDB_CODE_SUCCESS) { printf("query failen sql : %s\n errstr : %s\n", sql, taos_errstr(result)); ASSERT_EQ(taos_errno(result), TSDB_CODE_SUCCESS); @@ -69,12 +74,13 @@ typedef struct { void insertData(TAOS *taos, TAOS_STMT_OPTIONS *option, const char *sql, int CTB_NUMS, int ROW_NUMS, int CYC_NUMS, bool isCreateTable) { // create database and table - do_query(taos, "DROP DATABASE IF EXISTS testdb2"); - do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb2"); - do_query(taos, - "CREATE STABLE IF NOT EXISTS testdb2.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS " - "(groupId INT, location BINARY(24))"); - do_query(taos, "USE testdb2"); + do_query(taos, "DROP DATABASE IF EXISTS stmt_testdb_2"); + do_query(taos, "CREATE DATABASE IF NOT EXISTS stmt_testdb_2"); + do_query( + taos, + "CREATE STABLE IF NOT EXISTS stmt_testdb_2.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS " + "(groupId INT, location BINARY(24))"); + do_query(taos, "USE stmt_testdb_2"); // init TAOS_STMT *stmt; @@ -173,7 +179,7 @@ void insertData(TAOS *taos, TAOS_STMT_OPTIONS *option, const char *sql, int CTB_ for (int j = 0; j < ROW_NUMS; j++) { struct timeval tv; (&tv, NULL); - int64_t ts = 1591060628000 + j + k * 100; + int64_t ts = 1591060628000 + j + k * 100000; float current = (float)0.0001f * j; int voltage = j; float phase = (float)0.0001f * j; @@ -207,12 +213,13 @@ void insertData(TAOS *taos, TAOS_STMT_OPTIONS *option, const char *sql, int CTB_ void getFields(TAOS *taos, const char *sql, int expectedALLFieldNum, TAOS_FIELD_E *expectedTagFields, int expectedTagFieldNum, TAOS_FIELD_E *expectedColFields, int expectedColFieldNum) { // create database and table - do_query(taos, "DROP DATABASE IF EXISTS testdb3"); - do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb3"); - do_query(taos, "USE testdb3"); - do_query(taos, - "CREATE STABLE IF NOT EXISTS testdb3.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS " - "(groupId INT, location BINARY(24))"); + do_query(taos, "DROP DATABASE IF EXISTS stmt_testdb_3"); + do_query(taos, "CREATE DATABASE IF NOT EXISTS stmt_testdb_3"); + do_query(taos, "USE stmt_testdb_3"); + do_query( + taos, + "CREATE STABLE IF NOT EXISTS stmt_testdb_3.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS " + "(groupId INT, location BINARY(24))"); TAOS_STMT *stmt = taos_stmt_init(taos); ASSERT_NE(stmt, nullptr); @@ -271,7 +278,7 @@ TEST(stmtCase, stb_insert) { TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(taos, nullptr); // interlace = 0 - { insertData(taos, nullptr, "INSERT INTO testdb2.? USING meters TAGS(?,?) VALUES (?,?,?,?)", 1, 1, 1, false); } + { insertData(taos, nullptr, "INSERT INTO stmt_testdb_2.? USING meters TAGS(?,?) VALUES (?,?,?,?)", 1, 1, 1, false); } { insertData(taos, nullptr, "INSERT INTO ? USING meters TAGS(?,?) VALUES (?,?,?,?)", 3, 3, 3, false); } @@ -283,6 +290,7 @@ TEST(stmtCase, stb_insert) { insertData(taos, &options, "INSERT INTO ? VALUES (?,?,?,?)", 3, 3, 3, true); } + do_query(taos, "DROP DATABASE IF EXISTS stmt_testdb_2"); taos_close(taos); } @@ -299,18 +307,20 @@ TEST(stmtCase, get_fields) { {"phase", TSDB_DATA_TYPE_FLOAT, 0, 0, sizeof(float)}}; getFields(taos, "INSERT INTO ? USING meters TAGS(?,?) VALUES (?,?,?,?)", 7, &tagFields[0], 2, &colFields[0], 4); } + do_query(taos, "DROP DATABASE IF EXISTS stmt_testdb_3"); taos_close(taos); } -/* + TEST(stmtCase, all_type) { TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(taos, nullptr); - do_query(taos, "DROP DATABASE IF EXISTS testdb1"); - do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb1"); + do_query(taos, "DROP DATABASE IF EXISTS stmt_testdb_1"); + do_query(taos, "CREATE DATABASE IF NOT EXISTS stmt_testdb_1"); do_query( taos, - "CREATE STABLE testdb1.stb(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 smallint, c7 " + "CREATE STABLE stmt_testdb_1.stb1(ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(8), c6 " + "smallint, c7 " "tinyint, c8 bool, c9 nchar(8), c10 geometry(100))TAGS(tts timestamp, t1 int, t2 bigint, t3 float, t4 double, t5 " "binary(8), t6 smallint, t7 tinyint, t8 bool, t9 nchar(8), t10 geometry(100))"); @@ -418,18 +428,22 @@ TEST(stmtCase, all_type) { params[9].is_null = NULL; params[9].num = 1; + size_t size; + int code = initCtxGeomFromText(); + checkError(stmt, code); + unsigned char *outputGeom1; - size_t size1; - initCtxMakePoint(); - int code = doMakePoint(1.000, 2.000, &outputGeom1, &size1); + const char *wkt = "LINESTRING(1.0 1.0, 2.0 2.0)"; + code = doGeomFromText(wkt, &outputGeom1, &size); checkError(stmt, code); params[10].buffer_type = TSDB_DATA_TYPE_GEOMETRY; params[10].buffer = outputGeom1; - params[10].length = (int32_t *)&size1; + params[9].buffer_length = size; + params[10].length = (int32_t *)&size; params[10].is_null = NULL; params[10].num = 1; - char *stmt_sql = "insert into testdb1.? using stb tags(?,?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?,?)"; + char *stmt_sql = "insert into stmt_testdb_1.? using stb1 tags(?,?,?,?,?,?,?,?,?,?,?)values (?,?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, stmt_sql, 0); checkError(stmt, code); @@ -449,17 +463,17 @@ TEST(stmtCase, all_type) { checkError(stmt, code); taos_stmt_close(stmt); + do_query(taos, "DROP DATABASE IF EXISTS stmt_testdb_1"); taos_close(taos); } -*/ TEST(stmtCase, geometry) { TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(taos, nullptr); - do_query(taos, "DROP DATABASE IF EXISTS testdb5"); - do_query(taos, "CREATE DATABASE IF NOT EXISTS testdb5"); - do_query(taos, "CREATE TABLE testdb5.tb1(ts timestamp,c1 geometry(256))"); + do_query(taos, "DROP DATABASE IF EXISTS stmt_testdb_5"); + do_query(taos, "CREATE DATABASE IF NOT EXISTS stmt_testdb_5"); + do_query(taos, "CREATE TABLE stmt_testdb_5.tb1(ts timestamp,c1 geometry(256))"); TAOS_STMT *stmt = taos_stmt_init(taos); ASSERT_NE(stmt, nullptr); @@ -468,7 +482,6 @@ TEST(stmtCase, geometry) { 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, }, - // {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, @@ -503,7 +516,7 @@ TEST(stmtCase, geometry) { params[1].is_null = NULL; params[1].num = 3; - char *stmt_sql = "insert into testdb5.tb1 (ts,c1)values(?,?)"; + char *stmt_sql = "insert into stmt_testdb_5.tb1 (ts,c1)values(?,?)"; int code = taos_stmt_prepare(stmt, stmt_sql, 0); checkError(stmt, code); @@ -522,6 +535,7 @@ TEST(stmtCase, geometry) { taosMemoryFree(t64_len); taosMemoryFree(wkb_len); taos_stmt_close(stmt); + do_query(taos, "DROP DATABASE IF EXISTS stmt_testdb_5"); taos_close(taos); } From 113f7124b561f960bb2c2da00cab23e345288ce5 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 13 Jan 2025 18:24:21 +0800 Subject: [PATCH 3/8] fix:[TD-33504]add test case --- tests/parallel_test/cases.task | 1 + tests/system-test/7-tmq/tmq_td33504.py | 84 ++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/system-test/7-tmq/tmq_td33504.py diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 3c93c729d4..21005d910b 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -329,6 +329,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dataFromTsdbNWal-multiCtb.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_taosx.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_ts5466.py +,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_td33504.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_ts-5473.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/td-32187.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/td-33225.py diff --git a/tests/system-test/7-tmq/tmq_td33504.py b/tests/system-test/7-tmq/tmq_td33504.py new file mode 100644 index 0000000000..085b245dd5 --- /dev/null +++ b/tests/system-test/7-tmq/tmq_td33504.py @@ -0,0 +1,84 @@ + +import taos +import sys +import time +import socket +import os +import threading + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * +from taos.tmq import * +from taos import * + +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + #tdSql.init(conn.cursor(), logSql) # output sql.txt file + + def test(self): + tdSql.execute(f'create database if not exists db') + tdSql.execute(f'use db') + tdSql.execute(f'CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)') + tdSql.execute("INSERT INTO d1001 USING meters TAGS('California.SanFrancisco', 2) VALUES('2018-10-05 14:38:05.000',10.30000,219,0.31000)") + tdSql.execute("INSERT INTO d1002 USING meters TAGS('California.SanFrancisco', 2) VALUES('2018-10-05 14:38:05.000',10.30000,219,0.31000)") + tdSql.execute("INSERT INTO d1003 USING meters TAGS('California.SanFrancisco', 2) VALUES('2018-10-05 14:38:05.000',10.30000,219,0.31000)") + tdSql.execute("INSERT INTO d1004 USING meters TAGS('California.SanFrancisco', 2) VALUES('2018-10-05 14:38:05.000',10.30000,219,0.31000)") + + tdSql.execute(f'create topic t0 as select * from meters') + tdSql.execute(f'create topic t1 as select * from meters') + + consumer_dict = { + "group.id": "g1", + "td.connect.user": "root", + "td.connect.pass": "taosdata", + "auto.offset.reset": "earliest", + } + consumer = Consumer(consumer_dict) + + try: + consumer.subscribe(["t0"]) + except TmqError: + tdLog.exit(f"subscribe error") + + try: + res = consumer.poll(1) + print(res) + + consumer.unsubscribe() + + try: + consumer.subscribe(["t1"]) + except TmqError: + tdLog.exit(f"subscribe error") + + + res = consumer.poll(1) + print(res) + if res == None and taos_errno(None) != 0: + tdLog.exit(f"poll error %d" % taos_errno(None)) + + except TmqError: + tdLog.exit(f"poll error") + finally: + consumer.close() + + + def run(self): + self.test() + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) From 1fe3ada4649dd2578729b3b7d1af65a889a86efb Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Tue, 14 Jan 2025 14:56:17 +0800 Subject: [PATCH 4/8] fix async error in unit test --- source/client/test/stmt2Test.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/client/test/stmt2Test.cpp b/source/client/test/stmt2Test.cpp index 3e21721c47..52c89e97ab 100644 --- a/source/client/test/stmt2Test.cpp +++ b/source/client/test/stmt2Test.cpp @@ -197,7 +197,7 @@ void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUM checkError(stmt, code); // exec - int affected; + int affected = 0; code = taos_stmt2_exec(stmt, &affected); total_affected += affected; checkError(stmt, code); @@ -219,8 +219,9 @@ void do_stmt(TAOS* taos, TAOS_STMT2_OPTION* option, const char* sql, int CTB_NUM taosMemoryFree(tags); } } - - ASSERT_EQ(total_affected, CYC_NUMS * ROW_NUMS * CTB_NUMS); + if (option->asyncExecFn == NULL) { + ASSERT_EQ(total_affected, CYC_NUMS * ROW_NUMS * CTB_NUMS); + } for (int i = 0; i < CTB_NUMS; i++) { taosMemoryFree(tbs[i]); } From 2511a15d71311fa9874f81133d468df76d9b407b Mon Sep 17 00:00:00 2001 From: factosea <285808407@qq.com> Date: Tue, 14 Jan 2025 15:20:05 +0800 Subject: [PATCH 5/8] fix: doc demo code --- docs/examples/c/insert_data_demo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/examples/c/insert_data_demo.c b/docs/examples/c/insert_data_demo.c index 7570af02ad..364872fd88 100644 --- a/docs/examples/c/insert_data_demo.c +++ b/docs/examples/c/insert_data_demo.c @@ -58,12 +58,13 @@ static int DemoInsertData() { taos_cleanup(); return -1; } - taos_free_result(result); // you can check affectedRows here int rows = taos_affected_rows(result); fprintf(stdout, "Successfully inserted %d rows into power.meters.\n", rows); + taos_free_result(result); + // close & clean taos_close(taos); taos_cleanup(); From b8268b39e7f10bc870e5c2a049f2b35dd793c4d3 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Thu, 16 Jan 2025 09:45:52 +0800 Subject: [PATCH 6/8] Test(wal): add case for remove wal. --- tests/system-test/7-tmq/walRemoveLog.py | 188 ++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 tests/system-test/7-tmq/walRemoveLog.py diff --git a/tests/system-test/7-tmq/walRemoveLog.py b/tests/system-test/7-tmq/walRemoveLog.py new file mode 100644 index 0000000000..3a69a31d14 --- /dev/null +++ b/tests/system-test/7-tmq/walRemoveLog.py @@ -0,0 +1,188 @@ +import taos +import sys +import time +import socket +import os +import platform +import threading +from enum import Enum + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.cluster import * +from taos.tmq import * +from taos import * + +sys.path.append("./7-tmq") +from tmqCommon import * + + +class TDTestCase: + global cmd_list + cmd_list = [] + + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), True) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files or "taosd.exe" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def prepareData(self): + tdLog.info("create database db_repl_1 and insert data") + cmd1 = "taosBenchmark -y -a 1 -n 100 -t 100 -v 1 -d %s" % ("db_repl_1") + os.system(cmd1) + + tdLog.info("create database db_repl_2 and insert data") + cmd2 = "taosBenchmark -y -a 2 -n 100 -t 100 -v 1 -d %s" % ("db_repl_2") + os.system(cmd2) + + tdLog.info("create database db_repl_3 and insert data") + cmd3 = "taosBenchmark -y -a 3 -n 100 -t 100 -v 1 -d %s" % ("db_repl_3") + os.system(cmd3) + + def insertData(self): + tdLog.info("insert one record into db_repl_*.d0") + tdSql.execute("insert into db_repl_1.d0 values(now(),6.8358979,250,148.5000000);") + tdSql.execute("insert into db_repl_2.d0 values(now(),6.8358979,250,148.5000000);") + tdSql.execute("insert into db_repl_3.d0 values(now(),6.8358979,250,148.5000000);") + + def flushDatabase(self): + tdLog.info("flush database db_repl_1") + tdSql.execute("flush database db_repl_1") + + tdLog.info("flush database db_repl_2") + tdSql.execute("flush database db_repl_2") + + tdLog.info("flush database db_repl_3") + tdSql.execute("flush database db_repl_3") + + def checkDatacount(self,expCount): + tdLog.info("select data count from db_repl_1") + tdSql.query("select count(*) from db_repl_1.meters") + actCount = tdSql.getData(0, 0) + assert actCount == expCount, f"db_repl_1.meters count is {actCount}, expect {expCount}" + + tdLog.info("select data count from db_repl_2") + tdSql.query("select count(*) from db_repl_2.meters") + actCount = tdSql.getData(0, 0) + assert actCount == expCount, f"db_repl_2.meters count is {actCount}, expect {expCount}" + + + tdLog.info("select data count from db_repl_3") + tdSql.query("select count(*) from db_repl_3.meters") + actCount = tdSql.getData(0, 0) + assert actCount == expCount, f"db_repl_3.meters count is {actCount}, expect {expCount}" + + + def collect_rm_wal_cmds(self): + global cmd_list + buildPath = self.getBuildPath() + rowLen = tdSql.query('show vnodes on dnode 1') + for i in range(rowLen): + vgroupId = tdSql.getData(i, 1) + walPath = buildPath + "/../sim/dnode1/data/vnode/vnode{}/wal/*".format(vgroupId) + cmd = "rm -rf %s" % walPath + cmd_list.append(cmd) + + rowLen = tdSql.query('show vnodes on dnode 2') + for i in range(rowLen): + vgroupId = tdSql.getData(i, 1) + walPath = buildPath + "/../sim/dnode2/data/vnode/vnode{}/wal/*".format(vgroupId) + cmd = "rm -rf %s" % walPath + cmd_list.append(cmd) + + rowLen = tdSql.query('show vnodes on dnode 3') + for i in range(rowLen): + vgroupId = tdSql.getData(i, 1) + walPath = buildPath + "/../sim/dnode3/data/vnode/vnode{}/wal/*".format(vgroupId) + cmd = "rm -rf %s" % walPath + cmd_list.append(cmd) + + def execute_rm_wal_cmds(self): + for cmd in cmd_list: + print(cmd) + os.system(cmd) + + def run(self): + print("======== run remove wal test ========") + self.prepareData() + self.flushDatabase() + + self.collect_rm_wal_cmds() + tdSql.execute(f'create topic data_repl_1 as select ts,current from db_repl_1.meters') + tdSql.execute(f'create topic data_repl_2 as select ts,current from db_repl_2.meters') + tdSql.execute(f'create topic data_repl_3 as select ts,current from db_repl_3.meters') + + tdDnodes=cluster.dnodes + tdDnodes[0].stoptaosd() + tdDnodes[1].stoptaosd() + tdDnodes[2].stoptaosd() + + + time.sleep(10) + + self.execute_rm_wal_cmds() + + tdDnodes[0].starttaosd() + tdDnodes[1].starttaosd() + tdDnodes[2].starttaosd() + + self.checkDatacount(10000) + self.insertData() + self.checkDatacount(10001) + + consumer_dict = { + "group.id": "g1", + "td.connect.user": "root", + "td.connect.pass": "taosdata", + "auto.offset.reset": "earliest", + } + consumer = Consumer(consumer_dict) + + try: + consumer.subscribe(["data_repl_1", "data_repl_2", "data_repl_3"]) + except TmqError: + tdLog.exit(f"subscribe error") + + cnt = 0 + try: + while True: + res = consumer.poll(1) + print(res) + if not res: + print("cnt:",cnt) + if cnt == 0 or cnt != 3: + tdLog.exit("consume error") + break + val = res.value() + if val is None: + continue + for block in val: + print(block.fetchall(),len(block.fetchall())) + cnt += len(block.fetchall()) + finally: + consumer.close() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) From 658b45d5d06f2f4a5de24b12bf29ce068bff7ce6 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Thu, 16 Jan 2025 09:48:26 +0800 Subject: [PATCH 7/8] Add walRemoveLog.py to parallel_test. --- tests/parallel_test/cases.task | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 3c93c729d4..a47fb5f732 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -361,6 +361,7 @@ ,,y,system-test,./pytest.sh python3 test.py -f 7-tmq/tmqVnodeSplit-column-false.py -N 3 -n 3 ,,y,system-test,./pytest.sh python3 test.py -f 7-tmq/tmqVnodeSplit-db.py -N 3 -n 3 ,,y,system-test,./pytest.sh python3 test.py -f 7-tmq/tmqVnodeSplit-db-false.py -N 3 -n 3 +,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/walRemoveLog.py -N 3 ,,y,system-test,./pytest.sh python3 test.py -f 7-tmq/tmqVnodeReplicate.py -M 3 -N 3 -n 3 ,,y,system-test,./pytest.sh python3 ./test.py -f 99-TDcase/TD-19201.py From f07fe7362a4fd0226f0abe3b9b7a47c6969846b3 Mon Sep 17 00:00:00 2001 From: dmchen Date: Fri, 17 Jan 2025 04:10:37 +0000 Subject: [PATCH 8/8] fix/insert-when-2-replicas --- source/libs/sync/src/syncMain.c | 3 ++- tests/army/cluster/arbitrator.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 4862a4b963..0933fd48c7 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -3428,7 +3428,8 @@ _out:; ths->pLogBuf->matchIndex, ths->pLogBuf->endIndex); if (code == 0 && ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) { - TAOS_CHECK_RETURN(syncNodeUpdateAssignedCommitIndex(ths, matchIndex)); + int64_t index = syncNodeUpdateAssignedCommitIndex(ths, matchIndex); + sTrace("vgId:%d, update assigned commit index %" PRId64 "", ths->vgId, index); if (ths->fsmState != SYNC_FSM_STATE_INCOMPLETE && syncLogBufferCommit(ths->pLogBuf, ths, ths->assignedCommitIndex) < 0) { diff --git a/tests/army/cluster/arbitrator.py b/tests/army/cluster/arbitrator.py index 9fd8e7b1f3..385358e5cc 100644 --- a/tests/army/cluster/arbitrator.py +++ b/tests/army/cluster/arbitrator.py @@ -35,6 +35,12 @@ class TDTestCase(TBase): time.sleep(1) + tdSql.execute("use db;") + + tdSql.execute("CREATE STABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);") + + tdSql.execute("CREATE TABLE d0 USING meters TAGS (\"California.SanFrancisco\", 2);"); + count = 0 while count < 100: @@ -72,6 +78,8 @@ class TDTestCase(TBase): count += 1 + tdSql.execute("INSERT INTO d0 VALUES (NOW, 10.3, 219, 0.31);") + def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed")