/* * Copyright (C) 2015-present ScyllaDB */ /* * SPDX-License-Identifier: AGPL-3.0-or-later */ #pragma once #include #include #include #include #include #include #include "db/view/view_update_generator.hh" #include "transport/messages/result_message_base.hh" #include "cql3/query_options_fwd.hh" #include "cql3/values.hh" #include "cql3/prepared_statements_cache.hh" #include "cql3/query_processor.hh" #include "bytes.hh" #include "schema.hh" #include "test/lib/eventually.hh" namespace replica { class database; } namespace db { class batchlog_manager; } namespace db::view { class view_builder; } namespace auth { class service; } namespace cql3 { class query_processor; } namespace service { class client_state; class migration_manager; } class not_prepared_exception : public std::runtime_error { public: not_prepared_exception(const cql3::prepared_cache_key_type& id) : std::runtime_error(format("Not prepared: {}", id)) {} }; namespace db { class config; } struct scheduling_groups { scheduling_group compaction_scheduling_group; scheduling_group memory_compaction_scheduling_group; scheduling_group streaming_scheduling_group; scheduling_group statement_scheduling_group; scheduling_group memtable_scheduling_group; scheduling_group memtable_to_cache_scheduling_group; scheduling_group gossip_scheduling_group; }; // Creating and destroying scheduling groups on each env setup and teardown // doesn't work because it messes up execution stages due to scheduling groups // having the same name but not having the same id on each run. So they are // created once and used across all envs. This method allows retrieving them to // be used in tests. // Not thread safe! future get_scheduling_groups(); class cql_test_config { public: seastar::shared_ptr db_config; // Scheduling groups are overwritten unconditionally, see get_scheduling_groups(). std::optional dbcfg; std::set disabled_features; std::optional qp_mcfg; cql_test_config(); cql_test_config(const cql_test_config&); cql_test_config(shared_ptr); ~cql_test_config(); }; class cql_test_env { public: virtual ~cql_test_env() {}; virtual future<::shared_ptr> execute_cql(sstring_view text) = 0; virtual future<::shared_ptr> execute_cql( sstring_view text, std::unique_ptr qo) = 0; /// Processes queries (which must be modifying queries) as a batch. virtual future<::shared_ptr> execute_batch( const std::vector& queries, std::unique_ptr qo) = 0; virtual future prepare(sstring query) = 0; virtual future<::shared_ptr> execute_prepared( cql3::prepared_cache_key_type id, std::vector values, db::consistency_level cl = db::consistency_level::ONE) = 0; virtual future<::shared_ptr> execute_prepared_with_qo( cql3::prepared_cache_key_type id, std::unique_ptr qo) = 0; virtual future> get_modification_mutations(const sstring& text) = 0; virtual future<> create_table(std::function schema_maker) = 0; virtual future<> require_keyspace_exists(const sstring& ks_name) = 0; virtual future<> require_table_exists(const sstring& ks_name, const sstring& cf_name) = 0; virtual future<> require_table_exists(std::string_view qualified_name) = 0; virtual future<> require_table_does_not_exist(const sstring& ks_name, const sstring& cf_name) = 0; virtual future<> require_column_has_value( const sstring& table_name, std::vector pk, std::vector ck, const sstring& column_name, data_value expected) = 0; virtual future<> stop() = 0; virtual service::client_state& local_client_state() = 0; virtual replica::database& local_db() = 0; virtual cql3::query_processor& local_qp() = 0; virtual distributed& db() = 0; virtual distributed & qp() = 0; virtual auth::service& local_auth_service() = 0; virtual db::view::view_builder& local_view_builder() = 0; virtual db::view::view_update_generator& local_view_update_generator() = 0; virtual service::migration_notifier& local_mnotifier() = 0; virtual sharded& migration_manager() = 0; virtual sharded& batchlog_manager() = 0; virtual sharded& gossiper() = 0; virtual future<> refresh_client_state() = 0; data_dictionary::database data_dictionary(); }; future<> do_with_cql_env(std::function(cql_test_env&)> func, cql_test_config = {}); future<> do_with_cql_env_thread(std::function func, cql_test_config = {}, thread_attributes thread_attr = {}); reader_permit make_reader_permit(cql_test_env&); // CQL test config with raft experimental feature enabled cql_test_config raft_cql_test_config();