add unit test async stmt order
This commit is contained in:
parent
b55980d71d
commit
b0bf9bb502
|
@ -37,7 +37,7 @@ namespace {
|
||||||
void checkError(TAOS_STMT2* stmt, int code) {
|
void checkError(TAOS_STMT2* stmt, int code) {
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
STscStmt2* pStmt = (STscStmt2*)stmt;
|
STscStmt2* pStmt = (STscStmt2*)stmt;
|
||||||
if (pStmt == nullptr || pStmt->sql.sqlStr == nullptr) {
|
if (pStmt == nullptr || pStmt->sql.sqlStr == nullptr || pStmt->exec.pRequest == nullptr) {
|
||||||
printf("stmt api error\n stats : %d\n errstr : %s\n", pStmt->sql.status, taos_stmt_errstr(stmt));
|
printf("stmt api error\n stats : %d\n errstr : %s\n", pStmt->sql.status, taos_stmt_errstr(stmt));
|
||||||
} else {
|
} else {
|
||||||
printf("stmt api error\n sql : %s\n stats : %d\n errstr : %s\n", pStmt->sql.sqlStr, pStmt->sql.status,
|
printf("stmt api error\n sql : %s\n stats : %d\n errstr : %s\n", pStmt->sql.sqlStr, pStmt->sql.status,
|
||||||
|
@ -1611,8 +1611,10 @@ TEST(stmt2Case, errcode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void stmtAsyncBindCb(void* param, TAOS_RES* pRes, int code) {
|
void stmtAsyncBindCb(void* param, TAOS_RES* pRes, int code) {
|
||||||
|
bool* finish = (bool*)param;
|
||||||
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
|
||||||
taosMsleep(500);
|
taosMsleep(500);
|
||||||
|
*finish = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1622,10 +1624,17 @@ void stmtAsyncQueryCb2(void* param, TAOS_RES* pRes, int code) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stmtAsyncBindCb2(void* param, TAOS_RES* pRes, int code) {
|
||||||
|
bool* finish = (bool*)param;
|
||||||
|
taosMsleep(500);
|
||||||
|
*finish = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TEST(stmt2Case, async_order) {
|
TEST(stmt2Case, async_order) {
|
||||||
int CTB_NUMS = 3;
|
int CTB_NUMS = 2;
|
||||||
int ROW_NUMS = 3;
|
int ROW_NUMS = 2;
|
||||||
int CYC_NUMS = 1;
|
int CYC_NUMS = 2;
|
||||||
|
|
||||||
TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
TAOS* taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||||
TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb2, NULL};
|
TAOS_STMT2_OPTION option = {0, true, true, stmtAsyncQueryCb2, NULL};
|
||||||
|
@ -1651,9 +1660,8 @@ TEST(stmt2Case, async_order) {
|
||||||
sprintf(tmp, "create table stmt2_testdb_15.%s using stmt2_testdb_15.stb tags(0, 'after')", tbs[i]);
|
sprintf(tmp, "create table stmt2_testdb_15.%s using stmt2_testdb_15.stb tags(0, 'after')", tbs[i]);
|
||||||
do_query(taos, tmp);
|
do_query(taos, tmp);
|
||||||
}
|
}
|
||||||
|
// params
|
||||||
// case 1 : bind_a->exec_a->bind_a->exec_a->...
|
TAOS_STMT2_BIND** paramv = (TAOS_STMT2_BIND**)taosMemoryMalloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*));
|
||||||
for (int r = 0; r < CYC_NUMS; r++) {
|
|
||||||
// col params
|
// col params
|
||||||
int64_t** ts = (int64_t**)taosMemoryMalloc(CTB_NUMS * sizeof(int64_t*));
|
int64_t** ts = (int64_t**)taosMemoryMalloc(CTB_NUMS * sizeof(int64_t*));
|
||||||
char** b = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
|
char** b = (char**)taosMemoryMalloc(CTB_NUMS * sizeof(char*));
|
||||||
|
@ -1667,14 +1675,41 @@ TEST(stmt2Case, async_order) {
|
||||||
ts[i] = (int64_t*)taosMemoryMalloc(ROW_NUMS * sizeof(int64_t));
|
ts[i] = (int64_t*)taosMemoryMalloc(ROW_NUMS * sizeof(int64_t));
|
||||||
b[i] = (char*)taosMemoryMalloc(ROW_NUMS * sizeof(char));
|
b[i] = (char*)taosMemoryMalloc(ROW_NUMS * sizeof(char));
|
||||||
for (int j = 0; j < ROW_NUMS; j++) {
|
for (int j = 0; j < ROW_NUMS; j++) {
|
||||||
ts[i][j] = 1591060628000 + r * 100000 + j;
|
ts[i][j] = 1591060628000 + 100000 + j;
|
||||||
b[i][j] = 'a' + j;
|
b[i][j] = 'a' + j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// bind params
|
||||||
|
for (int i = 0; i < CTB_NUMS; i++) {
|
||||||
|
// create col params
|
||||||
|
paramv[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
|
||||||
|
paramv[i][0] = {TSDB_DATA_TYPE_TIMESTAMP, &ts[i][0], &ts_len[0], NULL, ROW_NUMS};
|
||||||
|
paramv[i][1] = {TSDB_DATA_TYPE_BINARY, &b[i][0], &b_len[0], NULL, ROW_NUMS};
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 1 : bind_a->exec_a->bind_a->exec_a->...
|
||||||
|
{
|
||||||
|
printf("case 1 : bind_a->exec_a->bind_a->exec_a->...\n");
|
||||||
|
for (int r = 0; r < CYC_NUMS; r++) {
|
||||||
|
// bind
|
||||||
|
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
|
||||||
|
bool finish = false;
|
||||||
|
code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
|
||||||
|
|
||||||
|
checkError(stmt, code);
|
||||||
|
|
||||||
|
// exec
|
||||||
|
code = taos_stmt2_exec(stmt, NULL);
|
||||||
|
checkError(stmt, code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 2 : bind_a->bind_a->bind_a->exec_a->...
|
||||||
|
{
|
||||||
|
printf("case 2 : bind_a->bind_a->bind_a->exec_a->...\n");
|
||||||
|
for (int r = 0; r < CYC_NUMS; r++) {
|
||||||
// bind params
|
// bind params
|
||||||
TAOS_STMT2_BIND** paramv = (TAOS_STMT2_BIND**)taosMemoryMalloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*));
|
TAOS_STMT2_BIND** paramv = (TAOS_STMT2_BIND**)taosMemoryMalloc(CTB_NUMS * sizeof(TAOS_STMT2_BIND*));
|
||||||
|
|
||||||
for (int i = 0; i < CTB_NUMS; i++) {
|
for (int i = 0; i < CTB_NUMS; i++) {
|
||||||
// create col params
|
// create col params
|
||||||
paramv[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
|
paramv[i] = (TAOS_STMT2_BIND*)taosMemoryMalloc(2 * sizeof(TAOS_STMT2_BIND));
|
||||||
|
@ -1683,16 +1718,111 @@ TEST(stmt2Case, async_order) {
|
||||||
}
|
}
|
||||||
// bind
|
// bind
|
||||||
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
|
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
|
||||||
code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, NULL);
|
bool finish = false;
|
||||||
// code = taos_stmt2_bind_param(stmt, &bindv, -1);
|
code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
|
||||||
|
while (!finish) {
|
||||||
|
taosMsleep(100);
|
||||||
|
}
|
||||||
|
checkError(stmt, code);
|
||||||
|
}
|
||||||
|
// exec
|
||||||
|
code = taos_stmt2_exec(stmt, NULL);
|
||||||
|
checkError(stmt, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 3 : bind->exec_a->bind->exec_a->...
|
||||||
|
{
|
||||||
|
printf("case 3 : bind->exec_a->bind->exec_a->...\n");
|
||||||
|
for (int r = 0; r < CYC_NUMS; r++) {
|
||||||
|
// bind
|
||||||
|
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
|
||||||
|
bool finish = false;
|
||||||
|
code = taos_stmt2_bind_param(stmt, &bindv, -1);
|
||||||
|
|
||||||
checkError(stmt, code);
|
checkError(stmt, code);
|
||||||
|
|
||||||
// exec
|
// exec
|
||||||
int affected = 0;
|
code = taos_stmt2_exec(stmt, NULL);
|
||||||
code = taos_stmt2_exec(stmt, &affected);
|
checkError(stmt, code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 4 : bind_a->close
|
||||||
|
{
|
||||||
|
printf("case 4 : bind_a->close\n");
|
||||||
|
// bind
|
||||||
|
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
|
||||||
|
bool finish = false;
|
||||||
|
code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
|
||||||
|
checkError(stmt, code);
|
||||||
|
taos_stmt2_close(stmt);
|
||||||
|
checkError(stmt, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 5 : bind_a->exec_a->close
|
||||||
|
{
|
||||||
|
printf("case 5 : bind_a->exec_a->close\n");
|
||||||
|
// init
|
||||||
|
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
|
||||||
|
ASSERT_NE(stmt, nullptr);
|
||||||
|
int code = taos_stmt2_prepare(stmt, sql, 0);
|
||||||
|
checkError(stmt, code);
|
||||||
|
// bind
|
||||||
|
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
|
||||||
|
bool finish = false;
|
||||||
|
code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
|
||||||
|
checkError(stmt, code);
|
||||||
|
// exec
|
||||||
|
code = taos_stmt2_exec(stmt, NULL);
|
||||||
|
checkError(stmt, code);
|
||||||
|
// close
|
||||||
|
taos_stmt2_close(stmt);
|
||||||
|
checkError(stmt, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
option = {0, false, false, NULL, NULL};
|
||||||
|
stmt = taos_stmt2_init(taos, &option);
|
||||||
|
ASSERT_NE(stmt, nullptr);
|
||||||
|
code = taos_stmt2_prepare(stmt, sql, 0);
|
||||||
checkError(stmt, code);
|
checkError(stmt, code);
|
||||||
|
|
||||||
|
// case 6 : bind_a->exec->bind_a->exec->...
|
||||||
|
{
|
||||||
|
printf("case 6 : bind_a->exec->bind_a->exec->...\n");
|
||||||
|
// init
|
||||||
|
|
||||||
|
checkError(stmt, code);
|
||||||
|
for (int r = 0; r < CYC_NUMS; r++) {
|
||||||
|
// bind
|
||||||
|
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
|
||||||
|
bool finish = false;
|
||||||
|
code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb, (void*)&finish);
|
||||||
|
checkError(stmt, code);
|
||||||
|
// exec
|
||||||
|
code = taos_stmt2_exec(stmt, NULL);
|
||||||
|
checkError(stmt, code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// case 7 (error:no wait error) : bind_a->bind_a
|
||||||
|
{
|
||||||
|
printf("case 7 (error:no wait error) : bind_a->bind_a\n");
|
||||||
|
// bind
|
||||||
|
TAOS_STMT2_BINDV bindv = {CTB_NUMS, tbs, NULL, paramv};
|
||||||
|
bool finish = false;
|
||||||
|
code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb2, (void*)&finish);
|
||||||
|
checkError(stmt, code);
|
||||||
|
taosMsleep(200);
|
||||||
|
code = taos_stmt2_bind_param_a(stmt, &bindv, -1, stmtAsyncBindCb2, (void*)&finish);
|
||||||
|
ASSERT_EQ(code, TSDB_CODE_TSC_STMT_API_ERROR);
|
||||||
|
while (!finish) {
|
||||||
|
taosMsleep(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// close
|
||||||
|
taos_stmt2_close(stmt);
|
||||||
|
|
||||||
|
// free memory
|
||||||
for (int i = 0; i < CTB_NUMS; i++) {
|
for (int i = 0; i < CTB_NUMS; i++) {
|
||||||
taosMemoryFree(paramv[i]);
|
taosMemoryFree(paramv[i]);
|
||||||
taosMemoryFree(ts[i]);
|
taosMemoryFree(ts[i]);
|
||||||
|
@ -1703,20 +1833,9 @@ TEST(stmt2Case, async_order) {
|
||||||
taosMemoryFree(ts_len);
|
taosMemoryFree(ts_len);
|
||||||
taosMemoryFree(b_len);
|
taosMemoryFree(b_len);
|
||||||
taosMemoryFree(paramv);
|
taosMemoryFree(paramv);
|
||||||
}
|
|
||||||
// ASSERT_EQ(total_affected, CYC_NUMS * ROW_NUMS * CTB_NUMS);
|
|
||||||
|
|
||||||
// case 2 : bind_a->bind_a->bind_a->exec_a->...
|
|
||||||
// case 3 : bind->exec_a->bind->exec_a->...
|
|
||||||
// case 4 : bind_a->exec->bind_a->exec->...
|
|
||||||
// case 5 : bind_a->close
|
|
||||||
// case 6 : exec_a->close
|
|
||||||
|
|
||||||
for (int i = 0; i < CTB_NUMS; i++) {
|
for (int i = 0; i < CTB_NUMS; i++) {
|
||||||
taosMemoryFree(tbs[i]);
|
taosMemoryFree(tbs[i]);
|
||||||
}
|
}
|
||||||
taosMemoryFree(tbs);
|
taosMemoryFree(tbs);
|
||||||
|
|
||||||
taos_stmt2_close(stmt);
|
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
Loading…
Reference in New Issue