From fc735de91c1f583e94866daae4b5c6c58a2af808 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Wed, 20 May 2015 21:50:08 -0400 Subject: [PATCH] tests: test range reader Signed-off-by: Glauber Costa --- tests/urchin/sstable_mutation_test.cc | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/urchin/sstable_mutation_test.cc b/tests/urchin/sstable_mutation_test.cc index cb529004f6..6904e009f5 100644 --- a/tests/urchin/sstable_mutation_test.cc +++ b/tests/urchin/sstable_mutation_test.cc @@ -356,3 +356,44 @@ SEASTAR_TEST_CASE(complex_sst3_k2) { return make_ready_future<>(); }); } + +future<> test_range_reads(const dht::token& min, const dht::token& max, std::vector& expected) { + return reusable_sst("tests/urchin/sstables/uncompressed", 1).then([min, max, &expected] (auto sstp) mutable { + auto s = uncompressed_schema(); + + auto count = make_lw_shared(0); + auto expected_size = expected.size(); + auto subs = sstp->read_range_rows(s, min, max, [&expected, count] (auto mutation) mutable { + BOOST_REQUIRE(bytes_view(expected.back()) == bytes_view(mutation.key())); + expected.pop_back(); + (*count)++; + return make_ready_future<>(); + }); + + auto sptr = make_lw_shared>(std::move(subs)); + return sptr->done().then([sptr, sstp, count, expected_size] { + BOOST_REQUIRE(*count == expected_size); + }); + }); +} + +SEASTAR_TEST_CASE(read_range) { + std::vector expected = { to_bytes("finna"), to_bytes("isak"), to_bytes("gustaf"), to_bytes("vinna") }; + return do_with(std::move(expected), [] (auto& expected) { + return test_range_reads(dht::minimum_token(), dht::maximum_token(), expected); + }); +} + +SEASTAR_TEST_CASE(read_partial_range) { + std::vector expected = { to_bytes("finna"), to_bytes("isak") }; + return do_with(std::move(expected), [] (auto& expected) { + return test_range_reads(dht::global_partitioner().get_token(key_view(bytes_view(expected.back()))), dht::maximum_token(), expected); + }); +} + +SEASTAR_TEST_CASE(read_partial_range_2) { + std::vector expected = { to_bytes("gustaf"), to_bytes("vinna") }; + return do_with(std::move(expected), [] (auto& expected) { + return test_range_reads(dht::minimum_token(), dht::global_partitioner().get_token(key_view(bytes_view(expected.front()))), expected); + }); +}