aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-10-21 14:37:36 +0200
committerTor Egge <Tor.Egge@online.no>2022-10-21 14:37:36 +0200
commit1c06d4b7fc1eb025befa175406a6af218b30eb04 (patch)
treec1456dd71249049f3fa43b8434f7c2055d8b111b /searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp
parent2df2bbe253cc4a69117240645407a5d76dcd53cf (diff)
Use search::test::SchemaBuilder in searchcore unit tests.
Diffstat (limited to 'searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp')
-rw-r--r--searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp50
1 files changed, 25 insertions, 25 deletions
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 <vespa/searchlib/attribute/interlock.h>
#include <vespa/searchlib/test/directory_handler.h>
#include <vespa/searchlib/test/doc_builder.h>
+#include <vespa/searchlib/test/schema_builder.h>
#include <vespa/searchcommon/attribute/config.h>
#include <vespa/config-bucketspaces.h>
#include <vespa/config/subscription/sourcespec.h>
@@ -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<MyConfigSnapshot> UP;
@@ -307,12 +306,13 @@ template <typename Traits>
struct FixtureBase
{
TransportAndExecutorService _service;
+ static constexpr bool has_attr2 = Traits::has_attr2;
typename Traits::Config _cfg;
std::shared_ptr<bucketdb::BucketDBOwner> _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<bucketdb::BucketDBOwner>()),
_bucketDBHandler(*_bucketDB),
_ctx(_service.write(), _bucketDB, _bucketDBHandler),
- _baseSchema(),
+ _baseSchema(make_all_attr_schema(has_attr2)),
_snapshot(std::make_unique<MyConfigSnapshot>(_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 <typename SchemaT, typename ConfigDirT, uint32_t ConfigSerial = CFG_SERIAL>
+template <bool has_attr2_in, typename ConfigDirT, uint32_t ConfigSerial = CFG_SERIAL>
struct BaseTraitsT
{
- typedef SchemaT Schema;
+ static constexpr bool has_attr2 = has_attr2_in;
typedef ConfigDirT ConfigDir;
static uint32_t configSerial() { return ConfigSerial; }
};
-typedef BaseTraitsT<OneAttrSchema, ConfigDir1> BaseTraits;
+typedef BaseTraitsT<one_attr_schema, ConfigDir1> BaseTraits;
struct StoreOnlyTraits : public BaseTraits
{
@@ -430,7 +430,7 @@ struct FastAccessTraits : public BaseTraits
typedef FixtureBase<FastAccessTraits> FastAccessFixture;
template <typename ConfigDirT>
-struct FastAccessOnlyTraitsBase : public BaseTraitsT<TwoAttrSchema, ConfigDirT>
+struct FastAccessOnlyTraitsBase : public BaseTraitsT<two_attr_schema, ConfigDirT>
{
using Config = MyFastAccessConfig<true>;
using Context = MyFastAccessContext;
@@ -442,8 +442,8 @@ struct FastAccessOnlyTraitsBase : public BaseTraitsT<TwoAttrSchema, ConfigDirT>
typedef FastAccessOnlyTraitsBase<ConfigDir3> FastAccessOnlyTraits;
typedef FixtureBase<FastAccessOnlyTraits> FastAccessOnlyFixture;
-template <typename SchemaT, typename ConfigDirT>
-struct SearchableTraitsBase : public BaseTraitsT<SchemaT, ConfigDirT>
+template <bool has_attr2_in, typename ConfigDirT>
+struct SearchableTraitsBase : public BaseTraitsT<has_attr2_in, ConfigDirT>
{
using Config = MySearchableConfig;
using Context = MySearchableContext;
@@ -451,7 +451,7 @@ struct SearchableTraitsBase : public BaseTraitsT<SchemaT, ConfigDirT>
using FeedView = proton::SearchableFeedView;
};
-typedef SearchableTraitsBase<OneAttrSchema, ConfigDir1> SearchableTraits;
+typedef SearchableTraitsBase<one_attr_schema, ConfigDir1> SearchableTraits;
typedef FixtureBase<SearchableTraits> 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<AttributeGuard> 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<TwoAttrSchema, ConfigDir1> SearchableTraitsTwoField;
+typedef SearchableTraitsBase<two_attr_schema, ConfigDir1> SearchableTraitsTwoField;
typedef FixtureBase<SearchableTraitsTwoField> SearchableFixtureTwoField;
TEST_F("require that regular attributes are populated during reprocessing",