26#ifndef ROUTER_SRC_MOCK_HOST_RESOLVER_SRC_MOCK_RESOLVER_H_
27#define ROUTER_SRC_MOCK_HOST_RESOLVER_SRC_MOCK_RESOLVER_H_
30#include <system_error>
40template <
typename ValueType>
81 explicit operator bool()
const {
return 0 != must_wait_; }
85 mutable uint64_t must_wait_{0};
93 if (
entry.fail_not_found_)
return "not-found";
94 if (
entry.error_)
return "error";
100 CachePolicy::UseIfPresent)
override {
103 log_error(
"MockResolver - unexpected resolve of '%s'", hostname.c_str());
107 auto &
entry = it->second;
111 entry.wait_.change(should_wait);
114 log_info(
"must_wait_for other request for '%s'", hostname.c_str());
115 std::this_thread::sleep_for(should_wait.
wait());
119 log_info(
"MockResolver - mocked resolve of host '%s', returning %s",
129 if (
entry.fail_not_found_) {
Definition: mock_resolver.h:71
std::chrono::seconds wait() const
Definition: mock_resolver.h:82
void operator()(uint64_t &value) const
Definition: mock_resolver.h:73
Definition: mock_resolver.h:43
Entry(const Entry &other)
Definition: mock_resolver.h:46
bool error_
Definition: mock_resolver.h:60
WaitableVariable< uint64_t > wait_
Definition: mock_resolver.h:64
bool log_
Definition: mock_resolver.h:61
Entry()
Definition: mock_resolver.h:45
std::vector< net::ip::address > addresses_
Definition: mock_resolver.h:62
bool fail_not_found_
Definition: mock_resolver.h:59
std::atomic< uint64_t > called_
Definition: mock_resolver.h:63
Entry & operator=(const Entry &other)
Definition: mock_resolver.h:48
Definition: mock_resolver.h:88
ResolveActions actions_
Definition: mock_resolver.h:140
ResolveHostResult resolve_host(const std::string &hostname, CachePolicy cache_policy=CachePolicy::UseIfPresent) override
Definition: mock_resolver.h:98
static std::string action(const Entry &entry)
Definition: mock_resolver.h:92
MockResolver(ResolveActions actions)
Definition: mock_resolver.h:90
Definition: interface.h:37
Definition: wait_variable.h:37
Definition: expected.h:286
std::string Hostname
Definition: host_cache.cc:45
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:51
Logging interface for using and extending the logging subsystem.
#define IMPORT_LOG_FUNCTIONS()
convenience macro to avoid common boilerplate
Definition: logging.h:331
std::map< Hostname, Entry > ResolveActions
Definition: mock_resolver.h:69
std::chrono::seconds seconds
Definition: authorize_manager.cc:70
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
@ NotFound
Deterministic negative outcome (NXDOMAIN, NODATA).
CachePolicy
Definition: common.h:40
HARNESS_EXPORT std::error_code make_error_code(ErrcResolveResult) noexcept
Definition: error_code.cc:56
std::error_code make_error_code(DynamicLoaderErrc ec)
make error_code from a DynamicLoaderErrc.
Definition: dynamic_loader.cc:97
Define std::hash<Gtid>.
Definition: gtid.h:355
unexpected(E) -> unexpected< E >
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2898
struct result result
Definition: result.h:34
Definition: completion_hash.h:35
#define log_info(msg,...)
Definition: tm_log.h:79
#define log_error(msg,...)
Definition: tm_log.h:87