More configuration database unit testing improvements

This commit is contained in:
sfc-gh-tclinkenbeard 2021-05-16 17:25:41 -07:00
parent 8b58eacf8b
commit 1941d0eab3
6 changed files with 69 additions and 14 deletions

View File

@ -21,6 +21,7 @@ set(FDBCLIENT_SRCS
CommitTransaction.h
ConfigKnobs.cpp
ConfigKnobs.h
ConfigTransactionInterface.cpp
ConfigTransactionInterface.h
CoordinationInterface.h
DatabaseBackupAgent.actor.cpp

View File

@ -0,0 +1,45 @@
/*
* ConfigTransactionInterface.cpp
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "fdbclient/ConfigTransactionInterface.h"
#include "fdbclient/CoordinationInterface.h"
#include "flow/IRandom.h"
ConfigTransactionInterface::ConfigTransactionInterface() : _id(deterministicRandom()->randomUniqueID()) {}
void ConfigTransactionInterface::setupWellKnownEndpoints() {
getVersion.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GETVERSION, TaskPriority::Coordination);
get.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GET, TaskPriority::Coordination);
getRange.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GETRANGE, TaskPriority::Coordination);
commit.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_COMMIT, TaskPriority::Coordination);
}
ConfigTransactionInterface::ConfigTransactionInterface(NetworkAddress const& remote)
: getVersion(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GETVERSION)), get(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GET)),
getRange(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GETRANGE)), commit(Endpoint({ remote }, WLTOKEN_CONFIGTXN_COMMIT)) {
}
bool ConfigTransactionInterface::operator==(ConfigTransactionInterface const& rhs) const {
return _id == rhs._id;
}
bool ConfigTransactionInterface::operator!=(ConfigTransactionInterface const& rhs) const {
return !(*this == rhs);
}

View File

@ -128,25 +128,22 @@ struct ConfigTransactionGetRangeRequest {
};
struct ConfigTransactionInterface {
UID _id;
public:
static constexpr FileIdentifier file_identifier = 982485;
struct RequestStream<ConfigTransactionGetVersionRequest> getVersion;
struct RequestStream<ConfigTransactionGetRequest> get;
struct RequestStream<ConfigTransactionGetRangeRequest> getRange;
struct RequestStream<ConfigTransactionCommitRequest> commit;
ConfigTransactionInterface() = default;
ConfigTransactionInterface();
void setupWellKnownEndpoints();
ConfigTransactionInterface(NetworkAddress const& remote);
void setupWellKnownEndpoints() {
getVersion.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GETVERSION, TaskPriority::Coordination);
get.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GET, TaskPriority::Coordination);
getRange.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_GETRANGE, TaskPriority::Coordination);
commit.makeWellKnownEndpoint(WLTOKEN_CONFIGTXN_COMMIT, TaskPriority::Coordination);
}
ConfigTransactionInterface(NetworkAddress const& remote)
: getVersion(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GETVERSION)),
get(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GET)), getRange(Endpoint({ remote }, WLTOKEN_CONFIGTXN_GETRANGE)),
commit(Endpoint({ remote }, WLTOKEN_CONFIGTXN_COMMIT)) {}
bool operator==(ConfigTransactionInterface const& rhs) const;
bool operator!=(ConfigTransactionInterface const& rhs) const;
UID id() const { return _id; }
template <class Ar>
void serialize(Ar& ar) {

View File

@ -152,12 +152,18 @@ Future<Void> addTestGlobalSetMutation(ConfigStore& configStore, Version& lastWri
class LocalConfigEnvironment {
LocalConfiguration localConfiguration;
UID id;
public:
LocalConfigEnvironment(std::string const& configPath, std::map<Key, Value> const& manualKnobOverrides)
: localConfiguration(configPath, manualKnobOverrides) {}
: localConfiguration(configPath, manualKnobOverrides), id(deterministicRandom()->randomUniqueID()) {}
Future<Void> setup() { return localConfiguration.initialize("./", deterministicRandom()->randomUniqueID()); }
Future<Void> setup() { return localConfiguration.initialize("./", id); }
Future<Void> restart(std::string const& newConfigPath) {
localConfiguration = LocalConfiguration(newConfigPath, {});
return setup();
}
template <class TestType, class... Args>
Future<Void> run(Args&&... args) {

View File

@ -360,6 +360,10 @@ LocalConfiguration::LocalConfiguration(std::string const& configPath, std::map<K
LocalConfiguration::LocalConfiguration(std::string const& configPath, std::map<Key, Value> const& manualKnobOverrides)
: impl(std::make_unique<LocalConfigurationImpl>(configPath, manualKnobOverrides)) {}
LocalConfiguration::LocalConfiguration(LocalConfiguration&&) = default;
LocalConfiguration& LocalConfiguration::operator=(LocalConfiguration&&) = default;
LocalConfiguration::~LocalConfiguration() = default;
Future<Void> LocalConfiguration::initialize(std::string const& dataFolder, UID id) {

View File

@ -46,6 +46,8 @@ class LocalConfiguration {
public:
LocalConfiguration(std::string const& configPath, std::map<Key, Value> const& manualKnobOverrides);
LocalConfiguration(std::string const& configPath, std::map<Key, Value>&& manualKnobOverrides);
LocalConfiguration(LocalConfiguration&&);
LocalConfiguration& operator=(LocalConfiguration&&);
~LocalConfiguration();
Future<Void> initialize(std::string const& dataFolder, UID id);
FlowKnobs const& getFlowKnobs() const;