@@ -1255,6 +1255,66 @@ TEST_F(LdbCmdTest, CustomComparator) {
12551255 LDBCommandRunner::RunCommand (4 , argv, opts, LDBOptions (), &cfds));
12561256}
12571257
1258+ TEST_F (LdbCmdTest, DumpWal) {
1259+ Env* base_env = TryLoadCustomOrDefaultEnv ();
1260+ std::unique_ptr<Env> env (NewMemEnv (base_env));
1261+ Options opts;
1262+ opts.env = env.get ();
1263+ opts.create_if_missing = true ;
1264+
1265+ std::string dbname = test::PerThreadDBPath (env.get (), " ldb_cmd_test" );
1266+
1267+ DB* db = nullptr ;
1268+ ASSERT_OK (DB::Open (opts, dbname, &db));
1269+
1270+ // PutLogData record
1271+ WriteBatch batch;
1272+ batch.PutLogData (" xxx" );
1273+ WriteOptions wopts;
1274+ ASSERT_OK (db->Write (wopts, &batch));
1275+ batch.Clear ();
1276+
1277+ // PutBlobIndex record copied from db_blob_basic_test.cc
1278+ std::string blob_index;
1279+ constexpr uint64_t blob_file_number = 1000 ;
1280+ constexpr uint64_t offset = 1234 ;
1281+ constexpr uint64_t size = 5678 ;
1282+ BlobIndex::EncodeBlob (&blob_index, blob_file_number, offset, size,
1283+ kNoCompression );
1284+ constexpr uint64_t column_family_id = 0 ;
1285+ ASSERT_OK (WriteBatchInternal::PutBlobIndex (&batch, column_family_id,
1286+ " blob_index_key" , blob_index));
1287+ ASSERT_OK (db->Write (wopts, &batch));
1288+ batch.Clear ();
1289+
1290+ // TimedPut record
1291+ constexpr uint64_t write_unix_time = 1767123301 ; // 2025-12-30T19:35:01Z
1292+ batch.TimedPut (nullptr , " timed_put_key" , " v" , write_unix_time);
1293+ ASSERT_OK (db->Write (wopts, &batch));
1294+ batch.Clear ();
1295+
1296+ ASSERT_OK (db->Close ());
1297+ delete db;
1298+
1299+ string walfile_arg = string (" --walfile=" ) + dbname;
1300+ const char * const argv[] = {" ./ldb" , " dump_wal" , walfile_arg.c_str ()};
1301+ static const size_t argc = sizeof (argv) / sizeof (*argv);
1302+
1303+ // capture cout while running the command
1304+ std::stringstream captured_cout;
1305+ std::streambuf* original_cout_buffer = std::cout.rdbuf (captured_cout.rdbuf ());
1306+ int result =
1307+ LDBCommandRunner::RunCommand (argc, argv, opts, LDBOptions (), nullptr );
1308+ std::cout.rdbuf (original_cout_buffer);
1309+
1310+ // check the results of running dump_wal: log data must be included
1311+ string captured_output = captured_cout.str ();
1312+ ASSERT_EQ (0 , result) << " ldb output:\n\n " << captured_output;
1313+ ASSERT_NE (std::string::npos, captured_output.find (" LOG_DATA : 0x787878" ))
1314+ << " ldb output:\n\n "
1315+ << captured_output;
1316+ }
1317+
12581318} // namespace ROCKSDB_NAMESPACE
12591319
12601320int main (int argc, char ** argv) {
0 commit comments