mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-23 10:00:35 +00:00
The latter is pretty popular test/lib header that disseminates the
former one over whole lot of unit tests. The former, in turn, naturally
includes sstables.hh thus making tons of unrelated tests depend on
sstables class unused by them.
However, simple removal doesn't work, becase of local_shard_only bool
class definition in sstable_utils.hh used in simple_schema.hh. This
thing, in turn, is used in keys making helpers that don't belong to
sstable utils, so these are moved into simple_schema as well.
When done, this affects the mutation_source_test.hh, which needs the
local_shard_only bool class (and helps spreading the sstables.hh
throughout more unrelated tests) and a bunch of .cc test sources that
used sstable_utils.hh to indirectly include various headers of their
demand.
After patching, sstables.hh touches 2x times less tests. As a side
effect the sstables_manager.hh also becomes 2x times less dependent
on by tests.
Continuation of 9bdea110a6
Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
Closes #12240
105 lines
3.6 KiB
C++
105 lines
3.6 KiB
C++
/*
|
|
* Copyright (C) 2021-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#include "db/timeout_clock.hh"
|
|
|
|
#include <seastar/util/closeable.hh>
|
|
#include <seastar/testing/test_case.hh>
|
|
#include <seastar/testing/thread_test_case.hh>
|
|
#include "hashers.hh"
|
|
#include "xx_hasher.hh"
|
|
#include "gc_clock.hh"
|
|
#include "test/lib/simple_schema.hh"
|
|
#include "reader_concurrency_semaphore.hh"
|
|
|
|
bytes text_part1("sanity");
|
|
bytes text_part2("check");
|
|
bytes text_full("sanitycheck");
|
|
|
|
BOOST_AUTO_TEST_CASE(xx_hasher_sanity_check) {
|
|
xx_hasher hasher;
|
|
hasher.update(reinterpret_cast<const char*>(std::data(text_part1)), std::size(text_part1));
|
|
hasher.update(reinterpret_cast<const char*>(std::data(text_part2)), std::size(text_part2));
|
|
bytes hash = hasher.finalize();
|
|
bytes expected = from_hex("00000000000000001b1308f9e7c7dcf4");
|
|
BOOST_CHECK_EQUAL(hash, expected);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(md5_hasher_sanity_check) {
|
|
md5_hasher hasher;
|
|
hasher.update(reinterpret_cast<const char*>(std::data(text_part1)), std::size(text_part1));
|
|
hasher.update(reinterpret_cast<const char*>(std::data(text_part2)), std::size(text_part2));
|
|
bytes hash = hasher.finalize();
|
|
bytes expected = from_hex("a9221b2b5a53b9d9adf07f3305ed1a3e");
|
|
BOOST_CHECK_EQUAL(hash, expected);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(sha256_hasher_sanity_check) {
|
|
sha256_hasher hasher;
|
|
hasher.update(reinterpret_cast<const char*>(std::data(text_part1)), std::size(text_part1));
|
|
hasher.update(reinterpret_cast<const char*>(std::data(text_part2)), std::size(text_part2));
|
|
bytes hash = hasher.finalize();
|
|
bytes expected = from_hex("62bcb3e6160172824e1939116f48ae3680df989583c6d1bfbfa84fa9a080d003");
|
|
BOOST_REQUIRE_EQUAL(hash, expected);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(bytes_view_hasher_sanity_check) {
|
|
bytes_view_hasher hasher1;
|
|
hasher1.update(reinterpret_cast<const char*>(std::data(text_part1)), std::size(text_part1));
|
|
hasher1.update(reinterpret_cast<const char*>(std::data(text_part2)), std::size(text_part2));
|
|
size_t hash1 = hasher1.finalize();
|
|
|
|
bytes_view_hasher hasher2;
|
|
hasher2.update(reinterpret_cast<const char*>(std::data(text_full)), std::size(text_full));
|
|
size_t hash2 = hasher2.finalize();
|
|
|
|
BOOST_REQUIRE_EQUAL(hash1, hash2);
|
|
}
|
|
|
|
SEASTAR_THREAD_TEST_CASE(mutation_fragment_sanity_check) {
|
|
reader_concurrency_semaphore semaphore(reader_concurrency_semaphore::no_limits{}, __FILE__);
|
|
auto stop_semaphore = deferred_stop(semaphore);
|
|
simple_schema s;
|
|
auto permit = semaphore.make_tracking_only_permit(s.schema().get(), "test", db::no_timeout);
|
|
gc_clock::time_point ts(gc_clock::duration(1234567890000));
|
|
|
|
auto check_hash = [&] (const mutation_fragment& mf, uint64_t expected) {
|
|
xx_hasher h;
|
|
feed_hash(h, mf, *s.schema());
|
|
auto v = h.finalize_uint64();
|
|
BOOST_REQUIRE_EQUAL(v, expected);
|
|
};
|
|
|
|
|
|
|
|
{
|
|
mutation_fragment f(*s.schema(), permit, partition_start{ s.make_pkey(0), {} });
|
|
check_hash(f, 0xfb4f06dd4de434c2ull);
|
|
}
|
|
|
|
{
|
|
mutation_fragment f(*s.schema(), permit, partition_start{ s.make_pkey(1), tombstone(42, ts) });
|
|
check_hash(f, 0xcd9299d785a70d8dull);
|
|
}
|
|
|
|
{
|
|
mutation_fragment f(*s.schema(), permit, s.make_row(permit, s.make_ckey(1), "abc"));
|
|
check_hash(f, 0x8ae8c4860ca108bbull);
|
|
}
|
|
|
|
{
|
|
mutation_fragment f(*s.schema(), permit, s.make_static_row(permit, "def"));
|
|
check_hash(f, 0x2b8119e27581bbeeull);
|
|
}
|
|
|
|
{
|
|
mutation_fragment f(*s.schema(), permit, s.make_range_tombstone(query::clustering_range::make(s.make_ckey(2), s.make_ckey(3)), ts));
|
|
check_hash(f, 0x5092daca1b27ea26ull);
|
|
}
|
|
}
|