From dfe2b27fafefc7eb4702ed2a96ee5344a61d12cc Mon Sep 17 00:00:00 2001 From: Kaijie Gu <2459548460@qq.com> Date: Mon, 15 Jul 2024 23:17:06 +0800 Subject: [PATCH] add sql execution time interval parameter --- src/dbtest/src/sql_cntl.cc | 7 +++++++ src/dbtest/src/sql_cntl.h | 10 ++++++---- src/dbtest/src/sql_cntl_v2.cc | 6 ++++++ src/dbtest/src/sqltest.cc | 4 +++- src/dbtest/src/sqltest_v2.cc | 4 +++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/dbtest/src/sql_cntl.cc b/src/dbtest/src/sql_cntl.cc index 16958d24..7923991d 100644 --- a/src/dbtest/src/sql_cntl.cc +++ b/src/dbtest/src/sql_cntl.cc @@ -199,6 +199,9 @@ bool DBConnector::ExecWriteSql(int sql_id, const std::string& sql, TestResultSet SQLHSTMT m_hStatement; SQLHDBC m_hDatabaseConnection = DBConnector::conn_pool_[session_id - 1]; + //sleeep time_interval_ ms + usleep(1000 * time_interval_); + // Allocate a statement handle: Allocate a new statement handle for the database connection using SQLAllocHandle function. ret = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement); std::string err_info_stmt = DBConnector::SqlExecuteErr(session_id, sql_id, sql, "stmt", m_hStatement, ret, test_process_file); @@ -278,6 +281,9 @@ bool DBConnector::ExecReadSql2Int(int sql_id, const std::string& sql, TestResult // Get the expected result set list from test_result_set std::vector>> expected_result_set_list = test_result_set.ExpectedResultSetList(); + //sleeep time_interval_ ms + usleep(1000 * time_interval_); + // Allocate a statement handle: Allocate a new statement handle for the database connection using SQLAllocHandle function. ret = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement); // Check if allocating a statement handle was successful. If it fails, release the handle and return false. @@ -385,6 +391,7 @@ bool DBConnector::ExecReadSql2Int(int sql_id, const std::string& sql, TestResult * @return True if the operation is successful, false otherwise. */ bool DBConnector::SQLEndTnx(std::string opt, int session_id, int sql_id, TestResultSet& test_result_set, const std::string& db_type, std::string test_process_file) { + if (sql_id != 1024) { std::string blank(blank_base*(session_id - 1), ' '); std::string output_info; diff --git a/src/dbtest/src/sql_cntl.h b/src/dbtest/src/sql_cntl.h index 153cc989..f18a8a60 100644 --- a/src/dbtest/src/sql_cntl.h +++ b/src/dbtest/src/sql_cntl.h @@ -18,9 +18,11 @@ class DBConnector { private: // Each SQLHDBC is a handle for a single database connection. std::vector conn_pool_; + std::int32_t time_interval_; //time interval between sql execution public: // Initializes the database connector, stablishes a specified number of database connections and adds them to the connection pool. - bool InitDBConnector(std::string& user, std::string& passwd, std::string& db_type, int conn_pool_size) { + bool InitDBConnector(std::string& user, std::string& passwd, std::string& db_type, int conn_pool_size, int32_t time_interval) { + this->time_interval_ = time_interval; for (int i = 0; i < (int)conn_pool_size; i++) { // Initializes the ODBC environment handle m_hEnviroment. SQLHENV m_hEnviroment; @@ -30,8 +32,8 @@ class DBConnector { // Allocates the ODBC environment handle using SQLAllocHandle. ret = SQLAllocHandle(SQL_HANDLE_ENV, NULL, &m_hEnviroment); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { - std::cerr << "get env failed" << std::endl; - return false; + std::cerr << "get env failed" << std::endl; + return false; } // Sets the ODBC version to ODBC 3.0. @@ -41,7 +43,7 @@ class DBConnector { ret = SQLAllocHandle(SQL_HANDLE_DBC, m_hEnviroment, &m_hDatabaseConnection); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { std::cerr << "get conn failed" << std::endl; - return false; + return false; } // connect // Connects to the database using SQLConnect. diff --git a/src/dbtest/src/sql_cntl_v2.cc b/src/dbtest/src/sql_cntl_v2.cc index 73236cbb..00d384b5 100644 --- a/src/dbtest/src/sql_cntl_v2.cc +++ b/src/dbtest/src/sql_cntl_v2.cc @@ -223,6 +223,9 @@ bool DBConnector::ExecWriteSql(int sql_id, const std::string& sql, TestResultSet SQLHSTMT m_hStatement; SQLHDBC m_hDatabaseConnection = DBConnector::conn_pool_[session_id - 1]; + //sleeep time_interval_ ms + usleep(1000 * time_interval_); + ret = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement); std::string err_info_stmt = DBConnector::SqlExecuteErr(session_id, sql_id, sql, "stmt", m_hStatement, ret, test_process_file); if (!err_info_stmt.empty()) { @@ -313,6 +316,9 @@ bool DBConnector::ExecReadSql2Int(int sql_id, const std::string& sql, TestResult // Get the expected result set list from test_result_set std::vector>> expected_result_set_list = test_result_set.ExpectedResultSetList(); + //sleeep time_interval_ ms + usleep(1000 * time_interval_); + // Allocate a statement handle: Allocate a new statement handle for the database connection using SQLAllocHandle function. ret = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement); // Check if allocating a statement handle was successful. If it fails, release the handle and return false. diff --git a/src/dbtest/src/sqltest.cc b/src/dbtest/src/sqltest.cc index 30d7a110..0d3dc4a7 100644 --- a/src/dbtest/src/sqltest.cc +++ b/src/dbtest/src/sqltest.cc @@ -24,6 +24,7 @@ DEFINE_int32(conn_pool_size, 6, "db_conn pool size"); DEFINE_string(isolation, "serializable", "transation isolation level: read-uncommitted read-committed repeatable-read serializable"); DEFINE_string(case_dir, "mysql", "test case dir name"); DEFINE_string(timeout, "20", "timeout"); +DEFINE_int32(exec_inteval, 0, "sql execution time interval"); // std::vector mutex_txn(5); // same as conn_pool_size std::vector mutex_txn(FLAGS_conn_pool_size); // same as conn_pool_size @@ -416,6 +417,7 @@ int main(int argc, char* argv[]) { std::cout << " user: " + FLAGS_user << std::endl; std::cout << " passwd: " + FLAGS_passwd << std::endl; std::cout << " isolation: " + FLAGS_isolation << std::endl; + std::cout << " exec_interval: " + FLAGS_exec_inteval << std::endl; // mutex for txn for(int i=0;i mutex_txn(FLAGS_conn_pool_size); // same as conn_pool_size @@ -373,6 +374,7 @@ int main(int argc, char* argv[]) { std::cout << " user: " + FLAGS_user << std::endl; std::cout << " passwd: " + FLAGS_passwd << std::endl; std::cout << " isolation: " + FLAGS_isolation << std::endl; + std::cout << " exec_interval: " + FLAGS_exec_inteval << std::endl; // mutex for txn for(int i=0;i