tests: extract streamed_mutation assertions

Signed-off-by: Paweł Dziepak <pdziepak@scylladb.com>
(cherry picked from commit 50469e5ef3)
This commit is contained in:
Paweł Dziepak
2016-07-19 14:45:36 +01:00
committed by Pekka Enberg
parent f0af5719d5
commit a39bec0e24
4 changed files with 82 additions and 35 deletions

View File

@@ -116,6 +116,16 @@ std::ostream& operator<<(std::ostream& os, const streamed_mutation& sm) {
return os;
}
std::ostream& operator<<(std::ostream& os, mutation_fragment::kind k)
{
switch (k) {
case mutation_fragment::kind::static_row: return os << "static row";
case mutation_fragment::kind::clustering_row: return os << "clustering row";
case mutation_fragment::kind::range_tombstone: return os << "range tombstone";
}
abort();
}
streamed_mutation streamed_mutation_from_mutation(mutation m)
{
class reader final : public streamed_mutation::impl {

View File

@@ -249,6 +249,8 @@ public:
}
};
std::ostream& operator<<(std::ostream&, mutation_fragment::kind);
class position_in_partition {
int _bound_weight = 0;
stdx::optional<clustering_key_prefix> _ck;

View File

@@ -110,3 +110,55 @@ mutation_opt_assertions assert_that(streamed_mutation_opt smo) {
return { std::move(mo) };
}
class streamed_mutation_assertions {
streamed_mutation _sm;
clustering_key::equality _ck_eq;
public:
streamed_mutation_assertions(streamed_mutation sm)
: _sm(std::move(sm)), _ck_eq(*_sm.schema()) { }
streamed_mutation_assertions& produces_static_row() {
auto mfopt = _sm().get0();
if (!mfopt) {
BOOST_FAIL("Expected static row, got end of stream");
}
if (mfopt->mutation_fragment_kind() != mutation_fragment::kind::static_row) {
BOOST_FAIL(sprint("Expected static row, got: %s", mfopt->mutation_fragment_kind()));
}
return *this;
}
streamed_mutation_assertions& produces(mutation_fragment::kind k, std::vector<int> ck_elements) {
std::vector<bytes> ck_bytes;
for (auto&& e : ck_elements) {
ck_bytes.emplace_back(int32_type->decompose(e));
}
auto ck = clustering_key_prefix::from_exploded(*_sm.schema(), std::move(ck_bytes));
auto mfopt = _sm().get0();
if (!mfopt) {
BOOST_FAIL(sprint("Expected mutation fragment %s, got end of stream", ck));
}
if (mfopt->mutation_fragment_kind() != k) {
BOOST_FAIL(sprint("Expected mutation fragment kind %s, got: %s", k, mfopt->mutation_fragment_kind()));
}
if (!_ck_eq(mfopt->key(), ck)) {
BOOST_FAIL(sprint("Expected key %s, got: %s", ck, mfopt->key()));
}
return *this;
}
streamed_mutation_assertions& produces_end_of_stream() {
auto mfopt = _sm().get0();
BOOST_REQUIRE(!mfopt);
if (mfopt) {
BOOST_FAIL(sprint("Expected end of stream, got: %s", mfopt->mutation_fragment_kind()));
}
return *this;
}
};
static inline streamed_mutation_assertions assert_that_stream(streamed_mutation sm)
{
return streamed_mutation_assertions(std::move(sm));
}

View File

@@ -41,6 +41,7 @@
#include "range.hh"
#include "partition_slice_builder.hh"
#include "sstables/date_tiered_compaction_strategy.hh"
#include "mutation_assertions.hh"
#include <stdio.h>
#include <ftw.h>
@@ -2596,43 +2597,25 @@ SEASTAR_TEST_CASE(test_wrong_range_tombstone_order) {
auto smopt = reader().get0();
BOOST_REQUIRE(smopt);
auto& sm = *smopt;
using kind = mutation_fragment::kind;
auto then_expect = [&] (kind k, std::vector<int> ck_elems) {
std::vector<bytes> ck_bytes;
for (auto&& e : ck_elems) {
ck_bytes.emplace_back(int32_type->decompose(e));
}
auto ck = clustering_key_prefix::from_exploded(*s, std::move(ck_bytes));
auto mfopt = sm().get0();
BOOST_REQUIRE(mfopt);
if (mfopt->mutation_fragment_kind() != k) {
abort();
}
BOOST_REQUIRE(mfopt->mutation_fragment_kind() == k);
BOOST_REQUIRE(ck_eq(mfopt->key(), ck));
};
then_expect(kind::range_tombstone, { 0 });
then_expect(kind::clustering_row, { 1 });
then_expect(kind::clustering_row, { 1, 1 });
then_expect(kind::clustering_row, { 1, 2 });
then_expect(kind::clustering_row, { 1, 2, 3 });
then_expect(kind::range_tombstone, { 1, 3 });
then_expect(kind::clustering_row, { 1, 3 });
then_expect(kind::clustering_row, { 1, 3, 4 });
then_expect(kind::clustering_row, { 1, 4 });
then_expect(kind::clustering_row, { 1, 4, 0 });
then_expect(kind::range_tombstone, { 2 });
then_expect(kind::range_tombstone, { 2, 1 });
then_expect(kind::range_tombstone, { 2, 1 });
then_expect(kind::range_tombstone, { 2, 2 });
then_expect(kind::range_tombstone, { 2, 2 });
auto mfopt = sm().get0();
BOOST_REQUIRE(!mfopt);
assert_that_stream(std::move(*smopt))
.produces(kind::range_tombstone, { 0 })
.produces(kind::clustering_row, { 1 })
.produces(kind::clustering_row, { 1, 1 })
.produces(kind::clustering_row, { 1, 2 })
.produces(kind::clustering_row, { 1, 2, 3 })
.produces(kind::range_tombstone, { 1, 3 })
.produces(kind::clustering_row, { 1, 3 })
.produces(kind::clustering_row, { 1, 3, 4 })
.produces(kind::clustering_row, { 1, 4 })
.produces(kind::clustering_row, { 1, 4, 0 })
.produces(kind::range_tombstone, { 2 })
.produces(kind::range_tombstone, { 2, 1 })
.produces(kind::range_tombstone, { 2, 1 })
.produces(kind::range_tombstone, { 2, 2 })
.produces(kind::range_tombstone, { 2, 2 })
.produces_end_of_stream();
smopt = reader().get0();
BOOST_REQUIRE(!smopt);