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
80 lines
3.1 KiB
C++
80 lines
3.1 KiB
C++
/*
|
|
* Copyright (C) 2021-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
#include <seastar/util/closeable.hh>
|
|
#include "db/virtual_table.hh"
|
|
#include "db/system_keyspace.hh"
|
|
#include "schema.hh"
|
|
|
|
#include "test/lib/mutation_source_test.hh"
|
|
|
|
#include <seastar/testing/thread_test_case.hh>
|
|
|
|
class memtable_filling_test_vt : public db::memtable_filling_virtual_table {
|
|
std::vector<mutation> _mutations;
|
|
public:
|
|
memtable_filling_test_vt(schema_ptr s, std::vector<mutation> mutations)
|
|
: memtable_filling_virtual_table(s)
|
|
, _mutations(std::move(mutations)) {}
|
|
|
|
future<> execute(std::function<void(mutation)> mutation_sink) override {
|
|
return with_timeout(db::no_timeout, do_for_each(_mutations, [mutation_sink = std::move(mutation_sink)] (const mutation& m) { mutation_sink(m); }));
|
|
}
|
|
};
|
|
|
|
class streaming_test_vt : public db::streaming_virtual_table {
|
|
schema_ptr _s;
|
|
std::vector<mutation> _mutations;
|
|
public:
|
|
streaming_test_vt(schema_ptr s, std::vector<mutation> mutations)
|
|
: streaming_virtual_table(s)
|
|
, _s(s)
|
|
, _mutations(std::move(mutations)) {}
|
|
|
|
virtual future<> execute(reader_permit permit, db::result_collector& rc) override {
|
|
return async([this, permit, &rc] {
|
|
auto mt = make_lw_shared<replica::memtable>(_s);
|
|
do_for_each(_mutations, [mt] (const mutation& m) {
|
|
mt->apply(m);
|
|
}).get();
|
|
auto rdr = mt->make_flat_reader(_s, permit);
|
|
auto close_rdr = deferred_close(rdr);
|
|
rdr.consume_pausable([&rc] (mutation_fragment_v2 mf) {
|
|
return rc.take(std::move(mf)).then([] { return stop_iteration::no; });
|
|
}).get();
|
|
});
|
|
}
|
|
};
|
|
|
|
SEASTAR_THREAD_TEST_CASE(test_memtable_filling_vt_as_mutation_source) {
|
|
std::unique_ptr<memtable_filling_test_vt> table; // Used to prolong table's life
|
|
|
|
run_mutation_source_tests([&table] (schema_ptr s, const std::vector<mutation>& mutations, gc_clock::time_point) -> mutation_source {
|
|
table = std::make_unique<memtable_filling_test_vt>(s, mutations);
|
|
return table->as_mutation_source();
|
|
});
|
|
}
|
|
|
|
SEASTAR_THREAD_TEST_CASE(test_streaming_vt_as_mutation_source) {
|
|
std::unique_ptr<streaming_test_vt> table; // Used to prolong table's life
|
|
|
|
run_mutation_source_tests([&table] (schema_ptr s, const std::vector<mutation>& mutations, gc_clock::time_point) -> mutation_source {
|
|
table = std::make_unique<streaming_test_vt>(s, mutations);
|
|
return mutation_source([ms = table->as_mutation_source()] (schema_ptr s,
|
|
reader_permit permit,
|
|
const dht::partition_range& pr,
|
|
const query::partition_slice& slice,
|
|
const io_priority_class& pc,
|
|
tracing::trace_state_ptr trace_state,
|
|
streamed_mutation::forwarding stream_fwd,
|
|
mutation_reader::forwarding) {
|
|
return ms.make_reader_v2(s, permit, pr, slice, pc, trace_state, stream_fwd, mutation_reader::forwarding::no);
|
|
});
|
|
}, false /* with_partition_range_forwarding */);
|
|
}
|