Bug fixes

This commit is contained in:
2025-08-14 16:27:28 -04:00
parent 7ca50350e7
commit 52381467f7
2 changed files with 63 additions and 48 deletions

View File

@@ -131,8 +131,8 @@ public:
*/ */
explicit CommitRequest(size_t arena_size = 4096) explicit CommitRequest(size_t arena_size = 4096)
: arena_(arena_size), : arena_(arena_size),
preconditions_(ArenaStlAllocator<PreconditionParseState>(&arena_)), preconditions_(ArenaStlAllocator<Precondition>(&arena_)),
operations_(ArenaStlAllocator<OperationParseState>(&arena_)), operations_(ArenaStlAllocator<Operation>(&arena_)),
parser_context_(&arena_) {} parser_context_(&arena_) {}
/** /**

View File

@@ -12,7 +12,7 @@ TEST_CASE("CommitRequest basic parsing") {
"read_version": 12345 "read_version": 12345
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.request_id().has_value()); REQUIRE(request.request_id().has_value());
REQUIRE(request.request_id().value() == "test123"); REQUIRE(request.request_id().value() == "test123");
REQUIRE(request.leader_id() == "leader456"); REQUIRE(request.leader_id() == "leader456");
@@ -32,7 +32,7 @@ TEST_CASE("CommitRequest basic parsing") {
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.preconditions().size() == 1); REQUIRE(request.preconditions().size() == 1);
REQUIRE(request.preconditions()[0].type == Precondition::Type::PointRead); REQUIRE(request.preconditions()[0].type == Precondition::Type::PointRead);
REQUIRE(request.preconditions()[0].version == 12340); REQUIRE(request.preconditions()[0].version == 12340);
@@ -57,16 +57,16 @@ TEST_CASE("CommitRequest basic parsing") {
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.operations().size() == 2); REQUIRE(request.operations().size() == 2);
REQUIRE(request.operations()[0].type == Operation::Type::Write); REQUIRE(request.operations()[0].type == Operation::Type::Write);
REQUIRE(request.operations()[0].param1 == "test"); REQUIRE(request.operations()[0].param1 == "test"); // key
REQUIRE(request.operations()[0].param2 == "value"); REQUIRE(request.operations()[0].param2 == "value"); // value
REQUIRE(request.operations()[1].type == Operation::Type::Delete); REQUIRE(request.operations()[1].type == Operation::Type::Delete);
REQUIRE(request.operations()[1].param1 == "test2"); REQUIRE(request.operations()[1].param1 == "test2"); // key
REQUIRE(request.operations()[1].param2 == ""); REQUIRE(request.operations()[1].param2 == ""); // unused for delete
} }
SUBCASE("Invalid JSON") { SUBCASE("Invalid JSON") {
@@ -75,7 +75,8 @@ TEST_CASE("CommitRequest basic parsing") {
"read_version": "not_a_number" "read_version": "not_a_number"
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
SUBCASE("Missing required leader_id") { SUBCASE("Missing required leader_id") {
@@ -84,7 +85,8 @@ TEST_CASE("CommitRequest basic parsing") {
"read_version": 12345 "read_version": 12345
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE_FALSE(request.is_parse_complete()); REQUIRE_FALSE(request.is_parse_complete());
} }
@@ -94,7 +96,8 @@ TEST_CASE("CommitRequest basic parsing") {
"leader_id": "leader456" "leader_id": "leader456"
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE_FALSE(request.is_parse_complete()); REQUIRE_FALSE(request.is_parse_complete());
} }
@@ -105,7 +108,8 @@ TEST_CASE("CommitRequest basic parsing") {
"read_version": 12345 "read_version": 12345
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE_FALSE(request.is_parse_complete()); REQUIRE_FALSE(request.is_parse_complete());
} }
@@ -114,7 +118,8 @@ TEST_CASE("CommitRequest basic parsing") {
"request_id": "test123" "request_id": "test123"
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE_FALSE(request.is_parse_complete()); REQUIRE_FALSE(request.is_parse_complete());
} }
@@ -124,7 +129,7 @@ TEST_CASE("CommitRequest basic parsing") {
"read_version": 12345 "read_version": 12345
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.is_parse_complete()); REQUIRE(request.is_parse_complete());
REQUIRE_FALSE(request.request_id().has_value()); REQUIRE_FALSE(request.request_id().has_value());
REQUIRE(request.leader_id() == "leader456"); REQUIRE(request.leader_id() == "leader456");
@@ -147,7 +152,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.is_parse_complete()); REQUIRE(request.is_parse_complete());
} }
@@ -162,8 +167,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
REQUIRE_FALSE(request.is_parse_complete()); request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
SUBCASE("Valid point_read precondition - empty key") { SUBCASE("Valid point_read precondition - empty key") {
@@ -178,7 +183,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.is_parse_complete()); REQUIRE(request.is_parse_complete());
} }
@@ -189,13 +194,22 @@ TEST_CASE("CommitRequest precondition and operation validation") {
"preconditions": [ "preconditions": [
{ {
"type": "range_read", "type": "range_read",
"begin": "dGVzdA==", "version": 12340,
"end": "dGVzdFo=" "begin": "",
"end": ""
} }
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); bool parse_result =
request.parse_json(const_cast<char *>(json.data()), json.size());
INFO("Parse result: " << parse_result);
INFO("Parse complete: " << request.is_parse_complete());
INFO("Parse error: " << request.has_parse_error());
INFO("Leader ID: '" << request.leader_id() << "'");
INFO("Read version: " << request.read_version());
REQUIRE(parse_result);
REQUIRE(request.is_parse_complete()); REQUIRE(request.is_parse_complete());
} }
@@ -212,7 +226,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.is_parse_complete()); REQUIRE(request.is_parse_complete());
} }
@@ -228,8 +242,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
REQUIRE_FALSE(request.is_parse_complete()); request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
SUBCASE("Invalid range_read precondition - missing end") { SUBCASE("Invalid range_read precondition - missing end") {
@@ -244,8 +258,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
REQUIRE_FALSE(request.is_parse_complete()); request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
SUBCASE("Valid write operation") { SUBCASE("Valid write operation") {
@@ -261,7 +275,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.is_parse_complete()); REQUIRE(request.is_parse_complete());
} }
@@ -278,7 +292,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.is_parse_complete()); REQUIRE(request.is_parse_complete());
} }
@@ -294,8 +308,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
REQUIRE_FALSE(request.is_parse_complete()); request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
SUBCASE("Invalid write operation - missing value") { SUBCASE("Invalid write operation - missing value") {
@@ -310,8 +324,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
REQUIRE_FALSE(request.is_parse_complete()); request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
SUBCASE("Valid delete operation") { SUBCASE("Valid delete operation") {
@@ -326,7 +340,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.is_parse_complete()); REQUIRE(request.is_parse_complete());
} }
@@ -341,8 +355,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
REQUIRE_FALSE(request.is_parse_complete()); request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
SUBCASE("Valid range_delete operation") { SUBCASE("Valid range_delete operation") {
@@ -358,7 +372,7 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE(request.parse_json(json.data(), json.size())); REQUIRE(request.parse_json(const_cast<char *>(json.data()), json.size()));
REQUIRE(request.is_parse_complete()); REQUIRE(request.is_parse_complete());
} }
@@ -374,8 +388,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
REQUIRE_FALSE(request.is_parse_complete()); request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
SUBCASE("Invalid range_delete operation - missing end") { SUBCASE("Invalid range_delete operation - missing end") {
@@ -390,8 +404,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
REQUIRE_FALSE(request.is_parse_complete()); request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
SUBCASE("Mixed valid and invalid operations") { SUBCASE("Mixed valid and invalid operations") {
@@ -410,8 +424,8 @@ TEST_CASE("CommitRequest precondition and operation validation") {
] ]
})"; })";
REQUIRE_FALSE(request.parse_json(json.data(), json.size())); REQUIRE_FALSE(
REQUIRE_FALSE(request.is_parse_complete()); request.parse_json(const_cast<char *>(json.data()), json.size()));
} }
} }
@@ -538,17 +552,18 @@ TEST_CASE("CommitRequest streaming parsing") {
// Verify precondition was parsed correctly // Verify precondition was parsed correctly
REQUIRE(request.preconditions()[0].type == Precondition::Type::PointRead); REQUIRE(request.preconditions()[0].type == Precondition::Type::PointRead);
REQUIRE(request.preconditions()[0].version == 98764); REQUIRE(request.preconditions()[0].version == 98764);
REQUIRE(request.preconditions()[0].begin == "testKey"); REQUIRE(request.preconditions()[0].begin ==
"testKey"); // key stored in begin for point_read
REQUIRE(request.preconditions()[0].end == ""); REQUIRE(request.preconditions()[0].end == "");
// Verify operations were parsed correctly // Verify operations were parsed correctly
REQUIRE(request.operations()[0].type == Operation::Type::Write); REQUIRE(request.operations()[0].type == Operation::Type::Write);
REQUIRE(request.operations()[0].param1 == "testKey"); REQUIRE(request.operations()[0].param1 == "testKey"); // key
REQUIRE(request.operations()[0].param2 == "testValue"); REQUIRE(request.operations()[0].param2 == "testValue"); // value
REQUIRE(request.operations()[1].type == Operation::Type::Delete); REQUIRE(request.operations()[1].type == Operation::Type::Delete);
REQUIRE(request.operations()[1].param1 == "deleteKey"); REQUIRE(request.operations()[1].param1 == "deleteKey"); // key
REQUIRE(request.operations()[1].param2 == ""); REQUIRE(request.operations()[1].param2 == ""); // unused for delete
} }
SUBCASE("Streaming parse error handling") { SUBCASE("Streaming parse error handling") {