diff --git a/configure.py b/configure.py index 82dc40e355..098d9af3f8 100755 --- a/configure.py +++ b/configure.py @@ -162,6 +162,7 @@ modes = { scylla_tests = [ 'tests/mutation_test', + 'tests/streamed_mutation_test', 'tests/schema_registry_test', 'tests/canonical_mutation_test', 'tests/range_test', diff --git a/test.py b/test.py index 0822d8c55b..921026d24d 100755 --- a/test.py +++ b/test.py @@ -69,7 +69,8 @@ boost_tests = [ 'snitch_reset_test', 'auth_test', 'idl_test', - 'range_tombstone_list_test' + 'range_tombstone_list_test', + 'streamed_mutation_test', ] other_tests = [ diff --git a/tests/streamed_mutation_test.cc b/tests/streamed_mutation_test.cc new file mode 100644 index 0000000000..12042848bd --- /dev/null +++ b/tests/streamed_mutation_test.cc @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2016 ScyllaDB + */ + +/* + * This file is part of Scylla. + * + * Scylla is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Scylla is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Scylla. If not, see . + */ + +#define BOOST_TEST_DYN_LINK + +#include +#include + +#include "mutation_source_test.hh" +#include "streamed_mutation.hh" + +#include "disk-error-handler.hh" + +thread_local disk_error_signal_type commit_error; +thread_local disk_error_signal_type general_disk_error; + +void check_order_of_fragments(streamed_mutation sm) +{ + stdx::optional previous; + position_in_partition::less_compare cmp(*sm.schema()); + auto mf = sm().get0(); + while (mf) { + if (previous) { + BOOST_REQUIRE(cmp(*previous, *mf)); + } + previous = mf->position(); + mf = sm().get0(); + } +} + +SEASTAR_TEST_CASE(test_mutation_from_streamed_mutation_from_mutation) { + return seastar::async([] { + for_each_mutation([&] (const mutation& m) { + auto get_sm = [&] { + return streamed_mutation_from_mutation(mutation(m)); + }; + + check_order_of_fragments(get_sm()); + auto mopt = mutation_from_streamed_mutation(get_sm()).get0(); + BOOST_REQUIRE(mopt); + BOOST_REQUIRE_EQUAL(m, *mopt); + }); + }); +} + +SEASTAR_TEST_CASE(test_mutation_merger) { + return seastar::async([] { + for_each_mutation_pair([&] (const mutation& m1, const mutation& m2, are_equal) { + if (m1.schema()->version() != m2.schema()->version()) { + return; + } + + auto m12 = m1; + m12.apply(m2); + + auto get_sm = [&] { + std::vector sms; + sms.emplace_back(streamed_mutation_from_mutation(mutation(m1))); + sms.emplace_back(streamed_mutation_from_mutation(mutation(m2.schema(), m1.decorated_key(), m2.partition()))); + return merge_mutations(std::move(sms)); + }; + + check_order_of_fragments(get_sm()); + auto mopt = mutation_from_streamed_mutation(get_sm()).get0(); + BOOST_REQUIRE(mopt); + BOOST_REQUIRE(m12.partition().difference(m1.schema(), mopt->partition()).empty()); + BOOST_REQUIRE(mopt->partition().difference(m1.schema(), m12.partition()).empty()); + }); + }); +} +