diff --git a/searchcore/src/tests/proton/documentdb/CMakeLists.txt b/searchcore/src/tests/proton/documentdb/CMakeLists.txt index 4bf42c1701b0..c619cbfa986f 100644 --- a/searchcore/src/tests/proton/documentdb/CMakeLists.txt +++ b/searchcore/src/tests/proton/documentdb/CMakeLists.txt @@ -27,12 +27,10 @@ vespa_add_executable(searchcore_proton_documentdb_vespatest_test_app TEST vespatest_runner.cpp buckethandler_test.cpp combiningfeedview_test.cpp - configurer_test.cpp document_scan_iterator_test.cpp document_subdbs_test.cpp documentdbconfig_test.cpp documentdbconfigscout_test.cpp - feedview_test.cpp job_tracked_maintenance_job_test.cpp maintenancecontroller_test.cpp storeonlyfeedview_test.cpp @@ -48,9 +46,11 @@ vespa_add_executable(searchcore_proton_documentdb_gtest_test_app TEST gtest_runner.cpp clusterstatehandler_test.cpp bucketmover_common.cpp + configurer_test.cpp documentbucketmover_test.cpp documentmover_test.cpp executor_threading_service_test.cpp + feedview_test.cpp lid_space_common.cpp lid_space_compaction_test.cpp lid_space_handler_test.cpp diff --git a/searchcore/src/tests/proton/documentdb/configurer_test.cpp b/searchcore/src/tests/proton/documentdb/configurer_test.cpp index ac8a181528da..2e32b6acbebf 100644 --- a/searchcore/src/tests/proton/documentdb/configurer_test.cpp +++ b/searchcore/src/tests/proton/documentdb/configurer_test.cpp @@ -36,12 +36,10 @@ #include #include #include -#include +#include #include #include #include -#include -#include using namespace config; using namespace document; @@ -397,44 +395,44 @@ struct SearchViewComparer SearchViewComparer(SearchView::SP old, SearchView::SP new_); ~SearchViewComparer(); void expect_equal() { - EXPECT_EQUAL(_old.get(), _new.get()); + EXPECT_EQ(_old.get(), _new.get()); } void expect_not_equal() { - EXPECT_NOT_EQUAL(_old.get(), _new.get()); + EXPECT_NE(_old.get(), _new.get()); } void expect_equal_summary_setup() { - EXPECT_EQUAL(_old->getSummarySetup().get(), _new->getSummarySetup().get()); + EXPECT_EQ(_old->getSummarySetup().get(), _new->getSummarySetup().get()); } void expect_not_equal_summary_setup() { - EXPECT_NOT_EQUAL(_old->getSummarySetup().get(), _new->getSummarySetup().get()); + EXPECT_NE(_old->getSummarySetup().get(), _new->getSummarySetup().get()); } void expect_equal_match_view() { - EXPECT_EQUAL(_old->getMatchView().get(), _new->getMatchView().get()); + EXPECT_EQ(_old->getMatchView().get(), _new->getMatchView().get()); } void expect_not_equal_match_view() { - EXPECT_NOT_EQUAL(_old->getMatchView().get(), _new->getMatchView().get()); + EXPECT_NE(_old->getMatchView().get(), _new->getMatchView().get()); } void expect_equal_matchers() { - EXPECT_EQUAL(_old->getMatchers().get(), _new->getMatchers().get()); + EXPECT_EQ(_old->getMatchers().get(), _new->getMatchers().get()); } void expect_not_equal_matchers() { - EXPECT_NOT_EQUAL(_old->getMatchers().get(), _new->getMatchers().get()); + EXPECT_NE(_old->getMatchers().get(), _new->getMatchers().get()); } void expect_equal_index_searchable() { - EXPECT_EQUAL(_old->getIndexSearchable().get(), _new->getIndexSearchable().get()); + EXPECT_EQ(_old->getIndexSearchable().get(), _new->getIndexSearchable().get()); } void expect_not_equal_index_searchable() { - EXPECT_NOT_EQUAL(_old->getIndexSearchable().get(), _new->getIndexSearchable().get()); + EXPECT_NE(_old->getIndexSearchable().get(), _new->getIndexSearchable().get()); } void expect_equal_attribute_manager() { - EXPECT_EQUAL(_old->getAttributeManager().get(), _new->getAttributeManager().get()); + EXPECT_EQ(_old->getAttributeManager().get(), _new->getAttributeManager().get()); } void expect_not_equal_attribute_manager() { - EXPECT_NOT_EQUAL(_old->getAttributeManager().get(), _new->getAttributeManager().get()); + EXPECT_NE(_old->getAttributeManager().get(), _new->getAttributeManager().get()); } void expect_equal_document_meta_store() { - EXPECT_EQUAL(_old->getDocumentMetaStore().get(), _new->getDocumentMetaStore().get()); + EXPECT_EQ(_old->getDocumentMetaStore().get(), _new->getDocumentMetaStore().get()); } }; @@ -452,22 +450,22 @@ struct FeedViewComparer FeedViewComparer(SearchableFeedView::SP old, SearchableFeedView::SP new_); ~FeedViewComparer(); void expect_equal() { - EXPECT_EQUAL(_old.get(), _new.get()); + EXPECT_EQ(_old.get(), _new.get()); } void expect_not_equal() { - EXPECT_NOT_EQUAL(_old.get(), _new.get()); + EXPECT_NE(_old.get(), _new.get()); } void expect_equal_index_adapter() { - EXPECT_EQUAL(_old->getIndexWriter().get(), _new->getIndexWriter().get()); + EXPECT_EQ(_old->getIndexWriter().get(), _new->getIndexWriter().get()); } void expect_not_equal_attribute_writer() { - EXPECT_NOT_EQUAL(_old->getAttributeWriter().get(), _new->getAttributeWriter().get()); + EXPECT_NE(_old->getAttributeWriter().get(), _new->getAttributeWriter().get()); } void expect_equal_summary_adapter() { - EXPECT_EQUAL(_old->getSummaryAdapter().get(), _new->getSummaryAdapter().get()); + EXPECT_EQ(_old->getSummaryAdapter().get(), _new->getSummaryAdapter().get()); } void expect_not_equal_schema() { - EXPECT_NOT_EQUAL(_old->getSchema().get(), _new->getSchema().get()); + EXPECT_NE(_old->getSchema().get(), _new->getSchema().get()); } }; @@ -484,16 +482,16 @@ struct FastAccessFeedViewComparer FastAccessFeedViewComparer(FastAccessFeedView::SP old, FastAccessFeedView::SP new_); ~FastAccessFeedViewComparer(); void expect_not_equal() { - EXPECT_NOT_EQUAL(_old.get(), _new.get()); + EXPECT_NE(_old.get(), _new.get()); } void expect_not_equal_attribute_writer() { - EXPECT_NOT_EQUAL(_old->getAttributeWriter().get(), _new->getAttributeWriter().get()); + EXPECT_NE(_old->getAttributeWriter().get(), _new->getAttributeWriter().get()); } void expect_equal_summary_adapter() { - EXPECT_EQUAL(_old->getSummaryAdapter().get(), _new->getSummaryAdapter().get()); + EXPECT_EQ(_old->getSummaryAdapter().get(), _new->getSummaryAdapter().get()); } void expect_not_equal_schema() { - EXPECT_NOT_EQUAL(_old->getSchema().get(), _new->getSchema().get()); + EXPECT_NE(_old->getSchema().get(), _new->getSchema().get()); } }; @@ -505,8 +503,9 @@ FastAccessFeedViewComparer::~FastAccessFeedViewComparer() = default; } -TEST_F("require that we can reconfigure index searchable", Fixture) +TEST(DocSubDBConfigurerTest, require_that_we_can_reconfigure_index_searchable) { + Fixture f; ViewPtrs o = f._views.getViewPtrs(); f._configurer->reconfigureIndexSearchable(); @@ -527,16 +526,21 @@ TEST_F("require that we can reconfigure index searchable", Fixture) } } +namespace { + const AttributeManager * asAttributeManager(const proton::IAttributeManager::SP &attrMgr) { auto result = dynamic_cast(attrMgr.get()); - ASSERT_TRUE(result != nullptr); + EXPECT_TRUE(result != nullptr); return result; } -TEST_F("require that we can reconfigure attribute manager", Fixture) +} + +TEST(DocSubDBConfigurerTest, require_that_we_can_reconfigure_attribute_manager) { + Fixture f; ViewPtrs o = f._views.getViewPtrs(); ReconfigParams params(CCR().setAttributesChanged(true).setSchemaChanged(true)); // Use new config snapshot == old config snapshot (only relevant for reprocessing) @@ -566,6 +570,8 @@ TEST_F("require that we can reconfigure attribute manager", Fixture) EXPECT_TRUE(asAttributeManager(f._views.getViewPtrs().fv.get()->getAttributeWriter()->getAttributeManager())->getImportedAttributes() != nullptr); } +namespace { + AttributeWriter::SP getAttributeWriter(Fixture &f) { @@ -583,20 +589,24 @@ checkAttributeWriterChangeOnRepoChange(Fixture &f, bool docTypeRepoChanged) params, f._resolver, 1, reconfig_serial_num); auto newAttributeWriter = getAttributeWriter(f); if (docTypeRepoChanged) { - EXPECT_NOT_EQUAL(oldAttributeWriter, newAttributeWriter); + EXPECT_NE(oldAttributeWriter, newAttributeWriter); } else { - EXPECT_EQUAL(oldAttributeWriter, newAttributeWriter); + EXPECT_EQ(oldAttributeWriter, newAttributeWriter); } } -TEST_F("require that we get new attribute writer if document type repo changes", Fixture) +} + +TEST(DocSubDBConfigurerTest, require_that_we_get_new_attribute_writer_if_document_type_repo_changes) { + Fixture f; checkAttributeWriterChangeOnRepoChange(f, false); checkAttributeWriterChangeOnRepoChange(f, true); } -TEST_F("require that reconfigure returns reprocessing initializer when changing attributes", Fixture) +TEST(DocSubDBConfigurerTest, require_that_reconfigure_returns_reprocessing_initializer_when_changing_attributes) { + Fixture f; ReconfigParams params(CCR().setAttributesChanged(true).setSchemaChanged(true)); SerialNum reconfig_serial_num = 0; IReprocessingInitializer::UP init = @@ -608,8 +618,9 @@ TEST_F("require that reconfigure returns reprocessing initializer when changing EXPECT_FALSE(init->hasReprocessors()); } -TEST_F("require that we can reconfigure attribute writer", FastAccessFixture) +TEST(DocSubDBConfigurerTest, require_that_we_can_reconfigure_attribute_writer) { + FastAccessFixture f; FastAccessFeedView::SP o = f._view._feedView.get(); SerialNum reconfig_serial_num = 0; f.reconfigure(*createConfig(), *createConfig(), 1, reconfig_serial_num); @@ -622,8 +633,9 @@ TEST_F("require that we can reconfigure attribute writer", FastAccessFixture) cmp.expect_not_equal_schema(); } -TEST_F("require that reconfigure returns reprocessing initializer", FastAccessFixture) +TEST(DocSubDBConfigurerTest, require_that_reconfigure_returns_reprocessing_initializer) { + FastAccessFixture f; SerialNum reconfig_serial_num = 0; auto init = f.reconfigure(*createConfig(), *createConfig(), 1, reconfig_serial_num); @@ -632,8 +644,9 @@ TEST_F("require that reconfigure returns reprocessing initializer", FastAccessFi EXPECT_FALSE(init->hasReprocessors()); } -TEST_F("require that we can reconfigure summary manager", Fixture) +TEST(DocSubDBConfigurerTest, require_that_we_can_reconfigure_summary_manager) { + Fixture f; ViewPtrs o = f._views.getViewPtrs(); ReconfigParams params(CCR().setSummaryChanged(true)); // Use new config snapshot == old config snapshot (only relevant for reprocessing) @@ -653,8 +666,9 @@ TEST_F("require that we can reconfigure summary manager", Fixture) } } -TEST_F("require that we can reconfigure matchers", Fixture) +TEST(DocSubDBConfigurerTest, require_that_we_can_reconfigure_matchers) { + Fixture f; ViewPtrs o = f._views.getViewPtrs(); // Use new config snapshot == old config snapshot (only relevant for reprocessing) SerialNum reconfig_serial_num = 0; @@ -678,60 +692,64 @@ TEST_F("require that we can reconfigure matchers", Fixture) } } -TEST("require that attribute manager (imported attributes) should change when imported fields has changed") +TEST(DocSubDBConfigurerTest, require_that_attribute_manager_should_change_when_imported_fields_have_changed) { ReconfigParams params(CCR().setImportedFieldsChanged(true)); EXPECT_TRUE(params.shouldAttributeManagerChange()); } -TEST("require that attribute manager (imported attributes) should change when visibility delay has changed") +TEST(DocSubDBConfigurerTest, require_that_attribute_manager_should_change_when_visibility_delay_has_changed) { ReconfigParams params(CCR().setVisibilityDelayChanged(true)); EXPECT_TRUE(params.shouldAttributeManagerChange()); } -TEST("require that attribute manager should change when alloc config has changed") +TEST(DocSubDBConfigurerTest, require_that_attribute_manager_should_change_when_alloc_config_has_changed) { ReconfigParams params(CCR().set_alloc_config_changed(true)); EXPECT_TRUE(params.shouldAttributeManagerChange()); } +namespace { + void -assertMaintenanceControllerShouldNotChange(DocumentDBConfig::ComparisonResult result) -{ +assertMaintenanceControllerShouldNotChange(DocumentDBConfig::ComparisonResult result) { ReconfigParams params(result); EXPECT_FALSE(params.configHasChanged()); EXPECT_FALSE(params.shouldMaintenanceControllerChange()); } void -assertMaintenanceControllerShouldChange(DocumentDBConfig::ComparisonResult result) -{ +assertMaintenanceControllerShouldChange(DocumentDBConfig::ComparisonResult result, std::string_view label) { + SCOPED_TRACE(label); ReconfigParams params(result); EXPECT_TRUE(params.configHasChanged()); EXPECT_TRUE(params.shouldMaintenanceControllerChange()); } -TEST("require that maintenance controller should change if some config has changed") -{ - TEST_DO(assertMaintenanceControllerShouldNotChange(CCR())); +} - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setRankProfilesChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setRankingConstantsChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setRankingExpressionsChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setOnnxModelsChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setIndexschemaChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setAttributesChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setSummaryChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setJuniperrcChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setDocumenttypesChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setDocumentTypeRepoChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setImportedFieldsChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setTuneFileDocumentDBChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setSchemaChanged(true))); - TEST_DO(assertMaintenanceControllerShouldChange(CCR().setMaintenanceChanged(true))); +TEST(DocSubDBConfigurerTest, require_that_maintenance_controller_should_change_if_some_config_has_changed) +{ + assertMaintenanceControllerShouldNotChange(CCR()); + assertMaintenanceControllerShouldChange(CCR().setRankProfilesChanged(true), "rank profiles changed"); + assertMaintenanceControllerShouldChange(CCR().setRankingConstantsChanged(true), "ranking constants changed"); + assertMaintenanceControllerShouldChange(CCR().setRankingExpressionsChanged(true), "ranking expressions changed"); + assertMaintenanceControllerShouldChange(CCR().setOnnxModelsChanged(true), "onnx models changed"); + assertMaintenanceControllerShouldChange(CCR().setIndexschemaChanged(true), "index schema changed"); + assertMaintenanceControllerShouldChange(CCR().setAttributesChanged(true), "attributes changed"); + assertMaintenanceControllerShouldChange(CCR().setSummaryChanged(true), "summary changed"); + assertMaintenanceControllerShouldChange(CCR().setJuniperrcChanged(true), "juniperrc changed"); + assertMaintenanceControllerShouldChange(CCR().setDocumenttypesChanged(true), "document types changed"); + assertMaintenanceControllerShouldChange(CCR().setDocumentTypeRepoChanged(true), "document types repo changed"); + assertMaintenanceControllerShouldChange(CCR().setImportedFieldsChanged(true), "imported fields changed"); + assertMaintenanceControllerShouldChange(CCR().setTuneFileDocumentDBChanged(true), "TuneFileDocumentCB changed"); + assertMaintenanceControllerShouldChange(CCR().setSchemaChanged(true), "schema changed"); + assertMaintenanceControllerShouldChange(CCR().setMaintenanceChanged(true), "maintenance changed"); } +namespace { + void assertSubDbsShouldNotChange(DocumentDBConfig::ComparisonResult result) { @@ -741,35 +759,39 @@ assertSubDbsShouldNotChange(DocumentDBConfig::ComparisonResult result) } void -assertSubDbsShouldChange(DocumentDBConfig::ComparisonResult result) +assertSubDbsShouldChange(DocumentDBConfig::ComparisonResult result, std::string_view label) { + SCOPED_TRACE(label); ReconfigParams params(result); EXPECT_TRUE(params.configHasChanged()); EXPECT_TRUE(params.shouldSubDbsChange()); } +} -TEST("require that subdbs should change if relevant config changed") +TEST(DocSubDBConfigurerTest, require_that_subdbs_should_change_if_relevant_config_changed) { - TEST_DO(assertSubDbsShouldNotChange(CCR())); + assertSubDbsShouldNotChange(CCR()); EXPECT_FALSE(ReconfigParams(CCR().setMaintenanceChanged(true)).shouldSubDbsChange()); - TEST_DO(assertSubDbsShouldChange(CCR().setFlushChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setStoreChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setDocumenttypesChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setDocumentTypeRepoChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setSummaryChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setJuniperrcChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setAttributesChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setImportedFieldsChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setVisibilityDelayChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setRankProfilesChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setRankingConstantsChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setRankingExpressionsChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setOnnxModelsChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().setSchemaChanged(true))); - TEST_DO(assertSubDbsShouldChange(CCR().set_alloc_config_changed(true))); + assertSubDbsShouldChange(CCR().setFlushChanged(true), "flush cnanged"); + assertSubDbsShouldChange(CCR().setStoreChanged(true), "store changed"); + assertSubDbsShouldChange(CCR().setDocumenttypesChanged(true), "document types changed"); + assertSubDbsShouldChange(CCR().setDocumentTypeRepoChanged(true), "document type repo changed"); + assertSubDbsShouldChange(CCR().setSummaryChanged(true), "summary changed"); + assertSubDbsShouldChange(CCR().setJuniperrcChanged(true), "juniperrc changed"); + assertSubDbsShouldChange(CCR().setAttributesChanged(true), "attributes changed"); + assertSubDbsShouldChange(CCR().setImportedFieldsChanged(true), "imported fields changed"); + assertSubDbsShouldChange(CCR().setVisibilityDelayChanged(true), "visibility delay changed"); + assertSubDbsShouldChange(CCR().setRankProfilesChanged(true), "rank profiles changed"); + assertSubDbsShouldChange(CCR().setRankingConstantsChanged(true), "ranking constants changed"); + assertSubDbsShouldChange(CCR().setRankingExpressionsChanged(true), "ranking expressions changed"); + assertSubDbsShouldChange(CCR().setOnnxModelsChanged(true), "onnx models changed"); + assertSubDbsShouldChange(CCR().setSchemaChanged(true), "schema changed"); + assertSubDbsShouldChange(CCR().set_alloc_config_changed(true), "allocd config changed"); } +namespace { + void assertSummaryManagerShouldNotChange(DocumentDBConfig::ComparisonResult result) { @@ -779,20 +801,23 @@ assertSummaryManagerShouldNotChange(DocumentDBConfig::ComparisonResult result) } void -assertSummaryManagerShouldChange(DocumentDBConfig::ComparisonResult result) +assertSummaryManagerShouldChange(DocumentDBConfig::ComparisonResult result, std::string_view label) { + SCOPED_TRACE(label); ReconfigParams params(result); EXPECT_TRUE(params.configHasChanged()); EXPECT_TRUE(params.shouldSummaryManagerChange()); } -TEST("require that summary manager should change if relevant config changed") +} + +TEST(DocSubDBConfigurerTest, require_that_summary_manager_should_change_if_relevant_config_changed) { - TEST_DO(assertSummaryManagerShouldNotChange(CCR())); - TEST_DO(assertSummaryManagerShouldChange(CCR().setSummaryChanged(true))); - TEST_DO(assertSummaryManagerShouldChange(CCR().setJuniperrcChanged(true))); - TEST_DO(assertSummaryManagerShouldChange(CCR().setDocumenttypesChanged(true))); - TEST_DO(assertSummaryManagerShouldChange(CCR().setDocumentTypeRepoChanged(true))); - TEST_DO(assertSummaryManagerShouldChange(CCR().setStoreChanged(true))); - TEST_DO(assertSummaryManagerShouldChange(CCR().setSchemaChanged(true))); + assertSummaryManagerShouldNotChange(CCR()); + assertSummaryManagerShouldChange(CCR().setSummaryChanged(true), "summary changed"); + assertSummaryManagerShouldChange(CCR().setJuniperrcChanged(true), "juniperrc changed"); + assertSummaryManagerShouldChange(CCR().setDocumenttypesChanged(true), "document types changed"); + assertSummaryManagerShouldChange(CCR().setDocumentTypeRepoChanged(true), "document type repo changed"); + assertSummaryManagerShouldChange(CCR().setStoreChanged(true), "store changed"); + assertSummaryManagerShouldChange(CCR().setSchemaChanged(true), "schema changed"); } diff --git a/searchcore/src/tests/proton/documentdb/feedview_test.cpp b/searchcore/src/tests/proton/documentdb/feedview_test.cpp index 4b904896c604..81d293a26e43 100644 --- a/searchcore/src/tests/proton/documentdb/feedview_test.cpp +++ b/searchcore/src/tests/proton/documentdb/feedview_test.cpp @@ -29,8 +29,10 @@ #include #include #include +#include #include #include +#include #include LOG_SETUP(".feedview_test"); @@ -178,6 +180,8 @@ struct MyIndexWriter : public test::MockIndexWriter } }; +using LastChange = std::tuple; + struct MyGidToLidChangeHandler : public MockGidToLidChangeHandler { document::GlobalId _changeGid; @@ -209,19 +213,9 @@ struct MyGidToLidChangeHandler : public MockGidToLidChangeHandler ++_changes; } } - - void assertChanges(document::GlobalId expGid, uint32_t expLid, uint32_t expChanges) { - EXPECT_EQUAL(expGid, _changeGid); - EXPECT_EQUAL(expLid, _changeLid); - EXPECT_EQUAL(expChanges, _changes); - } - void assertNumChanges(uint32_t expChanges) { - EXPECT_EQUAL(expChanges, _changes); - } - void assertLid(document::GlobalId gid, uint32_t expLid) { - uint32_t lid = _gidToLid[gid]; - EXPECT_EQUAL(expLid, lid); - } + LastChange get_last_change() const noexcept { return std::make_tuple(_changeGid, _changeLid, _changes); } + uint32_t get_num_changes() const noexcept { return _changes; } + uint32_t get_lid(document::GlobalId gid) { return _gidToLid[gid]; } }; struct MyDocumentStore : public test::DummyDocumentStore @@ -647,9 +641,7 @@ struct FixtureBase _writeService.master().sync(); } - bool assertTrace(const std::string &exp) { - return EXPECT_EQUAL(exp, _tracer._os.view()); - } + std::string get_trace() { return _tracer._os.str(); } DocumentContext::List makeDummyDocs(uint32_t first, uint32_t count, uint64_t tsfirst) __attribute__((noinline)); @@ -667,15 +659,9 @@ struct FixtureBase gate.await(); _writeService.master().sync(); } - void assertChangeHandler(document::GlobalId expGid, uint32_t expLid, uint32_t expChanges) { - _gidToLidChangeHandler->assertChanges(expGid, expLid, expChanges); - } - void assertChangeHandlerCount(uint32_t expChanges) { - _gidToLidChangeHandler->assertNumChanges(expChanges); - } - void assertChangeNotified(document::GlobalId gid, uint32_t expLid) { - _gidToLidChangeHandler->assertLid(gid, expLid); - } + LastChange get_last_change() { return _gidToLidChangeHandler->get_last_change(); } + uint32_t get_change_handler_count() { return _gidToLidChangeHandler->get_num_changes(); } + uint32_t get_notified_lid(document::GlobalId gid) { return _gidToLidChangeHandler->get_lid(gid); } void populateBeforeCompactLidSpace(); void dms_commit() { _dmsc->get().commit(search::CommitParam(serial)); } @@ -777,15 +763,15 @@ void assertBucketInfo(const BucketId &ebid, const Timestamp &ets, uint32_t lid, EXPECT_TRUE(metaStore.getGid(lid, gid)); search::DocumentMetaData meta = metaStore.getMetaData(gid); EXPECT_TRUE(meta.valid()); - EXPECT_EQUAL(ebid, meta.bucketId); + EXPECT_EQ(ebid, meta.bucketId); Timestamp ats; - EXPECT_EQUAL(ets, meta.timestamp); + EXPECT_EQ(ets, meta.timestamp); } void assertLidVector(const MyLidVector &exp, const MyLidVector &act) __attribute__((noinline)); void assertLidVector(const MyLidVector &exp, const MyLidVector &act) { - EXPECT_EQUAL(exp.size(), act.size()); + EXPECT_EQ(exp.size(), act.size()); for (size_t i = 0; i < exp.size(); ++i) { EXPECT_TRUE(std::find(act.begin(), act.end(), exp[i]) != act.end()); } @@ -795,17 +781,17 @@ void assertAttributeUpdate(SerialNum serialNum, const document::DocumentId &docId, DocumentIdT lid, const MyAttributeWriter & adapter) { - EXPECT_EQUAL(serialNum, adapter._updateSerial); - EXPECT_EQUAL(docId, adapter._updateDocId); - EXPECT_EQUAL(lid, adapter._updateLid); + EXPECT_EQ(serialNum, adapter._updateSerial); + EXPECT_EQ(docId, adapter._updateDocId); + EXPECT_EQ(lid, adapter._updateLid); } } -TEST_F("require that put() updates document meta store with bucket info", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_put_updates_document_meta_store_with_bucket_info) { + SearchableFeedViewFixture f; DocumentContext dc = f.doc1(); f.putAndWait(dc); f.dms_commit(); @@ -813,36 +799,38 @@ TEST_F("require that put() updates document meta store with bucket info", assertBucketInfo(dc.bid, dc.ts, 1, f.getMetaStore()); // TODO: rewrite to use getBucketInfo() when available BucketInfo bucketInfo = f.getBucketDB()->get(dc.bid); - EXPECT_EQUAL(1u, bucketInfo.getDocumentCount()); - EXPECT_NOT_EQUAL(bucketInfo.getChecksum(), BucketChecksum(0)); + EXPECT_EQ(1u, bucketInfo.getDocumentCount()); + EXPECT_NE(bucketInfo.getChecksum(), BucketChecksum(0)); } -TEST_F("require that put() calls attribute adapter", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_put_calls_attribute_adapter) { + SearchableFeedViewFixture f; DocumentContext dc = f.doc1(); - EXPECT_EQUAL(0u, f._docIdLimit.get()); + EXPECT_EQ(0u, f._docIdLimit.get()); f.putAndWait(dc); f.forceCommitAndWait(); - EXPECT_EQUAL(1u, f.maw._putSerial); - EXPECT_EQUAL(DocumentId("id:ns:searchdocument::1"), f.maw._putDocId); - EXPECT_EQUAL(1u, f.maw._putLid); - EXPECT_EQUAL(2u, f._docIdLimit.get()); + EXPECT_EQ(1u, f.maw._putSerial); + EXPECT_EQ(DocumentId("id:ns:searchdocument::1"), f.maw._putDocId); + EXPECT_EQ(1u, f.maw._putLid); + EXPECT_EQ(2u, f._docIdLimit.get()); } -TEST_F("require that put() notifies gid to lid change handler", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_put_notifies_gid_to_lid_change_handler) { + SearchableFeedViewFixture f; DocumentContext dc1 = f.doc1(10); DocumentContext dc2 = f.doc1(20); f.putAndWait(dc1); - TEST_DO(f.assertChangeHandler(dc1.gid(), 1u, 1u)); + EXPECT_EQ((LastChange{dc1.gid(), 1u, 1u}), f.get_last_change()); f.putAndWait(dc2); - TEST_DO(f.assertChangeHandler(dc2.gid(), 1u, 1u)); + EXPECT_EQ((LastChange{dc2.gid(), 1u, 1u}), f.get_last_change()); } -TEST_F("require that update() updates document meta store with bucket info", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_update_updates_document_meta_store_with_bucket_info) { + SearchableFeedViewFixture f; DocumentContext dc1 = f.doc1(10); DocumentContext dc2 = f.doc1(20); f.putAndWait(dc1); @@ -853,13 +841,14 @@ TEST_F("require that update() updates document meta store with bucket info", assertBucketInfo(dc1.bid, Timestamp(20), 1, f.getMetaStore()); // TODO: rewrite to use getBucketInfo() when available BucketInfo bucketInfo = f.getBucketDB()->get(dc1.bid); - EXPECT_EQUAL(1u, bucketInfo.getDocumentCount()); - EXPECT_NOT_EQUAL(bucketInfo.getChecksum(), bcs); - EXPECT_NOT_EQUAL(bucketInfo.getChecksum(), BucketChecksum(0)); + EXPECT_EQ(1u, bucketInfo.getDocumentCount()); + EXPECT_NE(bucketInfo.getChecksum(), bcs); + EXPECT_NE(bucketInfo.getChecksum(), BucketChecksum(0)); } -TEST_F("require that update() calls attribute adapter", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_update_calls_attribute_adapter) { + SearchableFeedViewFixture f; DocumentContext dc1 = f.doc1(10); DocumentContext dc2 = f.doc1(20); f.putAndWait(dc1); @@ -868,9 +857,9 @@ TEST_F("require that update() calls attribute adapter", SearchableFeedViewFixtur assertAttributeUpdate(2u, DocumentId("id:ns:searchdocument::1"), 1u, f.maw); } -TEST_F("require that remove() updates document meta store with bucket info", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_remove_updates_document_meta_store_with_bucket_info) { + SearchableFeedViewFixture f; DocumentContext dc1 = f.doc("id:test:searchdocument:n=1:1", 10); DocumentContext dc2 = f.doc("id:test:searchdocument:n=1:2", 11); f.putAndWait(dc1); @@ -884,64 +873,65 @@ TEST_F("require that remove() updates document meta store with bucket info", EXPECT_FALSE(f.getMetaStore().validLid(2)); // don't remember remove // TODO: rewrite to use getBucketInfo() when available BucketInfo bucketInfo = f.getBucketDB()->get(dc1.bid); - EXPECT_EQUAL(1u, bucketInfo.getDocumentCount()); - EXPECT_NOT_EQUAL(bucketInfo.getChecksum(), bcs2); - EXPECT_EQUAL(bucketInfo.getChecksum(), bcs1); + EXPECT_EQ(1u, bucketInfo.getDocumentCount()); + EXPECT_NE(bucketInfo.getChecksum(), bcs2); + EXPECT_EQ(bucketInfo.getChecksum(), bcs1); } -TEST_F("require that remove() calls attribute adapter", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_remove_calls_attribute_adapter) { + SearchableFeedViewFixture f; DocumentContext dc1 = f.doc1(10); DocumentContext dc2 = f.doc1(20); f.putAndWait(dc1); f.removeAndWait(dc2); - EXPECT_EQUAL(2u, f.maw._removeSerial); - EXPECT_EQUAL(1u, f.maw._removeLid); + EXPECT_EQ(2u, f.maw._removeSerial); + EXPECT_EQ(1u, f.maw._removeLid); } -TEST_F("require that remove() notifies gid to lid change handler", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_remove_notifies_gid_to_lid_change_handler) { + SearchableFeedViewFixture f; DocumentContext dc1 = f.doc1(10); DocumentContext dc2 = f.doc1(20); f.putAndWait(dc1); - TEST_DO(f.assertChangeHandler(dc1.gid(), 1u, 1u)); + EXPECT_EQ((LastChange{dc1.gid(), 1u, 1u}), f.get_last_change()); f.removeAndWait(dc2); - TEST_DO(f.assertChangeHandler(dc2.gid(), 0u, 2u)); + EXPECT_EQ((LastChange{dc2.gid(), 0u, 2u}), f.get_last_change()); +} + +namespace { + +std::tuple get_execute_counts(const test::ThreadingServiceObserver &observer) { + return std::make_tuple(observer.masterObserver().getExecuteCnt(), + observer.indexObserver().getExecuteCnt(), + observer.summaryObserver().getExecuteCnt()); } -bool -assertThreadObserver(uint32_t masterExecuteCnt, - uint32_t indexExecuteCnt, - uint32_t summaryExecuteCnt, - const test::ThreadingServiceObserver &observer) -{ - if (!EXPECT_EQUAL(masterExecuteCnt, observer.masterObserver().getExecuteCnt())) return false; - if (!EXPECT_EQUAL(indexExecuteCnt, observer.indexObserver().getExecuteCnt())) return false; - if (!EXPECT_EQUAL(summaryExecuteCnt, observer.summaryObserver().getExecuteCnt())) return false; - return true; } -TEST_F("require that remove() calls removes_complete() via delayed thread service", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_remove_calls_removes_complete_via_delayed_thread_service) { - EXPECT_TRUE(assertThreadObserver(0, 0, 0, f.writeServiceObserver())); + SearchableFeedViewFixture f; + EXPECT_EQ(std::make_tuple(0u, 0u, 0u), get_execute_counts(f.writeServiceObserver())); f.putAndWait(f.doc1(10)); f.forceCommitAndWait(); // put index fields handled in index thread - EXPECT_TRUE(assertThreadObserver(2, 2, 2, f.writeServiceObserver())); + EXPECT_EQ(std::make_tuple(2u, 2u, 2u), get_execute_counts(f.writeServiceObserver())); f.removeAndWait(f.doc1(20)); f.forceCommitAndWait(); // remove index fields handled in index thread // delayed remove complete handled in same index thread, then master thread - EXPECT_TRUE(assertThreadObserver(5, 4, 4, f.writeServiceObserver())); - EXPECT_EQUAL(1u, f.metaStoreObserver()._removes_complete_cnt); + EXPECT_EQ(std::make_tuple(5u, 4u, 4u), get_execute_counts(f.writeServiceObserver())); + EXPECT_EQ(1u, f.metaStoreObserver()._removes_complete_cnt); ASSERT_FALSE(f.metaStoreObserver()._removes_complete_lids.empty()); - EXPECT_EQUAL(1u, f.metaStoreObserver()._removes_complete_lids.back()); + EXPECT_EQ(1u, f.metaStoreObserver()._removes_complete_lids.back()); } -TEST_F("require that handleDeleteBucket() removes documents", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_handleDeleteBucket_removes_documents) { + SearchableFeedViewFixture f; DocumentContext::List docs; docs.push_back(f.doc("id:test:searchdocument:n=1:1", 10)); docs.push_back(f.doc("id:test:searchdocument:n=1:2", 11)); @@ -950,21 +940,21 @@ TEST_F("require that handleDeleteBucket() removes documents", SearchableFeedView docs.push_back(f.doc("id:test:searchdocument:n=2:2", 14)); f.putAndWait(docs); - TEST_DO(f.assertChangeHandler(docs.back().gid(), 5u, 5u)); - TEST_DO(f.assertChangeNotified(docs[0].gid(), 1)); - TEST_DO(f.assertChangeNotified(docs[1].gid(), 2)); - TEST_DO(f.assertChangeNotified(docs[2].gid(), 3)); - TEST_DO(f.assertChangeNotified(docs[3].gid(), 4)); - TEST_DO(f.assertChangeNotified(docs[4].gid(), 5)); + EXPECT_EQ((LastChange{docs.back().gid(), 5u, 5u}), f.get_last_change()); + EXPECT_EQ(1, f.get_notified_lid(docs[0].gid())); + EXPECT_EQ(2, f.get_notified_lid(docs[1].gid())); + EXPECT_EQ(3, f.get_notified_lid(docs[2].gid())); + EXPECT_EQ(4, f.get_notified_lid(docs[3].gid())); + EXPECT_EQ(5, f.get_notified_lid(docs[4].gid())); f.dms_commit(); DocumentIdT lid; EXPECT_TRUE(f.getMetaStore().getLid(docs[0].doc->getId().getGlobalId(), lid)); - EXPECT_EQUAL(1u, lid); + EXPECT_EQ(1u, lid); EXPECT_TRUE(f.getMetaStore().getLid(docs[1].doc->getId().getGlobalId(), lid)); - EXPECT_EQUAL(2u, lid); + EXPECT_EQ(2u, lid); EXPECT_TRUE(f.getMetaStore().getLid(docs[2].doc->getId().getGlobalId(), lid)); - EXPECT_EQUAL(3u, lid); + EXPECT_EQ(3u, lid); // delete bucket for user 1 DeleteBucketOperation op(docs[0].bid); @@ -975,8 +965,8 @@ TEST_F("require that handleDeleteBucket() removes documents", SearchableFeedView gate.await(); f.dms_commit(); - EXPECT_EQUAL(0u, f.getBucketDB()->get(docs[0].bid).getDocumentCount()); - EXPECT_EQUAL(2u, f.getBucketDB()->get(docs[3].bid).getDocumentCount()); + EXPECT_EQ(0u, f.getBucketDB()->get(docs[0].bid).getDocumentCount()); + EXPECT_EQ(2u, f.getBucketDB()->get(docs[3].bid).getDocumentCount()); EXPECT_FALSE(f.getMetaStore().getLid(docs[0].doc->getId().getGlobalId(), lid)); EXPECT_FALSE(f.getMetaStore().getLid(docs[1].doc->getId().getGlobalId(), lid)); EXPECT_FALSE(f.getMetaStore().getLid(docs[2].doc->getId().getGlobalId(), lid)); @@ -984,19 +974,19 @@ TEST_F("require that handleDeleteBucket() removes documents", SearchableFeedView assertLidVector(exp, f.miw._removes); assertLidVector(exp, f.msa._removes); assertLidVector(exp, f.maw._removes); - TEST_DO(f.assertChangeHandlerCount(8)); - TEST_DO(f.assertChangeNotified(docs[0].gid(), 0)); - TEST_DO(f.assertChangeNotified(docs[1].gid(), 0)); - TEST_DO(f.assertChangeNotified(docs[2].gid(), 0)); - TEST_DO(f.assertChangeNotified(docs[3].gid(), 4)); - TEST_DO(f.assertChangeNotified(docs[4].gid(), 5)); + EXPECT_EQ(8, f.get_change_handler_count()); + EXPECT_EQ(0, f.get_notified_lid(docs[0].gid())); + EXPECT_EQ(0, f.get_notified_lid(docs[1].gid())); + EXPECT_EQ(0, f.get_notified_lid(docs[2].gid())); + EXPECT_EQ(4, f.get_notified_lid(docs[3].gid())); + EXPECT_EQ(5, f.get_notified_lid(docs[4].gid())); } void assertPostConditionAfterRemoves(const DocumentContext::List &docs, SearchableFeedViewFixture &f) { - EXPECT_EQUAL(3u, f.getMetaStore().getNumUsedLids()); + EXPECT_EQ(3u, f.getMetaStore().getNumUsedLids()); EXPECT_FALSE(f.getMetaData(docs[0]).valid()); EXPECT_TRUE(f.getMetaData(docs[1]).valid()); EXPECT_FALSE(f.getMetaData(docs[1]).removed); @@ -1009,13 +999,14 @@ assertPostConditionAfterRemoves(const DocumentContext::List &docs, assertLidVector(MyLidVector().add(1).add(4), f.miw._removes); assertLidVector(MyLidVector().add(1).add(4), f.msa._removes); MyDocumentStore::DocMap &sdocs = f.msa._store._docs; - EXPECT_EQUAL(3u, sdocs.size()); + EXPECT_EQ(3u, sdocs.size()); EXPECT_TRUE(sdocs.find(1) == sdocs.end()); EXPECT_TRUE(sdocs.find(4) == sdocs.end()); } -TEST_F("require that removes are not remembered", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_removes_are_not_remembered) { + SearchableFeedViewFixture f; DocumentContext::List docs; docs.push_back(f.doc("id:test:searchdocument:n=1:1", 10)); docs.push_back(f.doc("id:test:searchdocument:n=1:2", 11)); @@ -1043,7 +1034,7 @@ TEST_F("require that removes are not remembered", SearchableFeedViewFixture) f.forceCommitAndWait(); f.putAndWait(docs[0]); f.forceCommitAndWait(); - EXPECT_EQUAL(5u, f.getMetaStore().getNumUsedLids()); + EXPECT_EQ(5u, f.getMetaStore().getNumUsedLids()); EXPECT_TRUE(f.getMetaData(docs[0]).valid()); EXPECT_TRUE(f.getMetaData(docs[1]).valid()); EXPECT_TRUE(f.getMetaData(docs[2]).valid()); @@ -1054,43 +1045,43 @@ TEST_F("require that removes are not remembered", SearchableFeedViewFixture) EXPECT_FALSE(f.getMetaData(docs[2]).removed); EXPECT_FALSE(f.getMetaData(docs[3]).removed); EXPECT_FALSE(f.getMetaData(docs[4]).removed); - EXPECT_EQUAL(5u, f.msa._store._docs.size()); + EXPECT_EQ(5u, f.msa._store._docs.size()); const Document::SP &doc1 = f.msa._store._docs[1]; - EXPECT_EQUAL(docs[3].doc->getId(), doc1->getId()); - EXPECT_EQUAL(docs[3].doc->getId().toString(), - doc1->getValue("s1")->toString()); + EXPECT_EQ(docs[3].doc->getId(), doc1->getId()); + EXPECT_EQ(docs[3].doc->getId().toString(), doc1->getValue("s1")->toString()); const Document::SP &doc4 = f.msa._store._docs[4]; - EXPECT_EQUAL(docs[0].doc->getId(), doc4->getId()); - EXPECT_EQUAL(docs[0].doc->getId().toString(), - doc4->getValue("s1")->toString()); - EXPECT_EQUAL(5u, f.msa._store._docs.size()); + EXPECT_EQ(docs[0].doc->getId(), doc4->getId()); + EXPECT_EQ(docs[0].doc->getId().toString(), doc4->getValue("s1")->toString()); + EXPECT_EQ(5u, f.msa._store._docs.size()); f.removeAndWait(docs[0]); f.forceCommitAndWait(); f.removeAndWait(docs[3]); f.forceCommitAndWait(); - EXPECT_EQUAL(3u, f.msa._store._docs.size()); + EXPECT_EQ(3u, f.msa._store._docs.size()); } -TEST_F("require that heartbeat propagates to index- and attributeadapter", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_heartbeat_propagates_to_index_and_attribute_adapter) { + SearchableFeedViewFixture f; vespalib::Gate gate; f.runInMaster([&, onDone = std::make_shared(gate)]() { f.fv.heartBeat(2, std::move(onDone)); }); gate.await(); - EXPECT_EQUAL(1, f.miw._heartBeatCount); - EXPECT_EQUAL(1, f.maw._heartBeatCount); + EXPECT_EQ(1, f.miw._heartBeatCount); + EXPECT_EQ(1, f.maw._heartBeatCount); } +namespace { + template void putDocumentAndUpdate(Fixture &f, const std::string &fieldName) { DocumentContext dc1 = f.doc1(); f.putAndWait(dc1); f.forceCommitAndWait(); - EXPECT_EQUAL(1u, f.msa._store._lastSyncToken); + EXPECT_EQ(1u, f.msa._store._lastSyncToken); DocumentContext dc2("id:ns:searchdocument::1", 20, f.getBuilder()); dc2.addFieldUpdate(f.getBuilder(), fieldName); @@ -1104,7 +1095,7 @@ void requireThatUpdateOnlyUpdatesAttributeAndNotDocumentStore(Fixture &f, { putDocumentAndUpdate(f, fieldName); - EXPECT_EQUAL(1u, f.msa._store._lastSyncToken); // document store not updated + EXPECT_EQ(1u, f.msa._store._lastSyncToken); // document store not updated assertAttributeUpdate(2u, DocumentId("id:ns:searchdocument::1"), 1, f.maw); } @@ -1114,81 +1105,80 @@ void requireThatUpdateUpdatesAttributeAndDocumentStore(Fixture &f, { putDocumentAndUpdate(f, fieldName); - EXPECT_EQUAL(2u, f.msa._store._lastSyncToken); // document store updated + EXPECT_EQ(2u, f.msa._store._lastSyncToken); // document store updated assertAttributeUpdate(2u, DocumentId("id:ns:searchdocument::1"), 1, f.maw); } -TEST_F("require that update() to fast-access attribute only updates attribute and not document store", - FastAccessFeedViewFixture) +} + +TEST(FeedViewTest, require_that_update_to_fast_access_attribute_only_updates_attribute_and_not_document_store) { + FastAccessFeedViewFixture f; f.maw._attrs.insert("a1"); // mark a1 as fast-access attribute field requireThatUpdateOnlyUpdatesAttributeAndNotDocumentStore(f, "a1"); } -TEST_F("require that update() to attribute only updates attribute and not document store", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_update_to_attribute_only_updates_attribute_and_not_document_store) { + SearchableFeedViewFixture f; f.maw._attrs.insert("a1"); // mark a1 as attribute field requireThatUpdateOnlyUpdatesAttributeAndNotDocumentStore(f, "a1"); } -TEST_F("require that update to non fast-access attribute also updates document store", - FastAccessFeedViewFixture) +TEST(FeedViewTest, require_that_update_to_non_fast_access_attribute_also_updates_document_store) { + FastAccessFeedViewFixture f; requireThatUpdateUpdatesAttributeAndDocumentStore(f, "a1"); } -TEST_F("require that update() to fast-access predicate attribute updates attribute and document store", - FastAccessFeedViewFixture) +TEST(FeedViewTest, require_that_update_to_fast_access_predicate_attribute_updates_attribute_and_document_store) { + FastAccessFeedViewFixture f; f.maw._attrs.insert("a2"); // mark a2 as fast-access attribute field requireThatUpdateUpdatesAttributeAndDocumentStore(f, "a2"); } -TEST_F("require that update() to predicate attribute updates attribute and document store", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_update_to_predicate_attribute_updates_attribute_and_document_store) { + SearchableFeedViewFixture f; f.maw._attrs.insert("a2"); // mark a2 as attribute field requireThatUpdateUpdatesAttributeAndDocumentStore(f, "a2"); } -TEST_F("require that update() to fast-access tensor attribute only updates attribute and NOT document store", - FastAccessFeedViewFixture) +TEST(FeedViewTest, require_that_update_to_fast_access_tensor_attribute_only_updates_attribute_and_not_document_store) { + FastAccessFeedViewFixture f; f.maw._attrs.insert("a3"); // mark a3 as fast-access attribute field requireThatUpdateOnlyUpdatesAttributeAndNotDocumentStore(f, "a3"); } -TEST_F("require that update() to tensor attribute only updates attribute and NOT document store", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_update_to_tensor_attribute_only_updates_attribute_and_not_document_store) { + SearchableFeedViewFixture f; f.maw._attrs.insert("a3"); // mark a3 as attribute field requireThatUpdateOnlyUpdatesAttributeAndNotDocumentStore(f, "a3"); } -TEST_F("require that compactLidSpace() propagates to document meta store and document store and " - "blocks lid space shrinkage until generation is no longer used", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_compactLidSpace_propagates_to_document_meta_store_and_document_store_and_blocks_lid_space_shrinkage_until_generation_is_no_longer_used) { + SearchableFeedViewFixture f; f.populateBeforeCompactLidSpace(); - EXPECT_TRUE(assertThreadObserver(5, 4, 4, f.writeServiceObserver())); + EXPECT_EQ(std::make_tuple(5u, 4u, 4u), get_execute_counts(f.writeServiceObserver())); f.compactLidSpaceAndWait(2); // performIndexForceCommit in index thread, then completion callback // in master thread. - EXPECT_TRUE(assertThreadObserver(7, 7, 7, f.writeServiceObserver())); - EXPECT_EQUAL(2u, f.metaStoreObserver()._compactLidSpaceLidLimit); - EXPECT_EQUAL(2u, f.getDocumentStore()._compactLidSpaceLidLimit); - EXPECT_EQUAL(1u, f.metaStoreObserver()._holdUnblockShrinkLidSpaceCnt); - EXPECT_EQUAL(2u, f._docIdLimit.get()); + EXPECT_EQ(std::make_tuple(7u, 7u, 7u), get_execute_counts(f.writeServiceObserver())); + EXPECT_EQ(2u, f.metaStoreObserver()._compactLidSpaceLidLimit); + EXPECT_EQ(2u, f.getDocumentStore()._compactLidSpaceLidLimit); + EXPECT_EQ(1u, f.metaStoreObserver()._holdUnblockShrinkLidSpaceCnt); + EXPECT_EQ(2u, f._docIdLimit.get()); } -TEST_F("require that compactLidSpace() doesn't propagate to " - "document meta store and document store and " - "blocks lid space shrinkage until generation is no longer used", - SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_compactLidSpace_doesnt_propagate_to_document_meta_store_and_document_store_and_blocks_lid_space_shrinkage_until_generation_is_no_longer_used) { + SearchableFeedViewFixture f; f.populateBeforeCompactLidSpace(); - EXPECT_TRUE(assertThreadObserver(5, 4, 4, f.writeServiceObserver())); + EXPECT_EQ(std::make_tuple(5u, 4u, 4u), get_execute_counts(f.writeServiceObserver())); CompactLidSpaceOperation op(0, 2); op.setSerialNum(0); Gate gate; @@ -1198,99 +1188,105 @@ TEST_F("require that compactLidSpace() doesn't propagate to " gate.await(); f._writeService.master().sync(); // Delayed holdUnblockShrinkLidSpace() in index thread, then master thread - EXPECT_TRUE(assertThreadObserver(6, 6, 5, f.writeServiceObserver())); - EXPECT_EQUAL(0u, f.metaStoreObserver()._compactLidSpaceLidLimit); - EXPECT_EQUAL(0u, f.getDocumentStore()._compactLidSpaceLidLimit); - EXPECT_EQUAL(0u, f.metaStoreObserver()._holdUnblockShrinkLidSpaceCnt); + EXPECT_EQ(std::make_tuple(6u, 6u, 5u), get_execute_counts(f.writeServiceObserver())); + EXPECT_EQ(0u, f.metaStoreObserver()._compactLidSpaceLidLimit); + EXPECT_EQ(0u, f.getDocumentStore()._compactLidSpaceLidLimit); + EXPECT_EQ(0u, f.metaStoreObserver()._holdUnblockShrinkLidSpaceCnt); } -TEST_F("require that compactLidSpace() propagates to attributeadapter", FastAccessFeedViewFixture) +TEST(FeedViewTest, require_that_compactLidSpace_propagates_to_attribute_adapter) { + FastAccessFeedViewFixture f; f.populateBeforeCompactLidSpace(); f.compactLidSpaceAndWait(2); - EXPECT_EQUAL(2u, f.maw._wantedLidLimit); + EXPECT_EQ(2u, f.maw._wantedLidLimit); } -TEST_F("require that compactLidSpace() propagates to index writer", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_compactLidSpace_propagates_to_index_writer) { + SearchableFeedViewFixture f; f.populateBeforeCompactLidSpace(); f.compactLidSpaceAndWait(2); - EXPECT_EQUAL(2u, f.miw._wantedLidLimit); + EXPECT_EQ(2u, f.miw._wantedLidLimit); } -TEST_F("require that commit is not implicitly called", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_commit_is_not_implicitly_called) { + SearchableFeedViewFixture f; DocumentContext dc = f.doc1(); f.putAndWait(dc); - EXPECT_EQUAL(0u, f.miw._commitCount); - EXPECT_EQUAL(0u, f.maw._commitCount); - EXPECT_EQUAL(0u, f._docIdLimit.get()); + EXPECT_EQ(0u, f.miw._commitCount); + EXPECT_EQ(0u, f.maw._commitCount); + EXPECT_EQ(0u, f._docIdLimit.get()); f.removeAndWait(dc); - EXPECT_EQUAL(0u, f.miw._commitCount); - EXPECT_EQUAL(0u, f.maw._commitCount); - EXPECT_EQUAL(0u, f._docIdLimit.get()); - f.assertTrace("put(adapter=attribute,serialNum=1,lid=1)," - "put(adapter=index,serialNum=1,lid=1)," - "ack(Result(0, ))," - "remove(adapter=attribute,serialNum=2,lid=1)," - "remove(adapter=index,serialNum=2,lid=1)," - "ack(Result(0, ))"); + EXPECT_EQ(0u, f.miw._commitCount); + EXPECT_EQ(0u, f.maw._commitCount); + EXPECT_EQ(0u, f._docIdLimit.get()); + EXPECT_EQ("put(adapter=attribute,serialNum=1,lid=1)," + "put(adapter=index,serialNum=1,lid=1)," + "ack(Result(0, ))," + "remove(adapter=attribute,serialNum=2,lid=1)," + "remove(adapter=index,serialNum=2,lid=1)," + "ack(Result(0, ))", f.get_trace()); f.forceCommitAndWait(); } -TEST_F("require that forceCommit updates docid limit", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_forceCommit_updates_docid_limit) { + SearchableFeedViewFixture f; DocumentContext dc = f.doc1(); f.putAndWait(dc); - EXPECT_EQUAL(0u, f.miw._commitCount); - EXPECT_EQUAL(0u, f.maw._commitCount); - EXPECT_EQUAL(0u, f._docIdLimit.get()); + EXPECT_EQ(0u, f.miw._commitCount); + EXPECT_EQ(0u, f.maw._commitCount); + EXPECT_EQ(0u, f._docIdLimit.get()); f.forceCommitAndWait(); - EXPECT_EQUAL(1u, f.miw._commitCount); - EXPECT_EQUAL(1u, f.maw._commitCount); - EXPECT_EQUAL(2u, f._docIdLimit.get()); - f.assertTrace("put(adapter=attribute,serialNum=1,lid=1)," - "put(adapter=index,serialNum=1,lid=1)," - "ack(Result(0, ))," - "commit(adapter=attribute,serialNum=1)," - "commit(adapter=index,serialNum=1)"); + EXPECT_EQ(1u, f.miw._commitCount); + EXPECT_EQ(1u, f.maw._commitCount); + EXPECT_EQ(2u, f._docIdLimit.get()); + EXPECT_EQ("put(adapter=attribute,serialNum=1,lid=1)," + "put(adapter=index,serialNum=1,lid=1)," + "ack(Result(0, ))," + "commit(adapter=attribute,serialNum=1)," + "commit(adapter=index,serialNum=1)", f.get_trace()); } -TEST_F("require that forceCommit updates docid limit during shrink", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_forceCommit_updates_docid_limit_during_shrink) { + SearchableFeedViewFixture f; f.putAndWait(f.makeDummyDocs(0, 3, 1000)); - EXPECT_EQUAL(0u, f._docIdLimit.get()); + EXPECT_EQ(0u, f._docIdLimit.get()); f.forceCommitAndWait(); - EXPECT_EQUAL(4u, f._docIdLimit.get()); + EXPECT_EQ(4u, f._docIdLimit.get()); f.removeAndWait(f.makeDummyDocs(1, 2, 2000)); - EXPECT_EQUAL(4u, f._docIdLimit.get()); + EXPECT_EQ(4u, f._docIdLimit.get()); f.forceCommitAndWait(); - EXPECT_EQUAL(4u, f._docIdLimit.get()); + EXPECT_EQ(4u, f._docIdLimit.get()); f.compactLidSpaceAndWait(2); - EXPECT_EQUAL(2u, f._docIdLimit.get()); + EXPECT_EQ(2u, f._docIdLimit.get()); f.forceCommitAndWait(); - EXPECT_EQUAL(2u, f._docIdLimit.get()); + EXPECT_EQ(2u, f._docIdLimit.get()); f.putAndWait(f.makeDummyDocs(1, 1, 3000)); - EXPECT_EQUAL(2u, f._docIdLimit.get()); + EXPECT_EQ(2u, f._docIdLimit.get()); f.forceCommitAndWait(); - EXPECT_EQUAL(3u, f._docIdLimit.get()); + EXPECT_EQ(3u, f._docIdLimit.get()); } -TEST_F("require that move() notifies gid to lid change handler", SearchableFeedViewFixture) +TEST(FeedViewTest, require_that_move_notifies_gid_to_lid_change_handler) { + SearchableFeedViewFixture f; DocumentContext dc1 = f.doc("id::searchdocument::1", 10); DocumentContext dc2 = f.doc("id::searchdocument::2", 20); f.putAndWait(dc1); f.forceCommitAndWait(); - TEST_DO(f.assertChangeHandler(dc1.gid(), 1u, 1u)); + EXPECT_EQ((LastChange{dc1.gid(), 1u, 1u}), f.get_last_change()); f.putAndWait(dc2); f.forceCommitAndWait(); - TEST_DO(f.assertChangeHandler(dc2.gid(), 2u, 2u)); + EXPECT_EQ((LastChange{dc2.gid(), 2u, 2u}), f.get_last_change()); DocumentContext dc3 = f.doc("id::searchdocument::1", 30); f.removeAndWait(dc3); f.forceCommitAndWait(); - TEST_DO(f.assertChangeHandler(dc3.gid(), 0u, 3u)); + EXPECT_EQ((LastChange{dc3.gid(), 0u, 3u}), f.get_last_change()); f.moveAndWait(dc2, 2, 1); f.forceCommitAndWait(); - TEST_DO(f.assertChangeHandler(dc2.gid(), 1u, 4u)); + EXPECT_EQ((LastChange{dc2.gid(), 1u, 4u}), f.get_last_change()); } diff --git a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp index 1d3303d58f67..b31a8ca73c05 100644 --- a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp +++ b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp @@ -17,11 +17,11 @@ #include #include #include +#include #include #include -#include -#include #include +#include #include LOG_SETUP("document_db_reference_resolver_test"); @@ -99,7 +99,7 @@ struct MyReferenceRegistry : public IDocumentDBReferenceRegistry { ReferenceMap map; IDocumentDBReference::SP get(std::string_view name) const override { auto itr = map.find(std::string(name)); - ASSERT_TRUE(itr != map.end()); + assert(itr != map.end()); return itr->second; } IDocumentDBReference::SP tryGet(std::string_view name) const override { @@ -126,7 +126,7 @@ struct MyAttributeManager : public MockAttributeManager { const ReferenceAttribute *getReferenceAttribute(const std::string &name) const { AttributeGuard::UP guard = getAttribute(name); auto *result = dynamic_cast(guard->get()); - ASSERT_TRUE(result != nullptr); + assert(result != nullptr); return result; } }; @@ -186,13 +186,17 @@ const ImportedAttributeVector & asImportedAttribute(const IAttributeVector &attr) { auto *result = dynamic_cast(&attr); - ASSERT_TRUE(result != nullptr); + assert(result != nullptr); return *result; } VESPA_THREAD_STACK_TAG(attribute_executor) -struct Fixture { +using AddVector = std::vector; +using RemoveVector = std::vector; + +class DocumentDBReferenceResolverTest : public ::testing::Test { +protected: MyGidToLidMapperFactory::SP factory; MonitoredRefCount _gidToLidChangeListenerRefCount; std::unique_ptr _attributeFieldWriter; @@ -205,24 +209,8 @@ struct Fixture { MyAttributeManager oldAttrMgr; DocumentModel docModel; ImportedFieldsConfig importedFieldsCfg; - Fixture() : - factory(std::make_shared()), - _gidToLidChangeListenerRefCount(), - _attributeFieldWriter(SequencedTaskExecutor::create(attribute_executor, 1)), - _parentGidToLidChangeHandler(std::make_shared()), - _parentGidToLidChangeHandler2(std::make_shared()), - parentReference(std::make_shared(factory, _parentGidToLidChangeHandler)), - parentReference2(std::make_shared(factory, _parentGidToLidChangeHandler2)), - registry(), - attrMgr(), - docModel(), - importedFieldsCfg(createImportedFieldsConfig()) - { - registry.add("parent", parentReference); - registry.add("parent2", parentReference2); - populateTargetAttributes(); - populateAttributeManagers(); - } + DocumentDBReferenceResolverTest(); + ~DocumentDBReferenceResolverTest() override; void populateTargetAttributes() { parentReference->addIntAttribute("target_a"); parentReference->addIntAttribute("target_b"); @@ -260,10 +248,10 @@ struct Fixture { bool useSearchCache, const ImportedAttributeVector::SP & attr) { ASSERT_TRUE(attr.get()); - EXPECT_EQUAL(name, attr->getName()); - EXPECT_EQUAL(attrMgr.getReferenceAttribute(referenceField), attr->getReferenceAttribute().get()); - EXPECT_EQUAL(parentReference->getAttribute(targetField).get(), attr->getTargetAttribute().get()); - EXPECT_EQUAL(useSearchCache, attr->getSearchCache().get() != nullptr); + EXPECT_EQ(name, attr->getName()); + EXPECT_EQ(attrMgr.getReferenceAttribute(referenceField), attr->getReferenceAttribute().get()); + EXPECT_EQ(parentReference->getAttribute(targetField).get(), attr->getTargetAttribute().get()); + EXPECT_EQ(useSearchCache, attr->getSearchCache().get() != nullptr); } MockGidToLidChangeHandler &getGidToLidChangeHandler(const std::string &referencedDocTypeName) { @@ -273,81 +261,98 @@ struct Fixture { return reference->getGidToLidChangeHandler(); } - void assertParentAdds(const std::string &referencedDocTypeName, const std::vector &expAdds) - { - auto &handler = getGidToLidChangeHandler(referencedDocTypeName); - handler.assertAdds(expAdds); + const AddVector& get_parent_adds(const std::string &referenced_doc_type_name) { + auto& handler = getGidToLidChangeHandler(referenced_doc_type_name); + return handler.get_adds(); } - void assertParentRemoves(const std::string &referencedDocTypeName, const std::vector &expRemoves) - { - auto &handler = getGidToLidChangeHandler(referencedDocTypeName); - handler.assertRemoves(expRemoves); + const RemoveVector& get_parent_removes(const std::string &referenced_doc_type_name) { + auto& handler = getGidToLidChangeHandler(referenced_doc_type_name); + return handler.get_removes(); } }; -TEST_F("require that reference attributes are connected to gid mapper", Fixture) +DocumentDBReferenceResolverTest::DocumentDBReferenceResolverTest() + : testing::Test(), + factory(std::make_shared()), + _gidToLidChangeListenerRefCount(), + _attributeFieldWriter(SequencedTaskExecutor::create(attribute_executor, 1)), + _parentGidToLidChangeHandler(std::make_shared()), + _parentGidToLidChangeHandler2(std::make_shared()), + parentReference(std::make_shared(factory, _parentGidToLidChangeHandler)), + parentReference2(std::make_shared(factory, _parentGidToLidChangeHandler2)), + registry(), + attrMgr(), + docModel(), + importedFieldsCfg(createImportedFieldsConfig()) { - f.resolve(); - EXPECT_EQUAL(f.factory.get(), f.getMapperFactoryPtr("ref")); - EXPECT_EQUAL(f.factory.get(), f.getMapperFactoryPtr("other_ref")); + registry.add("parent", parentReference); + registry.add("parent2", parentReference2); + populateTargetAttributes(); + populateAttributeManagers(); } -TEST_F("require that reference attributes are not connected to gid mapper during replay", Fixture) +DocumentDBReferenceResolverTest::~DocumentDBReferenceResolverTest() = default; + +TEST_F(DocumentDBReferenceResolverTest, require_that_reference_attributes_are_connected_to_gid_mapper) { - f.resolveReplay(); - EXPECT_EQUAL(static_cast(nullptr), f.getMapperFactoryPtr("ref")); - EXPECT_EQUAL(static_cast(nullptr), f.getMapperFactoryPtr("other_ref")); + resolve(); + EXPECT_EQ(factory.get(), getMapperFactoryPtr("ref")); + EXPECT_EQ(factory.get(), getMapperFactoryPtr("other_ref")); } -TEST_F("require that imported attributes are instantiated without search cache as default", Fixture) +TEST_F(DocumentDBReferenceResolverTest, require_that_reference_attributes_are_not_connected_to_gid_mapper_during_replay) { - auto repo = f.resolve(); - EXPECT_EQUAL(2u, repo->size()); - f.assertImportedAttribute("imported_a", "ref", "target_a", false, repo->get("imported_a")); - f.assertImportedAttribute("imported_b", "other_ref", "target_b", false, repo->get("imported_b")); + resolveReplay(); + EXPECT_EQ(static_cast(nullptr), getMapperFactoryPtr("ref")); + EXPECT_EQ(static_cast(nullptr), getMapperFactoryPtr("other_ref")); } -TEST_F("require that imported attributes are instantiated with search cache if visibility delay > 0", Fixture) +TEST_F(DocumentDBReferenceResolverTest, require_that_imported_attributes_are_instantiated_without_search_cache_as_default) { - auto repo = f.resolve(1s); - EXPECT_EQUAL(2u, repo->size()); - f.assertImportedAttribute("imported_a", "ref", "target_a", true, repo->get("imported_a")); - f.assertImportedAttribute("imported_b", "other_ref", "target_b", true, repo->get("imported_b")); + auto repo = resolve(); + EXPECT_EQ(2u, repo->size()); + assertImportedAttribute("imported_a", "ref", "target_a", false, repo->get("imported_a")); + assertImportedAttribute("imported_b", "other_ref", "target_b", false, repo->get("imported_b")); } -TEST_F("require that missing target attribute prevents creation of imported attribute", Fixture) +TEST_F(DocumentDBReferenceResolverTest, require_that_imported_attributes_are_instantiated_with_search_cache_if_visibility_delay_gt_0) { - f.parentReference->removeAttribute("target_a"); - auto repo = f.resolve(); - EXPECT_EQUAL(1u, repo->size()); - EXPECT_FALSE(repo->get("imported_a")); - EXPECT_TRUE(repo->get("imported_b")); + auto repo = resolve(1s); + EXPECT_EQ(2u, repo->size()); + assertImportedAttribute("imported_a", "ref", "target_a", true, repo->get("imported_a")); + assertImportedAttribute("imported_b", "other_ref", "target_b", true, repo->get("imported_b")); } -TEST_F("require that listeners are added", Fixture) +TEST_F(DocumentDBReferenceResolverTest, require_that_missing_target_attribute_prevents_creation_of_imported_attribute) { - f.resolve(); - TEST_DO(f.assertParentAdds("parent", {{"child","other_ref"},{"child","ref"}})); - TEST_DO(f.assertParentRemoves("parent", {{"child", {"other_ref","ref"}}})); - auto &listeners = f.getGidToLidChangeHandler("parent").getListeners(); - EXPECT_EQUAL(2u, listeners.size()); - EXPECT_EQUAL(f.attrMgr.getReferenceAttribute("other_ref"), getReferenceAttribute(*listeners[0])); - EXPECT_EQUAL(f.attrMgr.getReferenceAttribute("ref"), getReferenceAttribute(*listeners[1])); - TEST_DO(f.assertParentAdds("parent2", {})); - TEST_DO(f.assertParentRemoves("parent2", {{"child", {}}})); + parentReference->removeAttribute("target_a"); + auto repo = resolve(); + EXPECT_EQ(1u, repo->size()); + EXPECT_FALSE(repo->get("imported_a")); + EXPECT_TRUE(repo->get("imported_b")); } -TEST_F("require that listeners are removed", Fixture) +TEST_F(DocumentDBReferenceResolverTest, require_that_listeners_are_added) { - f.teardown(); - TEST_DO(f.assertParentAdds("parent", {})); - TEST_DO(f.assertParentRemoves("parent", {{"child", {}}})); - TEST_DO(f.assertParentAdds("parent2", {})); - TEST_DO(f.assertParentRemoves("parent2", {})); + resolve(); + EXPECT_EQ((AddVector{{"child","other_ref"},{"child","ref"}}), get_parent_adds("parent")); + EXPECT_EQ((RemoveVector{{"child", {"other_ref","ref"}}}), get_parent_removes("parent")); + auto &listeners = getGidToLidChangeHandler("parent").getListeners(); + EXPECT_EQ(2u, listeners.size()); + EXPECT_EQ(attrMgr.getReferenceAttribute("other_ref"), getReferenceAttribute(*listeners[0])); + EXPECT_EQ(attrMgr.getReferenceAttribute("ref"), getReferenceAttribute(*listeners[1])); + EXPECT_EQ(AddVector{}, get_parent_adds("parent2")); + EXPECT_EQ((RemoveVector{{"child", {}}}), get_parent_removes("parent2")); } -TEST_MAIN() +TEST_F(DocumentDBReferenceResolverTest, require_that_listeners_are_removed) { - TEST_RUN_ALL(); + teardown(); + EXPECT_EQ(AddVector{}, get_parent_adds("parent")); + EXPECT_EQ((RemoveVector{{"child", {}}}), get_parent_removes("parent")); + EXPECT_EQ(AddVector{}, get_parent_adds("parent2")); + EXPECT_EQ(RemoveVector{}, get_parent_removes("parent2")); } + +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchcore/src/tests/proton/reference/gid_to_lid_change_registrator/gid_to_lid_change_registrator_test.cpp b/searchcore/src/tests/proton/reference/gid_to_lid_change_registrator/gid_to_lid_change_registrator_test.cpp index a0a7495b76b0..34ed00317c56 100644 --- a/searchcore/src/tests/proton/reference/gid_to_lid_change_registrator/gid_to_lid_change_registrator_test.cpp +++ b/searchcore/src/tests/proton/reference/gid_to_lid_change_registrator/gid_to_lid_change_registrator_test.cpp @@ -1,11 +1,10 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include + #include -#include #include #include #include -#include +#include #include #include @@ -38,61 +37,61 @@ using test::MockGidToLidChangeHandler; using AddEntry = MockGidToLidChangeHandler::AddEntry; using RemoveEntry = MockGidToLidChangeHandler::RemoveEntry; -struct Fixture +using AddVector = std::vector; +using RemoveVector = std::vector; + +class GidToLidChangeRregistratorTest : public ::testing::Test { std::shared_ptr _handler; - Fixture() - : _handler(std::make_shared()) - { - } - - ~Fixture() { } +protected: + GidToLidChangeRregistratorTest(); + ~GidToLidChangeRregistratorTest() override; std::unique_ptr getRegistrator(const std::string &docTypeName) { return std::make_unique(_handler, docTypeName); } - void assertAdds(const std::vector &expAdds) { - _handler->assertAdds(expAdds); - } - - void assertRemoves(const std::vector &expRemoves) { - _handler->assertRemoves(expRemoves); - } + const AddVector& get_adds() const noexcept { return _handler->get_adds(); } + const RemoveVector& get_removes() const noexcept { return _handler->get_removes(); } }; -TEST_F("Test that we can register a listener", Fixture) +GidToLidChangeRregistratorTest::GidToLidChangeRregistratorTest() + : ::testing::Test(), + _handler(std::make_shared()) { - auto registrator = f.getRegistrator("testdoc"); - TEST_DO(f.assertAdds({})); - TEST_DO(f.assertRemoves({})); +} + +GidToLidChangeRregistratorTest::~GidToLidChangeRregistratorTest() = default; + +TEST_F(GidToLidChangeRregistratorTest, we_can_register_a_listener) +{ + auto registrator = getRegistrator("testdoc"); + EXPECT_EQ(AddVector{}, get_adds()); + EXPECT_EQ(RemoveVector{}, get_removes()); registrator->addListener(std::make_unique("testdoc", "f1")); - TEST_DO(f.assertAdds({{"testdoc","f1"}})); - TEST_DO(f.assertRemoves({})); + EXPECT_EQ((AddVector{{"testdoc","f1"}}), get_adds()); + EXPECT_EQ(RemoveVector{}, get_removes()); registrator.reset(); - TEST_DO(f.assertAdds({{"testdoc","f1"}})); - TEST_DO(f.assertRemoves({{"testdoc",{"f1"}}})); + EXPECT_EQ((AddVector{{"testdoc","f1"}}), get_adds()); + EXPECT_EQ((RemoveVector{{"testdoc",{"f1"}}}), get_removes()); } -TEST_F("Test that we can register multiple listeners", Fixture) +TEST_F(GidToLidChangeRregistratorTest, we_can_register_multiple_listeners) { - auto registrator = f.getRegistrator("testdoc"); - TEST_DO(f.assertAdds({})); - TEST_DO(f.assertRemoves({})); + auto registrator = getRegistrator("testdoc"); + EXPECT_EQ(AddVector{}, get_adds()); + EXPECT_EQ(RemoveVector{}, get_removes()); registrator->addListener(std::make_unique("testdoc", "f1")); registrator->addListener(std::make_unique("testdoc", "f2")); - TEST_DO(f.assertAdds({{"testdoc","f1"},{"testdoc","f2"}})); - TEST_DO(f.assertRemoves({})); + EXPECT_EQ((AddVector{{"testdoc","f1"},{"testdoc","f2"}}), get_adds()); + EXPECT_EQ(RemoveVector{}, get_removes()); registrator.reset(); - TEST_DO(f.assertAdds({{"testdoc","f1"},{"testdoc","f2"}})); - TEST_DO(f.assertRemoves({{"testdoc",{"f1","f2"}}})); + EXPECT_EQ((AddVector{{"testdoc","f1"},{"testdoc","f2"}}), get_adds()); + EXPECT_EQ((RemoveVector{{"testdoc",{"f1","f2"}}}), get_removes()); } } -TEST_MAIN() -{ - TEST_RUN_ALL(); -} +GTEST_MAIN_RUN_ALL_TESTS() diff --git a/searchcore/src/vespa/searchcore/proton/test/mock_gid_to_lid_change_handler.cpp b/searchcore/src/vespa/searchcore/proton/test/mock_gid_to_lid_change_handler.cpp index 6bf5b63b50a4..a4466232bd93 100644 --- a/searchcore/src/vespa/searchcore/proton/test/mock_gid_to_lid_change_handler.cpp +++ b/searchcore/src/vespa/searchcore/proton/test/mock_gid_to_lid_change_handler.cpp @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "mock_gid_to_lid_change_handler.h" -#include namespace proton::test { @@ -26,16 +25,4 @@ MockGidToLidChangeHandler::removeListeners(const std::string &docTypeName, const _removes.emplace_back(docTypeName, keepNames); } -void -MockGidToLidChangeHandler::assertAdds(const std::vector &expAdds) const -{ - EXPECT_EQUAL(expAdds, _adds); -} - -void -MockGidToLidChangeHandler::assertRemoves(const std::vector &expRemoves) const -{ - EXPECT_EQUAL(expRemoves, _removes); -} - } diff --git a/searchcore/src/vespa/searchcore/proton/test/mock_gid_to_lid_change_handler.h b/searchcore/src/vespa/searchcore/proton/test/mock_gid_to_lid_change_handler.h index 50b99d841c5e..8c6a11380eca 100644 --- a/searchcore/src/vespa/searchcore/proton/test/mock_gid_to_lid_change_handler.h +++ b/searchcore/src/vespa/searchcore/proton/test/mock_gid_to_lid_change_handler.h @@ -5,8 +5,6 @@ #include #include #include -#include -#include namespace proton::test { @@ -35,9 +33,8 @@ class MockGidToLidChangeHandler : public IGidToLidChangeHandler { void notifyRemoves(IDestructorCallbackSP, const std::vector &, SerialNum) override { } std::unique_ptr grab_pending_changes() override { return {}; } - void assertAdds(const std::vector &expAdds) const; - void assertRemoves(const std::vector &expRemoves) const; - + const std::vector &get_adds() const noexcept { return _adds; } + const std::vector& get_removes() const noexcept { return _removes; } const std::vector> &getListeners() const { return _listeners; } };