caipengbo commented on code in PR #2040:
URL: https://github.com/apache/kvrocks/pull/2040#discussion_r1463275912
##########
tests/cppunit/iterator_test.cc:
##########
@@ -363,4 +365,149 @@ TEST_F(SlotIteratorTest, LiveKeys) {
count++;
}
ASSERT_EQ(count, same_slot_keys.size());
+
+ engine::WALIterator wal_iter(storage_, slot_id);
+ count = 0;
+ for (wal_iter.Seek(start_seq + 1); wal_iter.Valid(); wal_iter.Next()) {
+ auto item = wal_iter.Item();
+ if (item.type == engine::WALItem::Type::kTypePut) {
+ auto [_, user_key] = ExtractNamespaceKey(item.key,
storage_->IsSlotIdEncoded());
+ ASSERT_EQ(slot_id, GetSlotIdFromKey(user_key.ToString())) <<
user_key.ToString();
+ count++;
+ }
+ }
+ ASSERT_EQ(count, same_slot_keys.size());
+}
+
+class WALIteratorTest : public TestBase {
+ protected:
+ explicit WALIteratorTest() = default;
+ ~WALIteratorTest() override = default;
+ void SetUp() override {}
+};
+
+TEST_F(WALIteratorTest, BasicType) {
+ auto start_seq = storage_->GetDB()->GetLatestSequenceNumber();
+ redis::String string(storage_, "test_ns0");
+ string.Set("a", "1");
+ string.MSet({{"b", "2"}, {"c", "3"}});
+ ASSERT_TRUE(string.Del("b").ok());
+
+ std::vector<std::string> put_keys, delete_keys;
+ auto expected_put_keys = {"a", "b", "c"};
+ auto expected_delete_keys = {"b"};
+
+ engine::WALIterator iter(storage_);
+
+ for (iter.Seek(start_seq + 1); iter.Valid(); iter.Next()) {
+ auto item = iter.Item();
+ switch (item.type) {
+ case engine::WALItem::Type::kTypePut: {
+ auto [ns, key] = ExtractNamespaceKey(item.key,
storage_->IsSlotIdEncoded());
+ ASSERT_EQ(ns.ToString(), "test_ns0");
+ put_keys.emplace_back(key.ToString());
+ break;
+ }
+ case engine::WALItem::Type::kTypeLogData: {
+ redis::WriteBatchLogData log_data;
+ ASSERT_TRUE(log_data.Decode(item.key).IsOK());
+ ASSERT_EQ(log_data.GetRedisType(), kRedisString);
+ break;
+ }
+ case engine::WALItem::Type::kTypeDelete: {
+ auto [ns, key] = ExtractNamespaceKey(item.key,
storage_->IsSlotIdEncoded());
+ ASSERT_EQ(ns.ToString(), "test_ns0");
+ delete_keys.emplace_back(key.ToString());
+ break;
+ }
+ default:
+ FAIL() << "Unexpected wal item type" << uint8_t(item.type);
+ }
+ }
+ ASSERT_TRUE(std::equal(expected_put_keys.begin(), expected_put_keys.end(),
put_keys.begin()));
+ ASSERT_TRUE(std::equal(expected_delete_keys.begin(),
expected_delete_keys.end(), delete_keys.begin()));
+}
+
+TEST_F(WALIteratorTest, ComplexType) {
Review Comment:
I wanted to implement all types of single tests, but I found that many of
them were repetitive and did not help for improving test coverage, so I chose
two categories of data types (`string` and `hash`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]