diff options
author | Tor Egge <Tor.Egge@online.no> | 2022-09-07 15:08:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-07 15:08:55 +0200 |
commit | a9d670dff75d1f1d3b9849ee60e312717ca570fe (patch) | |
tree | ae49c288efb2e70d20783c91c293aad5b7442968 /searchcore/src/tests/proton | |
parent | 9ebb7848b51f05209ab735e05d115c55d08ade1a (diff) |
Revert "Unify access to assets needed during rank-setup."
Diffstat (limited to 'searchcore/src/tests/proton')
7 files changed, 51 insertions, 82 deletions
diff --git a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp index 53ea1b3542f..8bd1168d9af 100644 --- a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp +++ b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp @@ -152,7 +152,7 @@ struct Fixture vespalib::TestClock _clock; matching::QueryLimiter _queryLimiter; EmptyConstantValueFactory _constantValueFactory; - RankingAssetsRepo _constantValueRepo; + ConstantValueRepo _constantValueRepo; vespalib::ThreadStackExecutor _summaryExecutor; std::shared_ptr<PendingLidTrackerBase> _pendingLidsForCommit; ViewSet _views; diff --git a/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp b/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp index c2d3da1b4f6..c3b117f300a 100644 --- a/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp +++ b/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp @@ -7,6 +7,7 @@ #include <vespa/searchcore/proton/test/documentdb_config_builder.h> #include <vespa/vespalib/testkit/testapp.h> #include <vespa/config-summary.h> +#include <vespa/document/config/documenttypes_config_fwd.h> #include <vespa/document/repo/configbuilder.h> #include <vespa/document/repo/documenttyperepo.h> #include <vespa/document/datatype/datatype.h> @@ -71,13 +72,13 @@ public: return *this; } MyConfigBuilder &addRankingExpression() { - _builder.rankingExpressions(make_shared<RankingExpressions>(std::move(RankingExpressions().add("my_expr", "my_file")))); + auto expr_list = RankingExpressions().add("my_expr", "my_file"); + _builder.rankingExpressions(make_shared<RankingExpressions>(expr_list)); return *this; } MyConfigBuilder &addOnnxModel() { - OnnxModels::Vector models; - models.emplace_back("my_model_name", "my_model_file"); - _builder.onnxModels(make_shared<OnnxModels>(std::move(models))); + OnnxModels::Vector models = {{"my_model_name", "my_model_file"}}; + _builder.onnxModels(make_shared<OnnxModels>(models)); return *this; } MyConfigBuilder &addImportedField() { @@ -168,7 +169,7 @@ struct DelayAttributeAspectFixture { Schema::SP schema; ConfigSP attrCfg; ConfigSP noAttrCfg; - explicit DelayAttributeAspectFixture(bool hasDocField) + DelayAttributeAspectFixture(bool hasDocField) : schema(make_shared<Schema>()), attrCfg(), noAttrCfg() diff --git a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp index e1ec5916291..ce66e99d2fc 100644 --- a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp +++ b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp @@ -113,13 +113,11 @@ addConfigsThatAreNotSavedToDisk(const DocumentDBConfig &cfg) RankingConstants::Vector constants = {{"my_name", "my_type", "my_path"}}; builder.rankingConstants(std::make_shared<RankingConstants>(constants)); - auto expr_list = std::make_shared<RankingExpressions>(); - expr_list->add("my_expr", "my_file"); - builder.rankingExpressions(expr_list); + auto expr_list = RankingExpressions().add("my_expr", "my_file"); + builder.rankingExpressions(std::make_shared<RankingExpressions>(expr_list)); - OnnxModels::Vector models; - models.emplace_back("my_model_name", "my_model_file"); - builder.onnxModels(std::make_shared<OnnxModels>(std::move(models))); + OnnxModels::Vector models = {{"my_model_name", "my_model_file"}}; + builder.onnxModels(std::make_shared<OnnxModels>(models)); ImportedFieldsConfigBuilder importedFields; importedFields.attribute.resize(1); diff --git a/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp b/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp index 3c157221e60..4c06feb6ae7 100644 --- a/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp +++ b/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp @@ -2,7 +2,7 @@ #include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/searchcore/proton/matching/ranking_assets_repo.h> +#include <vespa/searchcore/proton/matching/constant_value_repo.h> #include <vespa/eval/eval/value_cache/constant_value.h> using namespace proton::matching; @@ -14,9 +14,9 @@ private: ValueType _type; public: - explicit DoubleConstantValue(double value_) : _value(value_), _type(ValueType::double_type()) {} - const ValueType &type() const override { return _type; } - const Value &value() const override { return _value; } + DoubleConstantValue(double value_) : _value(value_), _type(ValueType::double_type()) {} + virtual const ValueType &type() const override { return _type; } + virtual const Value &value() const override { return _value; } }; class MyConstantValueFactory : public ConstantValueFactory { @@ -30,7 +30,7 @@ public: void add(const vespalib::string &path, const vespalib::string &type, double value) { _map.insert(std::make_pair(std::make_pair(path, type), value)); } - ConstantValue::UP create(const vespalib::string &path, const vespalib::string &type) const override { + virtual ConstantValue::UP create(const vespalib::string &path, const vespalib::string &type) const override { auto itr = _map.find(std::make_pair(path, type)); if (itr != _map.end()) { return std::make_unique<DoubleConstantValue>(itr->second); @@ -41,16 +41,14 @@ public: struct Fixture { MyConstantValueFactory factory; - RankingAssetsRepo repo; + ConstantValueRepo repo; Fixture() : factory(), repo(factory) { factory.add("path_1", "double", 3); factory.add("path_2", "double", 5); - RankingConstants::Vector constants; - constants.emplace_back("foo", "double", "path_1"); - constants.emplace_back("bar", "double", "path_3"); - repo.reconfigure(std::make_shared<RankingConstants>(constants),{}, {}); + repo.reconfigure(RankingConstants({{"foo", "double", "path_1"}, + {"bar", "double", "path_3"}})); } }; @@ -71,10 +69,8 @@ TEST_F("require that non-existing constant value in factory returns bad constant TEST_F("require that reconfigure replaces existing constant values in repo", Fixture) { - RankingConstants::Vector constants; - constants.emplace_back("bar", "double", "path_3"); - constants.emplace_back("baz", "double", "path_2"); - f.repo.reconfigure(std::make_shared<RankingConstants>(constants), {}, {}); + f.repo.reconfigure(RankingConstants({{"bar", "double", "path_3"}, + {"baz", "double", "path_2"}})); f.factory.add("path_3", "double", 7); EXPECT_TRUE(f.repo.getConstant("foo").get() == nullptr); EXPECT_EQUAL(7, f.repo.getConstant("bar")->value().as_double()); diff --git a/searchcore/src/tests/proton/matching/index_environment/index_environment_test.cpp b/searchcore/src/tests/proton/matching/index_environment/index_environment_test.cpp index bd7c3a4e8fd..f6c10f7ddb5 100644 --- a/searchcore/src/tests/proton/matching/index_environment/index_environment_test.cpp +++ b/searchcore/src/tests/proton/matching/index_environment/index_environment_test.cpp @@ -4,7 +4,6 @@ #include <vespa/eval/eval/value_cache/constant_value.h> #include <vespa/searchcore/proton/matching/indexenvironment.h> #include <vespa/searchcore/proton/matching/ranking_expressions.h> -#include <vespa/searchcore/proton/matching/onnx_models.h> using namespace proton::matching; using search::fef::FieldInfo; @@ -34,34 +33,17 @@ RankingExpressions make_expressions() { OnnxModels make_models() { OnnxModels::Vector list; - list.emplace_back(std::move(OnnxModel("model1", "path1").input_feature("input1","feature1").output_name("output1", "out1"))); + list.emplace_back(OnnxModel("model1", "path1").input_feature("input1","feature1").output_name("output1", "out1")); list.emplace_back(OnnxModel("model2", "path2")); - return {std::move(list)}; + return OnnxModels(list); } -struct MyRankingAssetsRepo : public IRankingAssetsRepo { - RankingExpressions _expressions; - OnnxModels _onnxModels; - MyRankingAssetsRepo(RankingExpressions expressions, OnnxModels onnxModels) - : _expressions(std::move(expressions)), - _onnxModels(std::move(onnxModels)) - {} - ~MyRankingAssetsRepo() override; - ConstantValue::UP getConstant(const vespalib::string &) const override { - return {}; - } - - vespalib::string getExpression(const vespalib::string & name) const override { - return _expressions.loadExpression(name); - } - - const OnnxModel *getOnnxModel(const vespalib::string & name) const override { - return _onnxModels.getModel(name); +struct MyConstantValueRepo : public IConstantValueRepo { + virtual ConstantValue::UP getConstant(const vespalib::string &) const override { + return ConstantValue::UP(); } }; -MyRankingAssetsRepo::~MyRankingAssetsRepo() = default; - Schema::UP buildSchema() { @@ -78,19 +60,19 @@ buildEmptySchema() } struct Fixture { - MyRankingAssetsRepo repo; + MyConstantValueRepo repo; Schema::UP schema; IndexEnvironment env; - explicit Fixture(Schema::UP schema_) - : repo(make_expressions(), make_models()), + Fixture(Schema::UP schema_) + : repo(), schema(std::move(schema_)), - env(7, *schema, Properties(), repo) + env(7, *schema, Properties(), repo, make_expressions(), make_models()) { } const FieldInfo *assertField(size_t idx, const vespalib::string &name, DataType dataType, - CollectionType collectionType) const { + CollectionType collectionType) { const FieldInfo *field = env.getField(idx); ASSERT_TRUE(field != nullptr); EXPECT_EQUAL(field, env.getFieldByName(name)); @@ -103,7 +85,7 @@ struct Fixture { void assertHiddenAttributeField(size_t idx, const vespalib::string &name, DataType dataType, - CollectionType collectionType) const { + CollectionType collectionType) { const FieldInfo *field = assertField(idx, name, dataType, collectionType); EXPECT_FALSE(field->hasAttribute()); EXPECT_TRUE(field->type() == FieldType::HIDDEN_ATTRIBUTE); @@ -112,7 +94,7 @@ struct Fixture { void assertAttributeField(size_t idx, const vespalib::string &name, DataType dataType, - CollectionType collectionType) const { + CollectionType collectionType) { const FieldInfo *field = assertField(idx, name, dataType, collectionType); EXPECT_TRUE(field->hasAttribute()); EXPECT_TRUE(field->type() == FieldType::ATTRIBUTE); diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp index b94ef025aa6..dbf4200a24a 100644 --- a/searchcore/src/tests/proton/matching/matching_test.cpp +++ b/searchcore/src/tests/proton/matching/matching_test.cpp @@ -3,7 +3,7 @@ #include <vespa/searchcore/proton/bucketdb/bucket_db_owner.h> #include <vespa/searchcore/proton/documentmetastore/documentmetastore.h> #include <vespa/searchcore/proton/matching/fakesearchcontext.h> -#include <vespa/searchcore/proton/matching/i_ranking_assets_repo.h> +#include <vespa/searchcore/proton/matching/i_constant_value_repo.h> #include <vespa/searchcore/proton/matching/match_context.h> #include <vespa/searchcore/proton/matching/match_params.h> #include <vespa/searchcore/proton/matching/match_tools.h> @@ -107,18 +107,10 @@ vespalib::string make_same_element_stack_dump(const vespalib::string &a1_term, c const uint32_t NUM_DOCS = 1000; -struct EmptyRankingAssetsRepo : public proton::matching::IRankingAssetsRepo { +struct EmptyConstantValueRepo : public proton::matching::IConstantValueRepo { vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &) const override { return {}; } - - vespalib::string getExpression(const vespalib::string &) const override { - return {}; - } - - const OnnxModel *getOnnxModel(const vespalib::string &) const override { - return nullptr; - } }; //----------------------------------------------------------------------------- @@ -133,7 +125,7 @@ struct MyWorld { MatchingStats matchingStats; vespalib::TestClock clock; QueryLimiter queryLimiter; - EmptyRankingAssetsRepo constantValueRepo; + EmptyConstantValueRepo constantValueRepo; MyWorld(); ~MyWorld(); @@ -355,7 +347,7 @@ struct MyWorld { } Matcher::SP createMatcher() { - return std::make_shared<Matcher>(schema, config, clock.clock(), queryLimiter, constantValueRepo, 0); + return std::make_shared<Matcher>(schema, config, clock.clock(), queryLimiter, constantValueRepo, RankingExpressions(), OnnxModels(), 0); } struct MySearchHandler : ISearchHandler { diff --git a/searchcore/src/tests/proton/verify_ranksetup/verify_ranksetup_test.cpp b/searchcore/src/tests/proton/verify_ranksetup/verify_ranksetup_test.cpp index 33a52f70f2b..6f4420695c4 100644 --- a/searchcore/src/tests/proton/verify_ranksetup/verify_ranksetup_test.cpp +++ b/searchcore/src/tests/proton/verify_ranksetup/verify_ranksetup_test.cpp @@ -27,9 +27,9 @@ using vespalib::make_string_short::fmt; struct Writer { FILE *file; - explicit Writer(const std::string &file_name) { + Writer(const std::string &file_name) { file = fopen(file_name.c_str(), "w"); - ASSERT_TRUE(file != nullptr); + ASSERT_TRUE(file != 0); } void fmt(const char *format, ...) const #ifdef __GNUC__ @@ -63,7 +63,7 @@ struct Attribute { ~Attribute(); }; -Attribute::~Attribute() = default; +Attribute::~Attribute() {} struct Setup { std::map<std::string,std::pair<std::string,std::string> > indexes; @@ -75,8 +75,8 @@ struct Setup { std::map<std::string,OnnxModel> onnx_models; Setup(); ~Setup(); - void add_onnx_model(OnnxModel model) { - onnx_models.insert_or_assign(model.name(), std::move(model)); + void add_onnx_model(const OnnxModel &model) { + onnx_models.insert_or_assign(model.name(), model); } void index(const std::string &name, schema::DataType data_type, schema::CollectionType collection_type) @@ -141,7 +141,7 @@ struct Setup { } void write_indexschema(const Writer &out) { out.fmt("indexfield[%zu]\n", indexes.size()); - auto pos = indexes.begin(); + std::map<std::string,std::pair<std::string,std::string> >::const_iterator pos = indexes.begin(); for (size_t i = 0; pos != indexes.end(); ++pos, ++i) { out.fmt("indexfield[%zu].name \"%s\"\n", i, pos->first.c_str()); out.fmt("indexfield[%zu].datatype %s\n", i, pos->second.first.c_str()); @@ -151,7 +151,7 @@ struct Setup { void write_rank_profiles(const Writer &out) { out.fmt("rankprofile[%zu]\n", extra_profiles.size() + 1); out.fmt("rankprofile[0].name \"default\"\n"); - auto pos = properties.begin(); + std::map<std::string,std::string>::const_iterator pos = properties.begin(); for (size_t i = 0; pos != properties.end(); ++pos, ++i) { out.fmt("rankprofile[0].fef.property[%zu]\n", properties.size()); out.fmt("rankprofile[0].fef.property[%zu].name \"%s\"\n", i, pos->first.c_str()); @@ -258,7 +258,7 @@ Setup::Setup() { verify_dir(); } -Setup::~Setup() = default; +Setup::~Setup() {} //----------------------------------------------------------------------------- @@ -279,15 +279,15 @@ struct SimpleSetup : Setup { struct OnnxSetup : Setup { OnnxSetup() : Setup() { add_onnx_model(OnnxModel("simple", TEST_PATH("../../../../../eval/src/tests/tensor/onnx_wrapper/simple.onnx"))); - add_onnx_model(std::move(OnnxModel("mapped", TEST_PATH("../../../../../eval/src/tests/tensor/onnx_wrapper/simple.onnx")) + add_onnx_model(OnnxModel("mapped", TEST_PATH("../../../../../eval/src/tests/tensor/onnx_wrapper/simple.onnx")) .input_feature("query_tensor", "rankingExpression(qt)") .input_feature("attribute_tensor", "rankingExpression(at)") .input_feature("bias_tensor", "rankingExpression(bt)") - .output_name("output", "result"))); - add_onnx_model(std::move(OnnxModel("fragile", TEST_PATH("../../../../../searchlib/src/tests/features/onnx_feature/fragile.onnx")) - .dry_run_on_setup(true))); - add_onnx_model(std::move(OnnxModel("unfragile", TEST_PATH("../../../../../searchlib/src/tests/features/onnx_feature/fragile.onnx")) - .dry_run_on_setup(false))); + .output_name("output", "result")); + add_onnx_model(OnnxModel("fragile", TEST_PATH("../../../../../searchlib/src/tests/features/onnx_feature/fragile.onnx")) + .dry_run_on_setup(true)); + add_onnx_model(OnnxModel("unfragile", TEST_PATH("../../../../../searchlib/src/tests/features/onnx_feature/fragile.onnx")) + .dry_run_on_setup(false)); } }; |