Make codebase consistent with design.md
This commit is contained in:
@@ -17,7 +17,8 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
REQUIRE(request.request_id().has_value());
|
||||
REQUIRE(request.request_id().value() == "test123");
|
||||
REQUIRE(request.leader_id() == "leader456");
|
||||
@@ -38,7 +39,8 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
REQUIRE(request.preconditions().size() == 1);
|
||||
REQUIRE(request.preconditions()[0].type == Precondition::Type::PointRead);
|
||||
REQUIRE(request.preconditions()[0].version == 12340);
|
||||
@@ -64,7 +66,8 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
REQUIRE(request.operations().size() == 2);
|
||||
|
||||
REQUIRE(request.operations()[0].type == Operation::Type::Write);
|
||||
@@ -82,8 +85,9 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"read_version": "not_a_number"
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Missing required leader_id") {
|
||||
@@ -92,8 +96,9 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"read_version": 12345
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
// Check completion based on required fields
|
||||
REQUIRE(request.leader_id().empty());
|
||||
}
|
||||
@@ -104,8 +109,9 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"leader_id": "leader456"
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
// Check completion based on required fields
|
||||
REQUIRE(!parser.has_read_version_been_set());
|
||||
}
|
||||
@@ -117,8 +123,9 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"read_version": 12345
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
// Check completion based on required fields
|
||||
REQUIRE(request.leader_id().empty());
|
||||
}
|
||||
@@ -128,8 +135,9 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
"request_id": "test123"
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
// Check completion based on required fields
|
||||
bool missing_leader = request.leader_id().empty();
|
||||
bool missing_version = !parser.has_read_version_been_set();
|
||||
@@ -143,7 +151,8 @@ TEST_CASE("CommitRequest basic parsing") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
REQUIRE_FALSE(request.request_id().has_value());
|
||||
REQUIRE(request.leader_id() == "leader456");
|
||||
REQUIRE(request.read_version() == 12345);
|
||||
@@ -167,7 +176,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Invalid point_read precondition - missing key") {
|
||||
@@ -181,8 +191,9 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Valid point_read precondition - empty key") {
|
||||
@@ -198,7 +209,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Valid range_read precondition") {
|
||||
@@ -215,9 +227,10 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
bool parse_result =
|
||||
auto parse_result =
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size());
|
||||
INFO("Parse result: " << parse_result);
|
||||
INFO("Parse result: " << (parse_result ==
|
||||
CommitRequestParser::ParseResult::Success));
|
||||
INFO("Parse error: " << parser.has_parse_error());
|
||||
const char *error_msg = parser.get_parse_error();
|
||||
INFO("Parse error message: " << (error_msg ? std::string(error_msg)
|
||||
@@ -225,7 +238,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
INFO("Leader ID: '" << request.leader_id() << "'");
|
||||
INFO("Read version: " << request.read_version());
|
||||
|
||||
REQUIRE(parse_result);
|
||||
REQUIRE(parse_result == CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Valid range_read precondition - empty begin/end") {
|
||||
@@ -242,7 +255,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Invalid range_read precondition - missing begin") {
|
||||
@@ -257,8 +271,9 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Invalid range_read precondition - missing end") {
|
||||
@@ -273,8 +288,9 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Valid write operation") {
|
||||
@@ -291,7 +307,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Valid write operation - empty key and value") {
|
||||
@@ -308,7 +325,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Invalid write operation - missing key") {
|
||||
@@ -323,8 +341,9 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Invalid write operation - missing value") {
|
||||
@@ -339,8 +358,9 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Valid delete operation") {
|
||||
@@ -356,7 +376,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Invalid delete operation - missing key") {
|
||||
@@ -370,8 +391,9 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Valid range_delete operation") {
|
||||
@@ -388,7 +410,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
})";
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Invalid range_delete operation - missing begin") {
|
||||
@@ -403,8 +426,9 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Invalid range_delete operation - missing end") {
|
||||
@@ -419,8 +443,9 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
|
||||
SUBCASE("Mixed valid and invalid operations") {
|
||||
@@ -439,8 +464,9 @@ TEST_CASE("CommitRequest precondition and operation validation") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE_FALSE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) !=
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,7 +487,8 @@ TEST_CASE("CommitRequest memory management") {
|
||||
]
|
||||
})";
|
||||
|
||||
REQUIRE(parser.parse(request, json.data(), json.size()));
|
||||
REQUIRE(parser.parse(request, json.data(), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
|
||||
// Check that arena allocation worked
|
||||
REQUIRE(request.total_allocated() > 0);
|
||||
@@ -669,7 +696,8 @@ TEST_CASE("CommitRequest arena debug dump") {
|
||||
std::string json = weaseldb::test_data::COMPLEX_JSON;
|
||||
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
|
||||
// Verify the request was parsed correctly
|
||||
REQUIRE(request.request_id().has_value());
|
||||
@@ -725,7 +753,8 @@ TEST_CASE("CommitRequest arena debug dump") {
|
||||
// Parse complex JSON
|
||||
std::string json = weaseldb::test_data::COMPLEX_JSON;
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
|
||||
// Debug dump after parsing
|
||||
std::ostringstream used_output;
|
||||
@@ -746,7 +775,8 @@ TEST_CASE("CommitRequest arena debug dump") {
|
||||
// Parse complex JSON first
|
||||
std::string json = weaseldb::test_data::COMPLEX_JSON;
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
|
||||
size_t allocated_before_reset = request.total_allocated();
|
||||
size_t used_before_reset = request.used_bytes();
|
||||
@@ -789,7 +819,8 @@ TEST_CASE("CommitRequest arena debug dump") {
|
||||
// Parse COMPLEX_JSON to get diverse content in memory
|
||||
std::string json = weaseldb::test_data::COMPLEX_JSON;
|
||||
REQUIRE(
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()));
|
||||
parser.parse(request, const_cast<char *>(json.data()), json.size()) ==
|
||||
CommitRequestParser::ParseResult::Success);
|
||||
|
||||
// Test different content visualization options
|
||||
std::ostringstream no_content;
|
||||
|
||||
Reference in New Issue
Block a user