diff --git a/configure.py b/configure.py index f6e1ffd749..f3b1f8cbfa 100755 --- a/configure.py +++ b/configure.py @@ -100,6 +100,7 @@ modes = { } urchin_tests = [ + 'tests/urchin/mutation_test', 'tests/urchin/types_test', ] diff --git a/test.py b/test.py index ee6201c7d6..7cdd4f93fc 100755 --- a/test.py +++ b/test.py @@ -11,6 +11,7 @@ all_tests = [ 'sstring_test', 'output_stream_test', 'urchin/types_test', + 'urchin/mutation_test', ] last_len = 0 diff --git a/tests/urchin/mutation_test.cc b/tests/urchin/mutation_test.cc new file mode 100644 index 0000000000..6d4e84b50d --- /dev/null +++ b/tests/urchin/mutation_test.cc @@ -0,0 +1,41 @@ +/* + * Copyright 2015 Cloudius Systems + */ + +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE core + +#include +#include "core/sstring.hh" +#include "database.hh" + +static sstring some_keyspace("ks"); +static sstring some_column_family("cf"); + +static boost::any make_atomic_cell(bytes value) { + return atomic_cell{0, atomic_cell::live{ttl_opt{}, std::move(value)}}; +}; + +BOOST_AUTO_TEST_CASE(test_mutation_is_applied) { + auto s = make_lw_shared(some_keyspace, some_column_family, + std::vector({{"p1", utf8_type}}), + std::vector({{"c1", int32_type}}), + std::vector({{"r1", int32_type}}), + utf8_type + ); + + column_family cf(s); + + column_definition& r1_col = *s->get_column_definition("r1"); + partition_key key = to_bytes("key1"); + clustering_key c_key = s->clustering_key_type->decompose_value({int32_type->decompose(2)}); + + mutation m(key, s); + m.set_clustered_cell(c_key, r1_col, make_atomic_cell(int32_type->decompose(3))); + cf.apply(m); + + row& row = cf.find_or_create_row(key, c_key); + auto& cell = boost::any_cast(row[r1_col.id]); + BOOST_REQUIRE(cell.is_live()); + BOOST_REQUIRE(int32_type->equal(cell.as_live().value, int32_type->decompose(3))); +}