Skip to content

Commit

Permalink
Add transaction commands to the testing framework (#1933)
Browse files Browse the repository at this point in the history
This commit adds the following commands to the testing framework:
-BEGIN_READ_ONLY_TRANSACTION
-COMMIT
-ROLLBACK
  • Loading branch information
rfdavid committed Aug 16, 2023
1 parent d71c54f commit 33bd2be
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
12 changes: 9 additions & 3 deletions test/include/test_runner/test_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ struct TestStatement {
std::string query;
uint64_t numThreads = 4;
std::string encodedJoin;
uint64_t expectedNumTuples = 0;
bool expectedError = false;
std::string errorMessage;
bool expectedOk = false;
uint64_t expectedNumTuples = 0;
std::vector<std::string> expectedTuples;
std::string errorMessage;
bool enumerate = false;
bool checkOutputOrder = false;
bool isBeginWriteTransaction = false;
std::string expectedTuplesCSVFile;
enum class TransactionCmdType {
AUTO_COMMIT,
BEGIN_WRITE_TRX,
BEGIN_READ_TRX,
COMMIT,
ROLLBACK
} transactionCmdType = TransactionCmdType::AUTO_COMMIT;
};

// Test group is a collection of test cases in a single file.
Expand Down
17 changes: 11 additions & 6 deletions test/include/test_runner/test_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ namespace kuzu {
namespace testing {

enum class TokenType {
/* header */
BEGIN_WRITE_TRANSACTION,
// header
DATASET,
GROUP,
SKIP,
/* body */
// body
BEGIN_READ_ONLY_TRANSACTION,
BEGIN_WRITE_TRANSACTION,
BUFFER_POOL_SIZE,
CASE,
CHECK_ORDER,
COMMIT,
DEFINE,
DEFINE_STATEMENT_BLOCK,
EMPTY,
Expand All @@ -28,22 +30,25 @@ enum class TokenType {
LOG,
PARALLELISM,
RESULT,
ROLLBACK,
SEPARATOR,
STATEMENT,
_SKIP_LINE
};

const std::unordered_map<std::string, TokenType> tokenMap = {{"-GROUP", TokenType::GROUP},
{"-DATASET", TokenType::DATASET}, {"-CASE", TokenType::CASE},
{"-DATASET", TokenType::DATASET}, {"-CASE", TokenType::CASE}, {"-COMMIT", TokenType::COMMIT},
{"-CHECK_ORDER", TokenType::CHECK_ORDER}, {"-ENCODED_JOIN", TokenType::ENCODED_JOIN},
{"-LOG", TokenType::LOG}, {"-DEFINE_STATEMENT_BLOCK", TokenType::DEFINE_STATEMENT_BLOCK},
{"-ENUMERATE", TokenType::ENUMERATE},
{"-BEGIN_WRITE_TRANSACTION", TokenType::BEGIN_WRITE_TRANSACTION},
{"-BEGIN_READ_ONLY_TRANSACTION", TokenType::BEGIN_READ_ONLY_TRANSACTION},
{"-PARALLELISM", TokenType::PARALLELISM}, {"-SKIP", TokenType::SKIP},
{"-DEFINE", TokenType::DEFINE}, {"-STATEMENT", TokenType::STATEMENT},
{"-INSERT_STATEMENT_BLOCK", TokenType::INSERT_STATEMENT_BLOCK},
{"-BUFFER_POOL_SIZE", TokenType::BUFFER_POOL_SIZE}, {"]", TokenType::END_OF_STATEMENT_BLOCK},
{"----", TokenType::RESULT}, {"--", TokenType::SEPARATOR}, {"#", TokenType::EMPTY}};
{"-ROLLBACK", TokenType::ROLLBACK}, {"-BUFFER_POOL_SIZE", TokenType::BUFFER_POOL_SIZE},
{"]", TokenType::END_OF_STATEMENT_BLOCK}, {"----", TokenType::RESULT},
{"--", TokenType::SEPARATOR}, {"#", TokenType::EMPTY}};

class LogicToken {
public:
Expand Down
1 change: 0 additions & 1 deletion test/include/test_runner/test_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class TestRunner {
const std::string& query, main::Connection& conn);

private:
static void initializeConnection(TestStatement* statement, main::Connection& conn);
static bool testStatement(
TestStatement* statement, main::Connection& conn, std::string& databasePath);
static bool checkLogicalPlans(std::unique_ptr<main::PreparedStatement>& preparedStatement,
Expand Down
14 changes: 13 additions & 1 deletion test/test_runner/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,19 @@ TestStatement* TestParser::extractStatement(TestStatement* statement) {
break;
}
case TokenType::BEGIN_WRITE_TRANSACTION: {
statement->isBeginWriteTransaction = true;
statement->transactionCmdType = TestStatement::TransactionCmdType::BEGIN_WRITE_TRX;
return statement;
}
case TokenType::BEGIN_READ_ONLY_TRANSACTION: {
statement->transactionCmdType = TestStatement::TransactionCmdType::BEGIN_READ_TRX;
return statement;
}
case TokenType::COMMIT: {
statement->transactionCmdType = TestStatement::TransactionCmdType::COMMIT;
return statement;
}
case TokenType::ROLLBACK: {
statement->transactionCmdType = TestStatement::TransactionCmdType::ROLLBACK;
return statement;
}
case TokenType::EMPTY: {
Expand Down
28 changes: 18 additions & 10 deletions test/test_runner/test_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,29 @@ namespace testing {
void TestRunner::runTest(const std::vector<std::unique_ptr<TestStatement>>& statements,
Connection& conn, std::string& databasePath) {
for (auto& statement : statements) {
initializeConnection(statement.get(), conn);
if (statement->isBeginWriteTransaction) {
spdlog::info("DEBUG LOG: {}", statement->logMessage);
spdlog::info("QUERY: {}", statement->query);
conn.setMaxNumThreadForExec(statement->numThreads);
switch (statement->transactionCmdType) {
case TestStatement::TransactionCmdType::BEGIN_WRITE_TRX:
conn.beginWriteTransaction();
continue;
break;
case TestStatement::TransactionCmdType::BEGIN_READ_TRX:
conn.beginReadOnlyTransaction();
break;
case TestStatement::TransactionCmdType::COMMIT:
conn.commit();
break;
case TestStatement::TransactionCmdType::ROLLBACK:
conn.rollback();
break;
default:
ASSERT_TRUE(testStatement(statement.get(), conn, databasePath));
break;
}
ASSERT_TRUE(testStatement(statement.get(), conn, databasePath));
}
}

void TestRunner::initializeConnection(TestStatement* statement, Connection& conn) {
spdlog::info("DEBUG LOG: {}", statement->logMessage);
spdlog::info("QUERY: {}", statement->query);
conn.setMaxNumThreadForExec(statement->numThreads);
}

bool TestRunner::testStatement(
TestStatement* statement, Connection& conn, std::string& databasePath) {
std::unique_ptr<PreparedStatement> preparedStatement;
Expand Down

0 comments on commit 33bd2be

Please sign in to comment.