mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
refactor: Replace all old instances of Config with New Config (#1627)
Fixes #1184 Previous PR's found [here](https://github.com/XRPLF/clio/pull/1593) and [here](https://github.com/XRPLF/clio/pull/1544)
This commit is contained in:
@@ -18,20 +18,49 @@
|
||||
//==============================================================================
|
||||
|
||||
#include "etl/CacheLoaderSettings.hpp"
|
||||
#include "util/config/Config.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
#include "util/newconfig/ConfigFileJson.hpp"
|
||||
#include "util/newconfig/ConfigValue.hpp"
|
||||
#include "util/newconfig/Types.hpp"
|
||||
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace json = boost::json;
|
||||
using namespace etl;
|
||||
using namespace testing;
|
||||
using namespace util::config;
|
||||
|
||||
inline ClioConfigDefinition
|
||||
generateDefaultCacheConfig()
|
||||
{
|
||||
return ClioConfigDefinition{
|
||||
{{"io_threads", ConfigValue{ConfigType::Integer}.defaultValue(2)},
|
||||
{"cache.num_diffs", ConfigValue{ConfigType::Integer}.defaultValue(32)},
|
||||
{"cache.num_markers", ConfigValue{ConfigType::Integer}.defaultValue(48)},
|
||||
{"cache.num_cursors_from_diff", ConfigValue{ConfigType::Integer}.defaultValue(0)},
|
||||
{"cache.num_cursors_from_account", ConfigValue{ConfigType::Integer}.defaultValue(0)},
|
||||
{"cache.page_fetch_size", ConfigValue{ConfigType::Integer}.defaultValue(512)},
|
||||
{"cache.load", ConfigValue{ConfigType::String}.defaultValue("async")}}
|
||||
};
|
||||
}
|
||||
|
||||
inline ClioConfigDefinition
|
||||
getParseCacheConfig(boost::json::value val)
|
||||
{
|
||||
ConfigFileJson const jsonVal{val.as_object()};
|
||||
auto config = generateDefaultCacheConfig();
|
||||
auto const errors = config.parse(jsonVal);
|
||||
[&]() { ASSERT_FALSE(errors.has_value()); }();
|
||||
return config;
|
||||
}
|
||||
|
||||
struct CacheLoaderSettingsTest : Test {};
|
||||
|
||||
TEST_F(CacheLoaderSettingsTest, DefaultSettingsParsedCorrectly)
|
||||
{
|
||||
auto const cfg = util::Config{json::parse(R"({})")};
|
||||
auto const cfg = generateDefaultCacheConfig();
|
||||
auto const settings = make_CacheLoaderSettings(cfg);
|
||||
auto const defaults = CacheLoaderSettings{};
|
||||
|
||||
@@ -40,7 +69,7 @@ TEST_F(CacheLoaderSettingsTest, DefaultSettingsParsedCorrectly)
|
||||
|
||||
TEST_F(CacheLoaderSettingsTest, NumThreadsCorrectlyPropagatedThroughConfig)
|
||||
{
|
||||
auto const cfg = util::Config{json::parse(R"({"io_threads": 42})")};
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"io_threads": 42})"));
|
||||
auto const settings = make_CacheLoaderSettings(cfg);
|
||||
|
||||
EXPECT_EQ(settings.numThreads, 42);
|
||||
@@ -48,7 +77,7 @@ TEST_F(CacheLoaderSettingsTest, NumThreadsCorrectlyPropagatedThroughConfig)
|
||||
|
||||
TEST_F(CacheLoaderSettingsTest, NumDiffsCorrectlyPropagatedThroughConfig)
|
||||
{
|
||||
auto const cfg = util::Config{json::parse(R"({"cache": {"num_diffs": 42}})")};
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"num_diffs": 42}})"));
|
||||
auto const settings = make_CacheLoaderSettings(cfg);
|
||||
|
||||
EXPECT_EQ(settings.numCacheDiffs, 42);
|
||||
@@ -56,7 +85,7 @@ TEST_F(CacheLoaderSettingsTest, NumDiffsCorrectlyPropagatedThroughConfig)
|
||||
|
||||
TEST_F(CacheLoaderSettingsTest, NumMarkersCorrectlyPropagatedThroughConfig)
|
||||
{
|
||||
auto const cfg = util::Config{json::parse(R"({"cache": {"num_markers": 42}})")};
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"num_markers": 42}})"));
|
||||
auto const settings = make_CacheLoaderSettings(cfg);
|
||||
|
||||
EXPECT_EQ(settings.numCacheMarkers, 42);
|
||||
@@ -64,7 +93,7 @@ TEST_F(CacheLoaderSettingsTest, NumMarkersCorrectlyPropagatedThroughConfig)
|
||||
|
||||
TEST_F(CacheLoaderSettingsTest, PageFetchSizeCorrectlyPropagatedThroughConfig)
|
||||
{
|
||||
auto const cfg = util::Config{json::parse(R"({"cache": {"page_fetch_size": 42}})")};
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"page_fetch_size": 42}})"));
|
||||
auto const settings = make_CacheLoaderSettings(cfg);
|
||||
|
||||
EXPECT_EQ(settings.cachePageFetchSize, 42);
|
||||
@@ -72,7 +101,7 @@ TEST_F(CacheLoaderSettingsTest, PageFetchSizeCorrectlyPropagatedThroughConfig)
|
||||
|
||||
TEST_F(CacheLoaderSettingsTest, SyncLoadStyleCorrectlyPropagatedThroughConfig)
|
||||
{
|
||||
auto const cfg = util::Config{json::parse(R"({"cache": {"load": "sYNC"}})")};
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "sYNC"}})"));
|
||||
auto const settings = make_CacheLoaderSettings(cfg);
|
||||
|
||||
EXPECT_EQ(settings.loadStyle, CacheLoaderSettings::LoadStyle::SYNC);
|
||||
@@ -81,7 +110,7 @@ TEST_F(CacheLoaderSettingsTest, SyncLoadStyleCorrectlyPropagatedThroughConfig)
|
||||
|
||||
TEST_F(CacheLoaderSettingsTest, AsyncLoadStyleCorrectlyPropagatedThroughConfig)
|
||||
{
|
||||
auto const cfg = util::Config{json::parse(R"({"cache": {"load": "aSynC"}})")};
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "aSynC"}})"));
|
||||
auto const settings = make_CacheLoaderSettings(cfg);
|
||||
|
||||
EXPECT_EQ(settings.loadStyle, CacheLoaderSettings::LoadStyle::ASYNC);
|
||||
@@ -91,14 +120,14 @@ TEST_F(CacheLoaderSettingsTest, AsyncLoadStyleCorrectlyPropagatedThroughConfig)
|
||||
TEST_F(CacheLoaderSettingsTest, NoLoadStyleCorrectlyPropagatedThroughConfig)
|
||||
{
|
||||
{
|
||||
auto const cfg = util::Config{json::parse(R"({"cache": {"load": "nONe"}})")};
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "nONe"}})"));
|
||||
auto const settings = make_CacheLoaderSettings(cfg);
|
||||
|
||||
EXPECT_EQ(settings.loadStyle, CacheLoaderSettings::LoadStyle::NONE);
|
||||
EXPECT_TRUE(settings.isDisabled());
|
||||
}
|
||||
{
|
||||
auto const cfg = util::Config{json::parse(R"({"cache": {"load": "nO"}})")};
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "nO"}})"));
|
||||
auto const settings = make_CacheLoaderSettings(cfg);
|
||||
|
||||
EXPECT_EQ(settings.loadStyle, CacheLoaderSettings::LoadStyle::NONE);
|
||||
|
||||
@@ -22,13 +22,18 @@
|
||||
#include "etl/CacheLoaderSettings.hpp"
|
||||
#include "etl/FakeDiffProvider.hpp"
|
||||
#include "etl/impl/CacheLoader.hpp"
|
||||
#include "util/Assert.hpp"
|
||||
#include "util/MockBackendTestFixture.hpp"
|
||||
#include "util/MockCache.hpp"
|
||||
#include "util/MockPrometheus.hpp"
|
||||
#include "util/async/context/BasicExecutionContext.hpp"
|
||||
#include "util/config/Config.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
#include "util/newconfig/ConfigFileJson.hpp"
|
||||
#include "util/newconfig/ConfigValue.hpp"
|
||||
#include "util/newconfig/Types.hpp"
|
||||
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -39,9 +44,34 @@ using namespace etl;
|
||||
using namespace util;
|
||||
using namespace data;
|
||||
using namespace testing;
|
||||
using namespace util::config;
|
||||
|
||||
namespace {
|
||||
|
||||
inline ClioConfigDefinition
|
||||
generateDefaultCacheConfig()
|
||||
{
|
||||
return ClioConfigDefinition{
|
||||
{{"io_threads", ConfigValue{ConfigType::Integer}.defaultValue(2)},
|
||||
{"cache.num_diffs", ConfigValue{ConfigType::Integer}.defaultValue(32)},
|
||||
{"cache.num_markers", ConfigValue{ConfigType::Integer}.defaultValue(48)},
|
||||
{"cache.num_cursors_from_diff", ConfigValue{ConfigType::Integer}.defaultValue(0)},
|
||||
{"cache.num_cursors_from_account", ConfigValue{ConfigType::Integer}.defaultValue(0)},
|
||||
{"cache.page_fetch_size", ConfigValue{ConfigType::Integer}.defaultValue(512)},
|
||||
{"cache.load", ConfigValue{ConfigType::String}.defaultValue("async")}}
|
||||
};
|
||||
}
|
||||
|
||||
inline ClioConfigDefinition
|
||||
getParseCacheConfig(boost::json::value val)
|
||||
{
|
||||
ConfigFileJson const jsonVal{val.as_object()};
|
||||
auto config = generateDefaultCacheConfig();
|
||||
auto const errors = config.parse(jsonVal);
|
||||
[&]() { ASSERT_FALSE(errors.has_value()); }();
|
||||
return config;
|
||||
}
|
||||
|
||||
constexpr auto SEQ = 30;
|
||||
|
||||
struct CacheLoaderTest : util::prometheus::WithPrometheus, MockBackendTest {
|
||||
@@ -178,7 +208,7 @@ TEST_P(ParametrizedCacheLoaderTest, CacheDisabledLeadsToCancellation)
|
||||
//
|
||||
TEST_F(CacheLoaderTest, SyncCacheLoaderWaitsTillFullyLoaded)
|
||||
{
|
||||
auto const cfg = util::Config(json::parse(R"({"cache": {"load": "sync"}})"));
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "sync"}})"));
|
||||
CacheLoader loader{cfg, backend, cache};
|
||||
|
||||
auto const diffs = diffProvider.getLatestDiff();
|
||||
@@ -204,7 +234,7 @@ TEST_F(CacheLoaderTest, SyncCacheLoaderWaitsTillFullyLoaded)
|
||||
|
||||
TEST_F(CacheLoaderTest, AsyncCacheLoaderCanBeStopped)
|
||||
{
|
||||
auto const cfg = util::Config(json::parse(R"({"cache": {"load": "async"}})"));
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "async"}})"));
|
||||
CacheLoader loader{cfg, backend, cache};
|
||||
|
||||
auto const diffs = diffProvider.getLatestDiff();
|
||||
@@ -232,7 +262,7 @@ TEST_F(CacheLoaderTest, AsyncCacheLoaderCanBeStopped)
|
||||
|
||||
TEST_F(CacheLoaderTest, DisabledCacheLoaderDoesNotLoadCache)
|
||||
{
|
||||
auto cfg = util::Config(json::parse(R"({"cache": {"load": "none"}})"));
|
||||
auto const cfg = getParseCacheConfig(json::parse(R"({"cache": {"load": "none"}})"));
|
||||
CacheLoader loader{cfg, backend, cache};
|
||||
|
||||
EXPECT_CALL(cache, updateImp).Times(0);
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "util/MockPrometheus.hpp"
|
||||
#include "util/MockXrpLedgerAPIService.hpp"
|
||||
#include "util/TestObject.hpp"
|
||||
#include "util/config/Config.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <grpcpp/server_context.h>
|
||||
@@ -39,11 +39,12 @@
|
||||
#include <vector>
|
||||
|
||||
using namespace etl::impl;
|
||||
using namespace util::config;
|
||||
|
||||
struct GrpcSourceTests : NoLoggerFixture, util::prometheus::WithPrometheus, tests::util::WithMockXrpLedgerAPIService {
|
||||
GrpcSourceTests()
|
||||
: WithMockXrpLedgerAPIService("localhost:0")
|
||||
, mockBackend_(std::make_shared<testing::StrictMock<MockBackend>>(util::Config{}))
|
||||
, mockBackend_(std::make_shared<testing::StrictMock<MockBackend>>(ClioConfigDefinition{}))
|
||||
, grpcSource_("localhost", std::to_string(getXRPLMockPort()), mockBackend_)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "util/MockPrometheus.hpp"
|
||||
#include "util/MockSubscriptionManager.hpp"
|
||||
#include "util/TestObject.hpp"
|
||||
#include "util/config/Config.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
|
||||
#include <boost/json/parse.hpp>
|
||||
#include <fmt/core.h>
|
||||
@@ -42,7 +42,6 @@
|
||||
|
||||
using namespace testing;
|
||||
using namespace etl;
|
||||
namespace json = boost::json;
|
||||
using namespace std::chrono;
|
||||
|
||||
static auto constexpr ACCOUNT = "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn";
|
||||
@@ -63,8 +62,7 @@ struct ETLLedgerPublisherTest : util::prometheus::WithPrometheus, MockBackendTes
|
||||
{
|
||||
SyncAsioContextTest::TearDown();
|
||||
}
|
||||
|
||||
util::Config cfg{json::parse("{}")};
|
||||
util::config::ClioConfigDefinition cfg{{}};
|
||||
MockCache mockCache;
|
||||
StrictMockSubscriptionManagerSharedPtr mockSubscriptionManagerPtr;
|
||||
};
|
||||
|
||||
@@ -28,7 +28,12 @@
|
||||
#include "util/MockSubscriptionManager.hpp"
|
||||
#include "util/NameGenerator.hpp"
|
||||
#include "util/Random.hpp"
|
||||
#include "util/config/Config.hpp"
|
||||
#include "util/newconfig/Array.hpp"
|
||||
#include "util/newconfig/ConfigConstraints.hpp"
|
||||
#include "util/newconfig/ConfigDefinition.hpp"
|
||||
#include "util/newconfig/ConfigFileJson.hpp"
|
||||
#include "util/newconfig/ConfigValue.hpp"
|
||||
#include "util/newconfig/Types.hpp"
|
||||
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
@@ -52,20 +57,78 @@
|
||||
#include <vector>
|
||||
|
||||
using namespace etl;
|
||||
using namespace util::config;
|
||||
using testing::Return;
|
||||
|
||||
constexpr static auto const TwoSourcesLedgerResponse = R"({
|
||||
"etl_sources": [
|
||||
{
|
||||
"ip": "127.0.0.1",
|
||||
"ws_port": "5005",
|
||||
"grpc_port": "source1"
|
||||
},
|
||||
{
|
||||
"ip": "127.0.0.1",
|
||||
"ws_port": "5005",
|
||||
"grpc_port": "source2"
|
||||
}
|
||||
]
|
||||
})";
|
||||
|
||||
constexpr static auto const ThreeSourcesLedgerResponse = R"({
|
||||
"etl_sources": [
|
||||
{
|
||||
"ip": "127.0.0.1",
|
||||
"ws_port": "5005",
|
||||
"grpc_port": "source1"
|
||||
},
|
||||
{
|
||||
"ip": "127.0.0.1",
|
||||
"ws_port": "5005",
|
||||
"grpc_port": "source2"
|
||||
},
|
||||
{
|
||||
"ip": "127.0.0.1",
|
||||
"ws_port": "5005",
|
||||
"grpc_port": "source3"
|
||||
}
|
||||
]
|
||||
})";
|
||||
|
||||
inline ClioConfigDefinition
|
||||
getParseLoadBalancerConfig(boost::json::value val)
|
||||
{
|
||||
ClioConfigDefinition config{
|
||||
{{"forwarding.cache_timeout",
|
||||
ConfigValue{ConfigType::Double}.defaultValue(0.0).withConstraint(validatePositiveDouble)},
|
||||
{"forwarding.request_timeout",
|
||||
ConfigValue{ConfigType::Double}.defaultValue(10.0).withConstraint(validatePositiveDouble)},
|
||||
{"allow_no_etl", ConfigValue{ConfigType::Boolean}.defaultValue(false)},
|
||||
{"etl_sources.[].ip", Array{ConfigValue{ConfigType::String}.optional().withConstraint(validateIP)}},
|
||||
{"etl_sources.[].ws_port", Array{ConfigValue{ConfigType::String}.optional().withConstraint(validatePort)}},
|
||||
{"etl_sources.[].grpc_port", Array{ConfigValue{ConfigType::String}.optional()}},
|
||||
{"num_markers", ConfigValue{ConfigType::Integer}.optional().withConstraint(validateNumMarkers)}}
|
||||
};
|
||||
|
||||
auto const errors = config.parse(ConfigFileJson{val.as_object()});
|
||||
[&]() { ASSERT_FALSE(errors.has_value()); }();
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
struct LoadBalancerConstructorTests : util::prometheus::WithPrometheus, MockBackendTestStrict {
|
||||
StrictMockSubscriptionManagerSharedPtr subscriptionManager_;
|
||||
StrictMockNetworkValidatedLedgersPtr networkManager_;
|
||||
StrictMockSourceFactory sourceFactory_{2};
|
||||
boost::asio::io_context ioContext_;
|
||||
boost::json::value configJson_{{"etl_sources", {"source1", "source2"}}};
|
||||
boost::json::value configJson_ = boost::json::parse(TwoSourcesLedgerResponse);
|
||||
|
||||
std::unique_ptr<LoadBalancer>
|
||||
makeLoadBalancer()
|
||||
{
|
||||
auto const cfg = getParseLoadBalancerConfig(configJson_);
|
||||
return std::make_unique<LoadBalancer>(
|
||||
util::Config{configJson_},
|
||||
cfg,
|
||||
ioContext_,
|
||||
backend,
|
||||
subscriptionManager_,
|
||||
@@ -191,16 +254,6 @@ TEST_F(LoadBalancerConstructorTests, fetchETLState_DifferentNetworkIDButAllowNoE
|
||||
makeLoadBalancer();
|
||||
}
|
||||
|
||||
struct LoadBalancerConstructorDeathTest : LoadBalancerConstructorTests {};
|
||||
|
||||
TEST_F(LoadBalancerConstructorDeathTest, numMarkersSpecifiedInConfigIsInvalid)
|
||||
{
|
||||
uint32_t const numMarkers = 257;
|
||||
configJson_.as_object()["num_markers"] = numMarkers;
|
||||
testing::Mock::AllowLeak(&sourceFactory_);
|
||||
EXPECT_DEATH({ makeLoadBalancer(); }, ".*");
|
||||
}
|
||||
|
||||
struct LoadBalancerOnConnectHookTests : LoadBalancerConstructorTests {
|
||||
LoadBalancerOnConnectHookTests()
|
||||
{
|
||||
@@ -327,7 +380,8 @@ struct LoadBalancer3SourcesTests : LoadBalancerConstructorTests {
|
||||
LoadBalancer3SourcesTests()
|
||||
{
|
||||
sourceFactory_.setSourcesNumber(3);
|
||||
configJson_.as_object()["etl_sources"] = {"source1", "source2", "source3"};
|
||||
configJson_ = boost::json::parse(ThreeSourcesLedgerResponse);
|
||||
|
||||
EXPECT_CALL(sourceFactory_, makeSource).Times(3);
|
||||
EXPECT_CALL(sourceFactory_.sourceAt(0), forwardToRippled).WillOnce(Return(boost::json::object{}));
|
||||
EXPECT_CALL(sourceFactory_.sourceAt(0), run);
|
||||
|
||||
Reference in New Issue
Block a user