From c8a372ae7f9cd6437b0ae48528dee0ae9be70bbb Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Thu, 13 Oct 2022 01:11:37 +0200 Subject: [PATCH] test: db: Add test for row merging involving many versions The test verifies that a row which participated in earlier merge, and its cells lost on the timestamp check, behaves exactly like an empty row and can accept any mutation. This wasn't the case in versions prior to f006acc. Closes #11787 --- test/boost/mutation_test.cc | 20 ++++++++++++++++++++ test/lib/simple_schema.hh | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/test/boost/mutation_test.cc b/test/boost/mutation_test.cc index 2528db4cf9..508bc382db 100644 --- a/test/boost/mutation_test.cc +++ b/test/boost/mutation_test.cc @@ -1877,6 +1877,26 @@ SEASTAR_TEST_CASE(test_commutativity_and_associativity) { return make_ready_future<>(); } +SEASTAR_THREAD_TEST_CASE(test_row_merging) { + simple_schema table; + auto&& s = *table.schema(); + + row r1; + table.set_cell(r1, "v1"); + + row r2; + table.set_cell(r2, "v2"); + + row r3; + table.set_cell(r3, "v3"); + + r2.apply_monotonically(s, column_kind::regular_column, std::move(r1)); + + auto r3_backup = row(s, column_kind::regular_column, r3); + r1.apply_monotonically(s, column_kind::regular_column, std::move(r3)); + BOOST_REQUIRE(r1.equal(column_kind::regular_column, s, r3_backup, s)); +} + SEASTAR_TEST_CASE(test_continuity_merging) { return seastar::async([] { simple_schema table; diff --git a/test/lib/simple_schema.hh b/test/lib/simple_schema.hh index 26a4899d48..991715f3db 100644 --- a/test/lib/simple_schema.hh +++ b/test/lib/simple_schema.hh @@ -138,6 +138,15 @@ public: return t; } + api::timestamp_type set_cell(row& r, const sstring& v, api::timestamp_type t = api::missing_timestamp) { + if (t == api::missing_timestamp) { + t = new_timestamp(); + } + const column_definition& v_def = get_v_def(*_s); + r.apply_monotonically(v_def, atomic_cell::make_live(*v_def.type, t, serialized(v))); + return t; + } + std::pair get_value(const schema& s, const clustering_row& row) { const column_definition& v_def = get_v_def(s); auto cell = row.cells().find_cell(v_def.id);