diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-21 16:22:32 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-21 16:22:32 +0000 |
commit | 83a2ef4c43a00eb09d31e41925260f5ea85c40bd (patch) | |
tree | 697739afd95dd8d7542b2c7a198ae33581bc624f /searchcore/src/tests/proton/documentdb | |
parent | 1bb2800fb1bf312689115a7230b1d3ead74d4ac6 (diff) |
Add helper classes containg a FNET_Transport and a FastOS_ThreadPool to reduce test boiler plate.
Diffstat (limited to 'searchcore/src/tests/proton/documentdb')
6 files changed, 29 insertions, 55 deletions
diff --git a/searchcore/src/tests/proton/documentdb/CMakeLists.txt b/searchcore/src/tests/proton/documentdb/CMakeLists.txt index 8ebeaef9a99..d36368a8ebd 100644 --- a/searchcore/src/tests/proton/documentdb/CMakeLists.txt +++ b/searchcore/src/tests/proton/documentdb/CMakeLists.txt @@ -3,6 +3,7 @@ vespa_add_executable(searchcore_documentdb_test_app TEST SOURCES documentdb_test.cpp DEPENDS + searchcore_test searchcore_server searchcore_initializer searchcore_reprocessing diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/CMakeLists.txt b/searchcore/src/tests/proton/documentdb/document_subdbs/CMakeLists.txt index 0bc1235bb6f..2706d183988 100644 --- a/searchcore/src/tests/proton/documentdb/document_subdbs/CMakeLists.txt +++ b/searchcore/src/tests/proton/documentdb/document_subdbs/CMakeLists.txt @@ -3,6 +3,7 @@ vespa_add_executable(searchcore_document_subdbs_test_app TEST SOURCES document_subdbs_test.cpp DEPENDS + searchcore_test searchcore_server searchcore_initializer searchcore_reprocessing diff --git a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp index 397250f3d1e..6e20d30fb36 100644 --- a/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp +++ b/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp @@ -25,6 +25,7 @@ #include <vespa/searchcore/proton/server/reconfig_params.h> #include <vespa/searchcore/proton/matching/querylimiter.h> #include <vespa/searchcore/proton/test/test.h> +#include <vespa/searchcore/proton/test/transport_helper.h> #include <vespa/searchcore/proton/test/thread_utils.h> #include <vespa/vespalib/util/idestructorcallback.h> #include <vespa/searchlib/index/docbuilder.h> @@ -36,8 +37,6 @@ #include <vespa/vespalib/util/threadstackexecutor.h> #include <vespa/vespalib/util/destructor_callbacks.h> #include <vespa/config/subscription/sourcespec.h> -#include <vespa/fastos/thread.h> -#include <vespa/fnet/transport.h> using namespace cloud::config::filedistribution; using namespace document; @@ -289,8 +288,7 @@ struct MyConfigSnapshot template <typename Traits> struct FixtureBase { - FastOS_ThreadPool _threadPool; - FNET_Transport _transport; + TransportMgr _transport; ThreadStackExecutor _summaryExecutor; ExecutorThreadingService _writeService; typename Traits::Config _cfg; @@ -303,8 +301,7 @@ struct FixtureBase typename Traits::SubDB _subDb; IFeedView::SP _tmpFeedView; FixtureBase() - : _threadPool(64_Ki), - _transport(), + : _transport(), _summaryExecutor(1, 64_Ki), _writeService(_summaryExecutor), _cfg(), @@ -312,18 +309,16 @@ struct FixtureBase _bucketDBHandler(*_bucketDB), _ctx(_writeService, _bucketDB, _bucketDBHandler), _baseSchema(), - _snapshot(std::make_unique<MyConfigSnapshot>(_transport, _baseSchema, Traits::ConfigDir::dir())), + _snapshot(std::make_unique<MyConfigSnapshot>(_transport.transport(), _baseSchema, Traits::ConfigDir::dir())), _baseDir(BASE_DIR + "/" + SUB_NAME, BASE_DIR), _subDb(_cfg._cfg, _ctx._ctx), _tmpFeedView() { - _transport.Start(&_threadPool); init(); } ~FixtureBase() { _writeService.master().execute(makeLambdaTask([this]() { _subDb.close(); })); _writeService.shutdown(); - _transport.ShutDown(true); } void setBucketStateCalculator(const std::shared_ptr<IBucketStateCalculator> & calc) { vespalib::Gate gate; @@ -354,7 +349,7 @@ struct FixtureBase runInMasterAndSync([&]() { performReconfig(serialNum, reconfigSchema, reconfigConfigDir); }); } void performReconfig(SerialNum serialNum, const Schema &reconfigSchema, const vespalib::string &reconfigConfigDir) { - auto newCfg = std::make_unique<MyConfigSnapshot>(_transport, reconfigSchema, reconfigConfigDir); + auto newCfg = std::make_unique<MyConfigSnapshot>(_transport.transport(), reconfigSchema, reconfigConfigDir); DocumentDBConfig::ComparisonResult cmpResult; cmpResult.attributesChanged = true; cmpResult.documenttypesChanged = true; diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp index c20f14d2d81..9a8d8bad60e 100644 --- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp @@ -27,6 +27,7 @@ #include <vespa/searchcore/proton/server/i_feed_handler_owner.h> #include <vespa/searchcore/proton/server/ireplayconfig.h> #include <vespa/searchcore/proton/test/dummy_feed_view.h> +#include <vespa/searchcore/proton/test/transport_helper.h> #include <vespa/searchlib/index/docbuilder.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/searchlib/transactionlog/translogserver.h> @@ -35,7 +36,6 @@ #include <vespa/vespalib/util/exceptions.h> #include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/io/fileutil.h> -#include <vespa/fnet/transport.h> #include <vespa/log/log.h> LOG_SETUP("feedhandler_test"); @@ -409,8 +409,7 @@ struct MyTlsWriter : TlsWriter { struct FeedHandlerFixture { DummyFileHeaderContext _fileHeaderContext; - FastOS_ThreadPool _threadPool; - FNET_Transport _transport; + TransportMgr _transport; TransLogServer tls; vespalib::string tlsSpec; vespalib::ThreadStackExecutor sharedExecutor; @@ -427,9 +426,8 @@ struct FeedHandlerFixture FeedHandler handler; FeedHandlerFixture() : _fileHeaderContext(), - _threadPool(64_Ki), _transport(), - tls(_transport, "mytls", 9016, "mytlsdir", _fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)), + tls(_transport.transport(), "mytls", 9016, "mytlsdir", _fileHeaderContext, DomainConfig().setPartSizeLimit(0x10000)), tlsSpec("tcp/localhost:9016"), sharedExecutor(1, 0x10000), writeService(sharedExecutor), @@ -443,7 +441,6 @@ struct FeedHandlerFixture handler(writeService, tlsSpec, schema.getDocType(), owner, writeFilter, replayConfig, tls, &tls_writer) { - _transport.Start(&_threadPool); _state.enterLoadState(); _state.enterReplayTransactionLogState(); handler.setActiveFeedView(&feedView); @@ -453,7 +450,6 @@ struct FeedHandlerFixture ~FeedHandlerFixture() { writeService.shutdown(); - _transport.ShutDown(true); } template <class FunctionType> inline void runAsMaster(FunctionType &&function) { diff --git a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp index aa525189b26..d51ea25f2f5 100644 --- a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp +++ b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp @@ -13,13 +13,12 @@ #include <vespa/searchcore/proton/server/bootstrapconfig.h> #include <vespa/searchcore/proton/server/fileconfigmanager.h> #include <vespa/searchcore/proton/test/documentdb_config_builder.h> +#include <vespa/searchcore/proton/test/transport_helper.h> #include <vespa/searchsummary/config/config-juniperrc.h> #include <vespa/vespalib/io/fileutil.h> -#include <vespa/vespalib/util/size_literals.h> #include <vespa/config-bucketspaces.h> #include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/fastos/thread.h> -#include <vespa/fnet/transport.h> + using namespace cloud::config::filedistribution; using namespace config; @@ -128,69 +127,55 @@ addConfigsThatAreNotSavedToDisk(const DocumentDBConfig &cfg) return builder.build(); } -struct Fixture { - FastOS_ThreadPool threadPool; - FNET_Transport transport; - Fixture() - : threadPool(64_Ki), - transport() - { - transport.Start(&threadPool); - } - ~Fixture() { - transport.ShutDown(true); - } -}; - -TEST_FF("requireThatConfigCanBeSavedAndLoaded", Fixture(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport))) +TEST_FF("requireThatConfigCanBeSavedAndLoaded", TransportMgr(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) { DocumentDBConfig::SP fullCfg = addConfigsThatAreNotSavedToDisk(*f2); - saveBaseConfigSnapshot(f1.transport, *fullCfg, 20); + saveBaseConfigSnapshot(f1.transport(), *fullCfg, 20); DocumentDBConfig::SP esnap(makeEmptyConfigSnapshot()); { - FileConfigManager cm(f1.transport, "out", myId, "dummy"); + FileConfigManager cm(f1.transport(), "out", myId, "dummy"); cm.loadConfig(*esnap, 20, esnap); } assertEqualSnapshot(*f2, *esnap); } -TEST_FF("requireThatConfigCanBeSerializedAndDeserialized", Fixture(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport))) +TEST_FF("requireThatConfigCanBeSerializedAndDeserialized", TransportMgr(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) { - saveBaseConfigSnapshot(f1.transport, *f2, 30); + saveBaseConfigSnapshot(f1.transport(), *f2, 30); nbostream stream; { - FileConfigManager cm(f1.transport, "out", myId, "dummy"); + FileConfigManager cm(f1.transport(), "out", myId, "dummy"); cm.serializeConfig(30, stream); } { - FileConfigManager cm(f1.transport, "out", myId, "dummy"); + FileConfigManager cm(f1.transport(), "out", myId, "dummy"); cm.deserializeConfig(40, stream); } DocumentDBConfig::SP fsnap(makeEmptyConfigSnapshot()); { - FileConfigManager cm(f1.transport, "out", myId, "dummy"); + FileConfigManager cm(f1.transport(), "out", myId, "dummy"); cm.loadConfig(*fsnap, 40, fsnap); } assertEqualSnapshot(*f2, *fsnap); EXPECT_EQUAL("dummy", fsnap->getDocTypeName()); } -TEST_FF("requireThatConfigCanBeLoadedWithoutExtraConfigsDataFile", Fixture(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport))) +TEST_FF("requireThatConfigCanBeLoadedWithoutExtraConfigsDataFile", TransportMgr(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) { - saveBaseConfigSnapshot(f1.transport, *f2, 70); + saveBaseConfigSnapshot(f1.transport(), *f2, 70); EXPECT_FALSE(vespalib::unlink("out/config-70/extraconfigs.dat")); DocumentDBConfig::SP esnap(makeEmptyConfigSnapshot()); { - FileConfigManager cm(f1.transport, "out", myId, "dummy"); + FileConfigManager cm(f1.transport(), "out", myId, "dummy"); cm.loadConfig(*esnap, 70, esnap); } } -TEST_FF("requireThatVisibilityDelayIsPropagated", Fixture(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport))) +TEST_FF("requireThatVisibilityDelayIsPropagated", TransportMgr(), DocumentDBConfig::SP(makeBaseConfigSnapshot(f1.transport()))) { - saveBaseConfigSnapshot(f1.transport, *f2, 80); + saveBaseConfigSnapshot(f1.transport(), *f2, 80); DocumentDBConfig::SP esnap(makeEmptyConfigSnapshot()); { ProtonConfigBuilder protonConfigBuilder; @@ -199,7 +184,7 @@ TEST_FF("requireThatVisibilityDelayIsPropagated", Fixture(), DocumentDBConfig::S ddb.visibilitydelay = 61.0; protonConfigBuilder.documentdb.push_back(ddb); protonConfigBuilder.maxvisibilitydelay = 100.0; - FileConfigManager cm(f1.transport, "out", myId, "dummy"); + FileConfigManager cm(f1.transport(), "out", myId, "dummy"); cm.setProtonConfig(std::make_shared<ProtonConfig>(protonConfigBuilder)); cm.loadConfig(*esnap, 70, esnap); } diff --git a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp index 45d4354564e..39a5c69376c 100644 --- a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp +++ b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp @@ -33,6 +33,7 @@ #include <vespa/searchcore/proton/test/disk_mem_usage_notifier.h> #include <vespa/searchcore/proton/test/mock_attribute_manager.h> #include <vespa/searchcore/proton/test/test.h> +#include <vespa/searchcore/proton/test/transport_helper.h> #include <vespa/searchlib/common/idocumentmetastore.h> #include <vespa/searchlib/index/docbuilder.h> #include <vespa/vespalib/data/slime/slime.h> @@ -43,7 +44,6 @@ #include <vespa/vespalib/util/monitored_refcount.h> #include <vespa/vespalib/util/size_literals.h> #include <vespa/vespalib/util/threadstackexecutor.h> -#include <vespa/fnet/transport.h> #include <unistd.h> #include <thread> @@ -349,8 +349,7 @@ public: test::DiskMemUsageNotifier _diskMemUsageNotifier; BucketCreateNotifier _bucketCreateNotifier; MonitoredRefCount _refCount; - FastOS_ThreadPool _threadPool; - FNET_Transport _transport; + TransportMgr _transport; MaintenanceController _mc; MaintenanceControllerFixture(); @@ -770,11 +769,9 @@ MaintenanceControllerFixture::MaintenanceControllerFixture() _attributeUsageFilter(), _bucketCreateNotifier(), _refCount(), - _threadPool(64_Ki), _transport(), - _mc(_transport, _threadService, _genericExecutor, _refCount, _docTypeName) + _mc(_transport.transport(), _threadService, _genericExecutor, _refCount, _docTypeName) { - _transport.Start(&_threadPool); std::vector<MyDocumentSubDB *> subDBs; subDBs.push_back(&_ready); subDBs.push_back(&_removed); @@ -785,7 +782,6 @@ MaintenanceControllerFixture::MaintenanceControllerFixture() MaintenanceControllerFixture::~MaintenanceControllerFixture() { - _transport.ShutDown(true); stopMaintenance(); } |