Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transaction commands to the testing framework #1933

Merged
merged 3 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
NONE,
WRITE,
rfdavid marked this conversation as resolved.
Show resolved Hide resolved
READ_ONLY,
COMMIT,
ROLLBACK
} transactionCmdType = TransactionCmdType::NONE;
};

// 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::WRITE;
return statement;
}
case TokenType::BEGIN_READ_ONLY_TRANSACTION: {
statement->transactionCmdType = TestStatement::TransactionCmdType::READ_ONLY;
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::WRITE:
conn.beginWriteTransaction();
continue;
break;
case TestStatement::TransactionCmdType::READ_ONLY:
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