1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-28 20:02:00 +03:00

Introduce set_provider_factory() method for server_state

This allows injecting an application allocated provider into
server_state.

After this virtual provider getter is unnecessary. Made the getter
normal method and fixed unit tests accordingly.
This commit is contained in:
Denis Protivensky
2021-12-14 20:28:56 +03:00
parent 13442a04d8
commit 9bd26d49c5
11 changed files with 302 additions and 308 deletions

View File

@ -245,12 +245,26 @@ namespace wsrep
rollback_mode)
, mutex_()
, cond_()
, provider_(*this)
{ }
wsrep::mock_provider& provider() const WSREP_OVERRIDE
{ return provider_; }
, provider_()
{
set_provider_factory([&](wsrep::server_state&,
const std::string&,
const std::string&,
const wsrep::provider::services&)
{
// The provider object is destroyed upon server state
// destruction, so using a raw pointer is safe.
provider_ = new wsrep::mock_provider(*this);
return std::unique_ptr<wsrep::provider>(provider_);
});
assert(load_provider("mock", "") == 0);
assert(provider_ != nullptr);
}
wsrep::mock_provider& mock_provider() const
{
return *provider_;
}
// mock connected state for tests without overriding the connect()
// method.
int mock_connect(const std::string& own_id,
@ -295,7 +309,7 @@ namespace wsrep
private:
wsrep::default_mutex mutex_;
wsrep::default_condition_variable cond_;
mutable wsrep::mock_provider provider_;
wsrep::mock_provider* provider_;
};
}