test: move away from collection_mutation_view::with_deserialized()

Use the collection_mutation_view directly.
This commit is contained in:
Botond Dénes
2026-03-18 15:10:50 +02:00
parent 35a776d043
commit c76ab90fb2
5 changed files with 87 additions and 113 deletions

View File

@@ -396,9 +396,7 @@ SEASTAR_TEST_CASE(test_map_mutations) {
lazy_row& r = p.static_row();
auto i = r.find_cell(column.id);
BOOST_REQUIRE(i);
i->as_collection_mutation().with_deserialized(*my_map_type, [] (collection_mutation_view_description muts) {
BOOST_REQUIRE(muts.cells.size() == 3);
});
BOOST_REQUIRE(i->as_collection_mutation().size() == 3);
// FIXME: more strict tests
});
}
@@ -437,9 +435,7 @@ SEASTAR_TEST_CASE(test_set_mutations) {
lazy_row& r = p.static_row();
auto i = r.find_cell(column.id);
BOOST_REQUIRE(i);
i->as_collection_mutation().with_deserialized(*my_set_type, [] (collection_mutation_view_description muts) {
BOOST_REQUIRE(muts.cells.size() == 3);
});
BOOST_REQUIRE(i->as_collection_mutation().size() == 3);
// FIXME: more strict tests
});
}
@@ -479,9 +475,7 @@ SEASTAR_TEST_CASE(test_list_mutations) {
lazy_row& r = p.static_row();
auto i = r.find_cell(column.id);
BOOST_REQUIRE(i);
i->as_collection_mutation().with_deserialized(*my_list_type, [] (collection_mutation_view_description muts) {
BOOST_REQUIRE(muts.cells.size() == 4);
});
BOOST_REQUIRE(i->as_collection_mutation().size() == 4);
// FIXME: more strict tests
});
}
@@ -527,31 +521,25 @@ SEASTAR_THREAD_TEST_CASE(test_udt_mutations) {
lazy_row& r = p.static_row();
auto i = r.find_cell(column.id);
BOOST_REQUIRE(i);
i->as_collection_mutation().with_deserialized(*ut, [&] (collection_mutation_view_description m) {
// one cell for each field that has been set. mut3 and mut1 should have been merged
BOOST_REQUIRE(m.cells.size() == 3);
BOOST_REQUIRE(std::all_of(m.cells.begin(), m.cells.end(), [] (const auto& c) { return c.second.is_live(); }));
auto cmv = i->as_collection_mutation();
// one cell for each field that has been set. mut3 and mut1 should have been merged
BOOST_REQUIRE(cmv.size() == 3);
BOOST_REQUIRE(std::all_of(cmv.begin(), cmv.end(), [] (const auto& c) { return c.second.is_live(); }));
auto cells_equal = [] (const auto& c1, const auto& c2) {
return c1.first == c2.first && c1.second.value().linearize() == c2.second.value().linearize();
};
auto cells_equal = [] (const auto& c1, const auto& c2) {
return c1.first == c2.first && c1.second.value().linearize() == c2.second.value().linearize();
};
auto cell_a = std::make_pair(serialize_field_index(0), make_collection_member(int32_type, 0));
BOOST_REQUIRE(cells_equal(m.cells[0], std::pair<bytes_view, atomic_cell_view>(cell_a.first, cell_a.second)));
auto cell_a = std::make_pair(serialize_field_index(0), make_collection_member(int32_type, 0));
auto cell_c = std::make_pair(serialize_field_index(2), make_collection_member(long_type, int64_t(3)));
auto cell_d = std::make_pair(serialize_field_index(3), make_collection_member(utf8_type, "text"));
auto cell_c = std::make_pair(serialize_field_index(2), make_collection_member(long_type, int64_t(3)));
BOOST_REQUIRE(cells_equal(m.cells[1], std::pair<bytes_view, atomic_cell_view>(cell_c.first, cell_c.second)));
auto cell_d = std::make_pair(serialize_field_index(3), make_collection_member(utf8_type, "text"));
BOOST_REQUIRE(cells_equal(m.cells[2], std::pair<bytes_view, atomic_cell_view>(cell_d.first, cell_d.second)));
auto mm = m.materialize(*ut);
BOOST_REQUIRE(mm.cells.size() == 3);
BOOST_REQUIRE(cells_equal(mm.cells[0], cell_a));
BOOST_REQUIRE(cells_equal(mm.cells[1], cell_c));
BOOST_REQUIRE(cells_equal(mm.cells[2], cell_d));
});
auto it = cmv.begin();
BOOST_REQUIRE(cells_equal(*it, std::pair<bytes_view, atomic_cell_view>(cell_a.first, cell_a.second)));
++it;
BOOST_REQUIRE(cells_equal(*it, std::pair<bytes_view, atomic_cell_view>(cell_c.first, cell_c.second)));
++it;
BOOST_REQUIRE(cells_equal(*it, std::pair<bytes_view, atomic_cell_view>(cell_d.first, cell_d.second)));
}
// Verify that serializing and unserializing a large collection doesn't
@@ -1449,10 +1437,8 @@ SEASTAR_TEST_CASE(test_mutation_diff) {
BOOST_REQUIRE(m2_1.find_row(*s, ckey2));
BOOST_REQUIRE(m2_1.find_row(*s, ckey2)->find_cell(2));
auto cmv = m2_1.find_row(*s, ckey2)->find_cell(2)->as_collection_mutation();
cmv.with_deserialized(*my_set_type, [] (collection_mutation_view_description cm) {
BOOST_REQUIRE(cm.cells.size() == 1);
BOOST_REQUIRE(cm.cells.front().first == int32_type->decompose(3));
});
BOOST_REQUIRE(cmv.size() == 1);
BOOST_REQUIRE(cmv.begin()->first == managed_bytes_view(int32_type->decompose(3)));
mutation m12_1(s, partition_key::from_single_value(*s, "key1"));
m12_1.apply(m1);
@@ -1467,10 +1453,8 @@ SEASTAR_TEST_CASE(test_mutation_diff) {
BOOST_REQUIRE(!m1_2.find_row(*s, ckey2)->find_cell(0));
BOOST_REQUIRE(!m1_2.find_row(*s, ckey2)->find_cell(1));
cmv = m1_2.find_row(*s, ckey2)->find_cell(2)->as_collection_mutation();
cmv.with_deserialized(*my_set_type, [] (collection_mutation_view_description cm) {
BOOST_REQUIRE(cm.cells.size() == 1);
BOOST_REQUIRE(cm.cells.front().first == int32_type->decompose(2));
});
BOOST_REQUIRE(cmv.size() == 1);
BOOST_REQUIRE(cmv.begin()->first == managed_bytes_view(int32_type->decompose(2)));
mutation m12_2(s, partition_key::from_single_value(*s, "key1"));
m12_2.apply(m2);
@@ -2917,19 +2901,16 @@ private:
}
BOOST_REQUIRE_EQUAL(is_cell_purgeable(cell), OnlyPurged);
} else if (cdef.type->is_collection() || cdef.type->is_user_type()) {
auto cell = cell_or_collection.as_collection_mutation();
cell.with_deserialized(*cdef.type, [&] (collection_mutation_view_description m_view) {
BOOST_REQUIRE(m_view.tomb.timestamp == api::missing_timestamp || m_view.tomb.timestamp > tomb.tomb().timestamp ||
is_tombstone_purgeable(m_view.tomb) == OnlyPurged);
auto t = m_view.tomb;
t.apply(tomb.tomb());
for (const auto& [key, cell] : m_view.cells) {
if constexpr (OnlyPurged) {
BOOST_REQUIRE(!cell.is_covered_by(t, false));
}
BOOST_REQUIRE_EQUAL(is_cell_purgeable(cell), OnlyPurged);
auto m_view = cell_or_collection.as_collection_mutation();
auto t = m_view.tomb();
BOOST_REQUIRE(t.timestamp == api::missing_timestamp || t.timestamp > tomb.tomb().timestamp || is_tombstone_purgeable(t) == OnlyPurged);
t.apply(tomb.tomb());
for (const auto& [key, cell] : m_view) {
if constexpr (OnlyPurged) {
BOOST_REQUIRE(!cell.is_covered_by(t, false));
}
});
BOOST_REQUIRE_EQUAL(is_cell_purgeable(cell), OnlyPurged);
}
} else {
throw std::runtime_error(fmt::format("Cannot check cell {} of unknown type {}", cdef.name_as_text(), cdef.type->name()));
}

View File

@@ -229,11 +229,9 @@ private:
if (cdef.is_atomic()) {
check_timestamp(cell.as_atomic_cell(cdef).timestamp());
} else if (cdef.type->is_collection() || cdef.type->is_user_type()) {
cell.as_collection_mutation().with_deserialized(*cdef.type, [this] (collection_mutation_view_description mv) {
for (const auto& c: mv.cells) {
check_timestamp(c.second.timestamp());
}
});
for (const auto& [key, c] : cell.as_collection_mutation()) {
check_timestamp(c.timestamp());
}
} else {
BOOST_FAIL(fmt::format("Failed to verify column bucket id: column {} is of unknown type {}", cdef.name_as_text(), cdef.type->name()));
}

View File

@@ -2899,58 +2899,52 @@ SEASTAR_TEST_CASE(test_uncompressed_collections_read) {
const atomic_cell_or_collection* cell) {
BOOST_REQUIRE(def.is_multi_cell());
int idx = 0;
cell->as_collection_mutation().with_deserialized(*def.type, [&] (collection_mutation_view_description m_view) {
for (auto&& entry : m_view.cells) {
auto cmp = compare_unsigned(int32_type->decompose(int32_t(val[idx])), entry.first);
if (cmp != 0) {
BOOST_FAIL(format("Expected row with column {} having value {}, but it has value {}",
def.id,
int32_type->decompose(int32_t(val[idx])),
to_hex(entry.first)));
}
++idx;
for (const auto& entry : cell->as_collection_mutation()) {
auto cmp = compare_unsigned(int32_type->decompose(int32_t(val[idx])), to_bytes(entry.first));
if (cmp != 0) {
BOOST_FAIL(format("Expected row with column {} having value {}, but it has value {}",
def.id,
int32_type->decompose(int32_t(val[idx])),
to_hex(to_bytes(entry.first))));
}
});
++idx;
}
});
assertions.push_back([val = std::move(list_val)] (const column_definition& def,
const atomic_cell_or_collection* cell) {
BOOST_REQUIRE(def.is_multi_cell());
int idx = 0;
cell->as_collection_mutation().with_deserialized(*def.type, [&] (collection_mutation_view_description m_view) {
for (auto&& entry : m_view.cells) {
auto cmp = compare_unsigned(utf8_type->decompose(val[idx]), entry.second.value().linearize());
if (cmp != 0) {
BOOST_FAIL(format("Expected row with column {} having value {}, but it has value {}",
def.id,
utf8_type->decompose(val[idx]),
entry.second.value().linearize()));
}
++idx;
for (const auto& entry : cell->as_collection_mutation()) {
auto cmp = compare_unsigned(utf8_type->decompose(val[idx]), entry.second.value().linearize());
if (cmp != 0) {
BOOST_FAIL(format("Expected row with column {} having value {}, but it has value {}",
def.id,
utf8_type->decompose(val[idx]),
entry.second.value().linearize()));
}
});
++idx;
}
});
assertions.push_back([val = std::move(map_val)] (const column_definition& def,
const atomic_cell_or_collection* cell) {
BOOST_REQUIRE(def.is_multi_cell());
int idx = 0;
cell->as_collection_mutation().with_deserialized(*def.type, [&] (collection_mutation_view_description m_view) {
for (auto&& entry : m_view.cells) {
auto cmp1 = compare_unsigned(int32_type->decompose(int32_t(val[idx].first)), entry.first);
auto cmp2 = compare_unsigned(utf8_type->decompose(val[idx].second), entry.second.value().linearize());
if (cmp1 != 0 || cmp2 != 0) {
BOOST_FAIL(
format("Expected row with column {} having value ({}, {}), but it has value ({}, {})",
def.id,
int32_type->decompose(int32_t(val[idx].first)),
utf8_type->decompose(val[idx].second),
to_hex(entry.first),
entry.second.value().linearize()));
}
++idx;
for (const auto& entry : cell->as_collection_mutation()) {
auto cmp1 = compare_unsigned(int32_type->decompose(int32_t(val[idx].first)), to_bytes(entry.first));
auto cmp2 = compare_unsigned(utf8_type->decompose(val[idx].second), entry.second.value().linearize());
if (cmp1 != 0 || cmp2 != 0) {
BOOST_FAIL(
format("Expected row with column {} having value ({}, {}), but it has value ({}, {})",
def.id,
int32_type->decompose(int32_t(val[idx].first)),
utf8_type->decompose(val[idx].second),
to_hex(to_bytes(entry.first)),
entry.second.value().linearize()));
}
});
++idx;
}
});
return assertions;

View File

@@ -162,19 +162,18 @@ SEASTAR_TEST_CASE(datafile_generation_11) {
BOOST_REQUIRE(r->size() == 1);
auto cell = r->find_cell(set_col.id);
BOOST_REQUIRE(cell);
return cell->as_collection_mutation().with_deserialized(*set_col.type, [&] (collection_mutation_view_description m) {
return m.materialize(*set_col.type);
});
return cell->as_collection_mutation();
};
auto sstp = verify_mutation(env, env.make_sstable(s), mt, "key1", [&] (mutation_opt& mutation) {
auto verify_set = [&tomb] (const collection_mutation_description& m) {
BOOST_REQUIRE(bool(m.tomb) == true);
BOOST_REQUIRE(m.tomb == tomb);
BOOST_REQUIRE(m.cells.size() == 3);
BOOST_REQUIRE(m.cells[0].first == to_bytes("1"));
BOOST_REQUIRE(m.cells[1].first == to_bytes("2"));
BOOST_REQUIRE(m.cells[2].first == to_bytes("3"));
auto verify_set = [&tomb] (const collection_mutation_view m) {
BOOST_REQUIRE(bool(m.tomb()) == true);
BOOST_REQUIRE(m.tomb() == tomb);
BOOST_REQUIRE(m.size() == 3);
auto it = m.begin();
BOOST_REQUIRE(to_bytes(it->first) == to_bytes("1")); ++it;
BOOST_REQUIRE(to_bytes(it->first) == to_bytes("2")); ++it;
BOOST_REQUIRE(to_bytes(it->first) == to_bytes("3"));
};
auto& mp = mutation->partition();
@@ -183,9 +182,7 @@ SEASTAR_TEST_CASE(datafile_generation_11) {
BOOST_REQUIRE(scol);
// The static set
scol->as_collection_mutation().with_deserialized(*static_set_col.type, [&] (collection_mutation_view_description mut) {
verify_set(mut.materialize(*static_set_col.type));
});
verify_set(scol->as_collection_mutation());
// The clustered set
auto m = verifier(mutation);
@@ -194,9 +191,9 @@ SEASTAR_TEST_CASE(datafile_generation_11) {
verify_mutation(env, sstp, "key2", [&] (mutation_opt& mutation) {
auto m = verifier(mutation);
BOOST_REQUIRE(!m.tomb);
BOOST_REQUIRE(m.cells.size() == 1);
BOOST_REQUIRE(m.cells[0].first == to_bytes("4"));
BOOST_REQUIRE(!m.tomb());
BOOST_REQUIRE(m.size() == 1);
BOOST_REQUIRE(to_bytes(m.begin()->first) == to_bytes("4"));
}).get();
});
}

View File

@@ -302,10 +302,14 @@ match_collection(const row& row, const schema& s, bytes col, const tombstone& t)
BOOST_CHECK_NO_THROW(row.cell_at(cdef->id));
auto c = row.cell_at(cdef->id).as_collection_mutation();
return c.with_deserialized(*cdef->type, [&] (collection_mutation_view_description mut) {
BOOST_REQUIRE(mut.tomb == t);
return mut.materialize(*cdef->type);
});
BOOST_REQUIRE(c.tomb() == t);
collection_mutation_description result;
result.tomb = c.tomb();
auto& vtype = *dynamic_cast<const collection_type_impl&>(*cdef->type).value_comparator();
for (auto [key, cell] : c) {
result.cells.emplace_back(to_bytes(key), atomic_cell(vtype, cell));
}
return result;
}
template <status Status>