From 283f52549b43f509cc59b89f7cfdf70ffbe0a172 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Thu, 26 Mar 2015 10:21:03 +0100 Subject: [PATCH] test: cql: Add test for results order with variable length keys --- tests/urchin/cql_query_test.cc | 29 +++++++++++++++++++++++++++++ tests/urchin/cql_test_env.hh | 10 ++++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/urchin/cql_query_test.cc b/tests/urchin/cql_query_test.cc index 0e3ab85edb..ec94b7eba9 100644 --- a/tests/urchin/cql_query_test.cc +++ b/tests/urchin/cql_query_test.cc @@ -7,6 +7,7 @@ #include "cql3/query_options.hh" #include "core/distributed.hh" #include "tests/test-utils.hh" +#include "tests/urchin/cql_test_env.hh" struct conversation_state { service::storage_proxy proxy; @@ -420,6 +421,34 @@ SEASTAR_TEST_CASE(test_range_queries) { }); } +SEASTAR_TEST_CASE(test_ordering_of_composites_with_variable_length_components) { + return do_with_cql_env([] (auto& e) { + return e.create_table([](auto ks) { + return schema(ks, "cf", + {{"k", bytes_type}}, + // We need more than one clustering column so that the single-element tuple format optimisation doesn't kick in + {{"c0", bytes_type}, {"c1", bytes_type}}, + {{"v", bytes_type}}, + {}, + utf8_type); + }).then([&e] { + return e.execute_cql("update cf set v = 0x01 where k = 0x00 and c0 = 0x0001 and c1 = 0x00;").discard_result(); + }).then([&e] { + return e.execute_cql("update cf set v = 0x02 where k = 0x00 and c0 = 0x03 and c1 = 0x00;").discard_result(); + }).then([&e] { + return e.execute_cql("update cf set v = 0x03 where k = 0x00 and c0 = 0x035555 and c1 = 0x00;").discard_result(); + }).then([&e] { + return e.execute_cql("update cf set v = 0x04 where k = 0x00 and c0 = 0x05 and c1 = 0x00;").discard_result(); + }).then([&e] { + return e.execute_cql("select v from cf where k = 0x00 allow filtering;").then([](auto msg) { + assert_that(msg).is_rows().with_rows({ + {from_hex("01")}, {from_hex("02")}, {from_hex("03")}, {from_hex("04")} + }); + }); + }); + }); +} + SEASTAR_TEST_CASE(test_map_insert_update) { auto db = make_shared>(); auto state = make_shared(*db, ks_name); diff --git a/tests/urchin/cql_test_env.hh b/tests/urchin/cql_test_env.hh index a42bae9f57..0a6c64ff95 100644 --- a/tests/urchin/cql_test_env.hh +++ b/tests/urchin/cql_test_env.hh @@ -111,3 +111,13 @@ future<::shared_ptr> make_env_for_test() { }); }); } + +template +static inline +future<> do_with_cql_env(Func&& func) { + return make_env_for_test().then([func = std::forward(func)] (auto e) { + return func(*e).finally([e] { + return e->stop().finally([e] {}); + }); + }); +}