From 1c06d4b7fc1eb025befa175406a6af218b30eb04 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Fri, 21 Oct 2022 14:37:36 +0200 Subject: Use search::test::SchemaBuilder in searchcore unit tests. --- .../document_subdbs/document_subdbs_test.cpp | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp') 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 7394ef1214c..12477469e04 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 @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,7 @@ using proton::bucketdb::IBucketDBHandlerInitializer; using vespalib::IDestructorCallback; using search::test::DirectoryHandler; using search::test::DocBuilder; +using search::test::SchemaBuilder; using searchcorespi::IFlushTarget; using searchcorespi::index::IThreadingService; using storage::spi::Timestamp; @@ -248,19 +250,9 @@ MySearchableContext::MySearchableContext(IThreadingService &writeService, {} MySearchableContext::~MySearchableContext() = default; -struct OneAttrSchema : public Schema -{ - OneAttrSchema() { - addAttributeField(Schema::AttributeField("attr1", Schema::DataType::INT32)); - } -}; +static inline constexpr bool one_attr_schema = false; -struct TwoAttrSchema : public OneAttrSchema -{ - TwoAttrSchema() { - addAttributeField(Schema::AttributeField("attr2", Schema::DataType::INT32)); - } -}; +static inline constexpr bool two_attr_schema = true; DocBuilder::AddFieldsType get_add_fields(bool has_attr2) @@ -273,6 +265,13 @@ get_add_fields(bool has_attr2) }; } +Schema +make_all_attr_schema(bool has_attr2) +{ + DocBuilder db(get_add_fields(has_attr2)); + return SchemaBuilder(db).add_all_attributes().build(); +} + struct MyConfigSnapshot { typedef std::unique_ptr UP; @@ -307,12 +306,13 @@ template struct FixtureBase { TransportAndExecutorService _service; + static constexpr bool has_attr2 = Traits::has_attr2; typename Traits::Config _cfg; std::shared_ptr _bucketDB; BucketDBHandler _bucketDBHandler; typename Traits::Context _ctx; - typename Traits::Schema _baseSchema; + Schema _baseSchema; MyConfigSnapshot::UP _snapshot; DirectoryHandler _baseDir; typename Traits::SubDB _subDb; @@ -323,7 +323,7 @@ struct FixtureBase _bucketDB(std::make_shared()), _bucketDBHandler(*_bucketDB), _ctx(_service.write(), _bucketDB, _bucketDBHandler), - _baseSchema(), + _baseSchema(make_all_attr_schema(has_attr2)), _snapshot(std::make_unique(_service.transport(), _baseSchema, Traits::ConfigDir::dir())), _baseDir(BASE_DIR + "/" + SUB_NAME, BASE_DIR), _subDb(_cfg._cfg, _ctx._ctx), @@ -358,7 +358,7 @@ struct FixtureBase runInMasterAndSync([&]() { _subDb.initViews(*_snapshot->_cfg, sessionMgr); }); } void basicReconfig(SerialNum serialNum) { - runInMasterAndSync([&]() { performReconfig(serialNum, TwoAttrSchema(), ConfigDir2::dir()); }); + runInMasterAndSync([&]() { performReconfig(serialNum, make_all_attr_schema(two_attr_schema), ConfigDir2::dir()); }); } void reconfig(SerialNum serialNum, const Schema &reconfigSchema, const vespalib::string &reconfigConfigDir) { runInMasterAndSync([&]() { performReconfig(serialNum, reconfigSchema, reconfigConfigDir); }); @@ -399,15 +399,15 @@ struct FixtureBase } }; -template +template struct BaseTraitsT { - typedef SchemaT Schema; + static constexpr bool has_attr2 = has_attr2_in; typedef ConfigDirT ConfigDir; static uint32_t configSerial() { return ConfigSerial; } }; -typedef BaseTraitsT BaseTraits; +typedef BaseTraitsT BaseTraits; struct StoreOnlyTraits : public BaseTraits { @@ -430,7 +430,7 @@ struct FastAccessTraits : public BaseTraits typedef FixtureBase FastAccessFixture; template -struct FastAccessOnlyTraitsBase : public BaseTraitsT +struct FastAccessOnlyTraitsBase : public BaseTraitsT { using Config = MyFastAccessConfig; using Context = MyFastAccessContext; @@ -442,8 +442,8 @@ struct FastAccessOnlyTraitsBase : public BaseTraitsT typedef FastAccessOnlyTraitsBase FastAccessOnlyTraits; typedef FixtureBase FastAccessOnlyFixture; -template -struct SearchableTraitsBase : public BaseTraitsT +template +struct SearchableTraitsBase : public BaseTraitsT { using Config = MySearchableConfig; using Context = MySearchableContext; @@ -451,7 +451,7 @@ struct SearchableTraitsBase : public BaseTraitsT using FeedView = proton::SearchableFeedView; }; -typedef SearchableTraitsBase SearchableTraits; +typedef SearchableTraitsBase SearchableTraits; typedef FixtureBase SearchableFixture; void @@ -762,7 +762,7 @@ struct DocumentHandler { FixtureType &_f; DocBuilder _builder; - DocumentHandler(FixtureType &f) : _f(f), _builder(get_add_fields(f._baseSchema.getNumAttributeFields() > 1)) {} + DocumentHandler(FixtureType &f) : _f(f), _builder(get_add_fields(f.has_attr2)) {} static constexpr uint32_t BUCKET_USED_BITS = 8; static DocumentId createDocId(uint32_t docId) { @@ -895,7 +895,7 @@ requireThatAttributesArePopulatedDuringReprocessing(FixtureType &f) } // Reconfig to 2 attribute fields - f.reconfig(40u, TwoAttrSchema(), ConfigDirT::dir()); + f.reconfig(40u, make_all_attr_schema(two_attr_schema), ConfigDirT::dir()); { std::vector attrs; @@ -913,7 +913,7 @@ TEST_F("require that fast-access attributes are populated during reprocessing", } // Setup with 2 fields (1 attribute according to config in dir) -typedef SearchableTraitsBase SearchableTraitsTwoField; +typedef SearchableTraitsBase SearchableTraitsTwoField; typedef FixtureBase SearchableFixtureTwoField; TEST_F("require that regular attributes are populated during reprocessing", -- cgit v1.2.3