summaryrefslogtreecommitdiffstats
path: root/searchcore
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
parent2df2bbe253cc4a69117240645407a5d76dcd53cf (diff)
Use search::test::SchemaBuilder in searchcore unit tests.
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_test.cpp1
-rw-r--r--searchcore/src/tests/proton/documentdb/document_subdbs/document_subdbs_test.cpp50
-rw-r--r--searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp23
-rw-r--r--searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp20
-rw-r--r--searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp12
-rw-r--r--searchcore/src/tests/proton/index/fusionrunner_test.cpp19
-rw-r--r--searchcore/src/tests/proton/index/indexmanager_test.cpp12
-rw-r--r--searchcore/src/vespa/searchcore/proton/common/attributefieldvaluenode.cpp1
8 files changed, 59 insertions, 79 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_test.cpp b/searchcore/src/tests/proton/attribute/attribute_test.cpp
index a6e9f8fe7ee..c1f2e9c897d 100644
--- a/searchcore/src/tests/proton/attribute/attribute_test.cpp
+++ b/searchcore/src/tests/proton/attribute/attribute_test.cpp
@@ -121,7 +121,6 @@ unregister(const AVConfig & cfg)
const string test_dir = "test_output";
const AVConfig INT32_SINGLE = unregister(AVConfig(AVBasicType::INT32));
-const AVConfig INT32_ARRAY = unregister(AVConfig(AVBasicType::INT32, AVCollectionType::ARRAY));
void
fillAttribute(const AttributeVector::SP &attr, uint32_t numDocs, int64_t value, uint64_t lastSyncToken)
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",
diff --git a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
index abd3fba65fd..d31ae33dd15 100644
--- a/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
+++ b/searchcore/src/tests/proton/documentdb/feedhandler/feedhandler_test.cpp
@@ -46,6 +46,7 @@
LOG_SETUP("feedhandler_test");
using document::BucketId;
+using document::DataType;
using document::Document;
using document::DocumentId;
using document::DocumentType;
@@ -56,8 +57,6 @@ using document::TensorDataType;
using document::TensorFieldValue;
using vespalib::IDestructorCallback;
using search::SerialNum;
-using search::index::schema::CollectionType;
-using search::index::schema::DataType;
using vespalib::makeLambdaTask;
using search::test::DocBuilder;
using search::transactionlog::TransLogServer;
@@ -276,7 +275,6 @@ MyFeedView::~MyFeedView() = default;
struct SchemaContext {
- Schema::SP schema;
DocBuilder builder;
SchemaContext();
SchemaContext(bool has_i2);
@@ -285,7 +283,6 @@ struct SchemaContext {
return DocTypeName(builder.get_document_type().getName());
}
std::shared_ptr<const document::DocumentTypeRepo> getRepo() const { return builder.get_repo_sp(); }
- void addField(vespalib::stringref fieldName);
};
SchemaContext::SchemaContext()
@@ -294,30 +291,19 @@ SchemaContext::SchemaContext()
}
SchemaContext::SchemaContext(bool has_i2)
- : schema(std::make_shared<Schema>()),
- builder([has_i2](auto& header) {
+ : builder([has_i2](auto& header) {
header.addTensorField("tensor", "tensor(x{},y{})")
.addTensorField("tensor2", "tensor(x{},y{})")
- .addField("i1", document::DataType::T_STRING);
+ .addField("i1", DataType::T_STRING);
if (has_i2) {
- header.addField("i2", document::DataType::T_STRING);
+ header.addField("i2", DataType::T_STRING);
}
})
{
- schema->addAttributeField(Schema::AttributeField("tensor", DataType::TENSOR, CollectionType::SINGLE, "tensor(x{},y{})"));
- schema->addAttributeField(Schema::AttributeField("tensor2", DataType::TENSOR, CollectionType::SINGLE, "tensor(x{},y{})"));
- addField("i1");
}
-
SchemaContext::~SchemaContext() = default;
-void
-SchemaContext::addField(vespalib::stringref fieldName)
-{
- schema->addIndexField(Schema::IndexField(fieldName, DataType::STRING, CollectionType::SINGLE));
-}
-
struct DocumentContext {
Document::SP doc;
BucketId bucketId;
@@ -332,7 +318,6 @@ struct TwoFieldsSchemaContext : public SchemaContext {
TwoFieldsSchemaContext()
: SchemaContext(true)
{
- addField("i2");
}
};
diff --git a/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp b/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp
index 5758e69dea4..b52078e98ec 100644
--- a/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp
+++ b/searchcore/src/tests/proton/documentdb/feedview/feedview_test.cpp
@@ -27,6 +27,7 @@
#include <vespa/searchcore/proton/test/transport_helper.h>
#include <vespa/searchlib/attribute/attributefactory.h>
#include <vespa/searchlib/test/doc_builder.h>
+#include <vespa/searchlib/test/schema_builder.h>
#include <vespa/searchcommon/attribute/config.h>
#include <vespa/vespalib/util/destructor_callbacks.h>
#include <vespa/vespalib/stllike/asciistream.h>
@@ -35,6 +36,7 @@
LOG_SETUP("feedview_test");
using document::BucketId;
+using document::DataType;
using document::Document;
using document::DocumentId;
using document::DocumentUpdate;
@@ -47,9 +49,8 @@ using vespalib::IDestructorCallback;
using vespalib::Gate;
using vespalib::GateCallback;
using search::SearchableStats;
-using search::index::schema::CollectionType;
-using search::index::schema::DataType;
using search::test::DocBuilder;
+using search::test::SchemaBuilder;
using searchcorespi::IndexSearchable;
using storage::spi::BucketChecksum;
using storage::spi::BucketInfo;
@@ -436,26 +437,21 @@ MyTransport::~MyTransport() = default;
struct SchemaContext
{
- Schema::SP _schema;
- DocBuilder _builder;
+ DocBuilder _builder;
+ Schema::SP _schema;
SchemaContext();
~SchemaContext();
std::shared_ptr<const document::DocumentTypeRepo> getRepo() const { return _builder.get_repo_sp(); }
};
SchemaContext::SchemaContext() :
- _schema(std::make_shared<Schema>()),
- _builder([](auto &header) { using document::DataType;
- header.addField("i1", DataType::T_STRING)
+ _builder([](auto &header) { header.addField("i1", DataType::T_STRING)
.addField("a1", DataType::T_STRING)
.addField("a2", DataType::T_PREDICATE)
.addTensorField("a3", "")
- .addField("s1", DataType::T_STRING); })
+ .addField("s1", DataType::T_STRING); }),
+ _schema(std::make_shared<Schema>(SchemaBuilder(_builder).add_indexes({"i1"}).add_attributes({"a1", "a2", "a3"}).build()))
{
- _schema->addIndexField(Schema::IndexField("i1", DataType::STRING, CollectionType::SINGLE));
- _schema->addAttributeField(Schema::AttributeField("a1", DataType::STRING, CollectionType::SINGLE));
- _schema->addAttributeField(Schema::AttributeField("a2", DataType::BOOLEANTREE, CollectionType::SINGLE));
- _schema->addAttributeField(Schema::AttributeField("a3", DataType::TENSOR, CollectionType::SINGLE));
}
SchemaContext::~SchemaContext() = default;
diff --git a/searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp b/searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp
index 3ae7a55aabd..fef4e80a355 100644
--- a/searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp
+++ b/searchcore/src/tests/proton/feed_and_search/feed_and_search.cpp
@@ -15,6 +15,7 @@
#include <vespa/searchlib/index/dummyfileheadercontext.h>
#include <vespa/searchlib/memoryindex/memory_index.h>
#include <vespa/searchlib/test/doc_builder.h>
+#include <vespa/searchlib/test/schema_builder.h>
#include <vespa/searchlib/test/string_field_builder.h>
#include <vespa/searchlib/test/index/mock_field_length_inspector.h>
#include <vespa/searchlib/query/base.h>
@@ -60,6 +61,7 @@ using search::queryeval::FieldSpecList;
using search::queryeval::SearchIterator;
using search::queryeval::Searchable;
using search::test::DocBuilder;
+using search::test::SchemaBuilder;
using search::test::StringFieldBuilder;
using std::ostringstream;
using vespalib::string;
@@ -112,12 +114,6 @@ const string word2 = "bar";
const DocumentIdT doc_id1 = 1;
const DocumentIdT doc_id2 = 2;
-Schema getSchema() {
- Schema schema;
- schema.addIndexField(Schema::IndexField(field_name, search::index::schema::DataType::STRING));
- return schema;
-}
-
Document::UP buildDocument(DocBuilder & doc_builder, int id,
const string &word) {
ostringstream ost;
@@ -164,12 +160,12 @@ VESPA_THREAD_STACK_TAG(write_executor)
// searches, dumps the index to disk, and performs the searches
// again.
void Test::requireThatMemoryIndexCanBeDumpedAndSearched() {
- Schema schema = getSchema();
vespalib::ThreadStackExecutor sharedExecutor(2, 0x10000);
auto indexFieldInverter = vespalib::SequencedTaskExecutor::create(invert_executor, 2);
auto indexFieldWriter = vespalib::SequencedTaskExecutor::create(write_executor, 2);
- MemoryIndex memory_index(schema, MockFieldLengthInspector(), *indexFieldInverter, *indexFieldWriter);
DocBuilder doc_builder([](auto& header) { header.addField(field_name, DataType::T_STRING); });
+ auto schema = SchemaBuilder(doc_builder).add_all_indexes().build();
+ MemoryIndex memory_index(schema, MockFieldLengthInspector(), *indexFieldInverter, *indexFieldWriter);
Document::UP doc = buildDocument(doc_builder, doc_id1, word1);
memory_index.insertDocument(doc_id1, *doc, {});
diff --git a/searchcore/src/tests/proton/index/fusionrunner_test.cpp b/searchcore/src/tests/proton/index/fusionrunner_test.cpp
index 0475d37b32c..5b9f35d74f2 100644
--- a/searchcore/src/tests/proton/index/fusionrunner_test.cpp
+++ b/searchcore/src/tests/proton/index/fusionrunner_test.cpp
@@ -13,6 +13,7 @@
#include <vespa/searchlib/fef/matchdatalayout.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
#include <vespa/searchlib/test/doc_builder.h>
+#include <vespa/searchlib/test/schema_builder.h>
#include <vespa/searchlib/test/string_field_builder.h>
#include <vespa/searchlib/memoryindex/memory_index.h>
#include <vespa/searchlib/query/tree/simplequery.h>
@@ -45,7 +46,6 @@ using search::fef::TermFieldHandle;
using search::fef::TermFieldMatchData;
using search::index::DummyFileHeaderContext;
using search::index::Schema;
-using search::index::schema::DataType;
using search::index::test::MockFieldLengthInspector;
using search::memoryindex::MemoryIndex;
using search::query::SimpleStringTerm;
@@ -56,6 +56,7 @@ using search::queryeval::FieldSpecList;
using search::queryeval::ISourceSelector;
using search::queryeval::SearchIterator;
using search::test::DocBuilder;
+using search::test::SchemaBuilder;
using search::test::StringFieldBuilder;
using searchcorespi::index::FusionRunner;
using searchcorespi::index::FusionSpec;
@@ -133,11 +134,13 @@ const string field_name = "field_name";
const string term = "foo";
const uint32_t disk_id[] = { 1, 2, 21, 42 };
-Schema getSchema() {
- Schema schema;
- schema.addIndexField(
- Schema::IndexField(field_name, DataType::STRING));
- return schema;
+auto add_fields = [](auto& header) { header.addField(field_name, document::DataType::T_STRING); };
+
+Schema
+getSchema()
+{
+ DocBuilder db(add_fields);
+ return SchemaBuilder(db).add_all_indexes().build();
}
void Test::setUp() {
@@ -186,8 +189,8 @@ void Test::createIndex(const string &dir, uint32_t id, bool fusion) {
const string index_dir = ost.str();
_selector->setDefaultSource(id - _selector->getBaseId());
- Schema schema = getSchema();
- DocBuilder doc_builder([](auto& header) { header.addField(field_name, document::DataType::T_STRING); });
+ DocBuilder doc_builder(add_fields);
+ auto schema = SchemaBuilder(doc_builder).add_all_indexes().build();
MemoryIndex memory_index(schema, MockFieldLengthInspector(),
_service.write().indexFieldInverter(),
_service.write().indexFieldWriter());
diff --git a/searchcore/src/tests/proton/index/indexmanager_test.cpp b/searchcore/src/tests/proton/index/indexmanager_test.cpp
index 68f1d4d0d0e..19035eaa7f7 100644
--- a/searchcore/src/tests/proton/index/indexmanager_test.cpp
+++ b/searchcore/src/tests/proton/index/indexmanager_test.cpp
@@ -15,6 +15,7 @@
#include <vespa/searchlib/common/serialnum.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
#include <vespa/searchlib/test/doc_builder.h>
+#include <vespa/searchlib/test/schema_builder.h>
#include <vespa/searchlib/test/string_field_builder.h>
#include <vespa/searchlib/memoryindex/compact_words_store.h>
#include <vespa/searchlib/memoryindex/document_inverter.h>
@@ -51,12 +52,12 @@ using vespalib::datastore::EntryRef;
using search::index::DummyFileHeaderContext;
using search::index::FieldLengthInfo;
using search::index::Schema;
-using search::index::schema::DataType;
using search::index::test::MockFieldLengthInspector;
using search::memoryindex::CompactWordsStore;
using search::memoryindex::FieldIndexCollection;
using search::queryeval::Source;
using search::test::DocBuilder;
+using search::test::SchemaBuilder;
using search::test::StringFieldBuilder;
using std::set;
using std::string;
@@ -85,10 +86,11 @@ const string index_dir = "test_data";
const string field_name = "field";
const uint32_t docid = 1;
+auto add_fields = [](auto& header) { header.addField(field_name, document::DataType::T_STRING); };
+
Schema getSchema() {
- Schema schema;
- schema.addIndexField(Schema::IndexField(field_name, DataType::STRING));
- return schema;
+ DocBuilder db(add_fields);
+ return SchemaBuilder(db).add_all_indexes().build();
}
void removeTestData() {
@@ -126,7 +128,7 @@ struct IndexManagerTest : public ::testing::Test {
_service(1),
_index_manager(),
_schema(getSchema()),
- _builder([](auto& header) { header.addField(field_name, document::DataType::T_STRING); })
+ _builder(add_fields)
{
removeTestData();
std::filesystem::create_directory(std::filesystem::path(index_dir));
diff --git a/searchcore/src/vespa/searchcore/proton/common/attributefieldvaluenode.cpp b/searchcore/src/vespa/searchcore/proton/common/attributefieldvaluenode.cpp
index f568e8ed702..7d9b1b3b06a 100644
--- a/searchcore/src/vespa/searchcore/proton/common/attributefieldvaluenode.cpp
+++ b/searchcore/src/vespa/searchcore/proton/common/attributefieldvaluenode.cpp
@@ -24,7 +24,6 @@ using document::select::Visitor;
using search::AttributeVector;
using search::attribute::AttributeContent;
using search::attribute::BasicType;
-using search::attribute::CollectionType;
using search::attribute::IAttributeVector;
using vespalib::IllegalArgumentException;
using vespalib::IllegalStateException;