diff options
author | Geir Storli <geirst@yahoo-inc.com> | 2017-02-22 13:10:12 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahoo-inc.com> | 2017-02-22 13:10:12 +0000 |
commit | 6b7796691d4aa39032b6244aec4bb01bef9df4fe (patch) | |
tree | b032356c22c91dc29d882ca9ce8ba50dd9040e54 /searchcore/src/tests/proton/attribute/imported_attributes_repo | |
parent | 03333b45e6cc2efcbd0eae85bfc68e5fcc9b74e8 (diff) |
Implement repo for storing imported attribute vector instances.
Diffstat (limited to 'searchcore/src/tests/proton/attribute/imported_attributes_repo')
4 files changed, 81 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/attribute/imported_attributes_repo/CMakeLists.txt b/searchcore/src/tests/proton/attribute/imported_attributes_repo/CMakeLists.txt new file mode 100644 index 00000000000..cac0574a8f7 --- /dev/null +++ b/searchcore/src/tests/proton/attribute/imported_attributes_repo/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(searchcore_imported_attributes_repo_test_app TEST + SOURCES + imported_attributes_repo_test.cpp + DEPENDS + searchcore_attribute +) +vespa_add_test(NAME searchcore_imported_attributes_repo_test_app COMMAND searchcore_imported_attributes_repo_test_app) diff --git a/searchcore/src/tests/proton/attribute/imported_attributes_repo/DESC b/searchcore/src/tests/proton/attribute/imported_attributes_repo/DESC new file mode 100644 index 00000000000..7d312b1df98 --- /dev/null +++ b/searchcore/src/tests/proton/attribute/imported_attributes_repo/DESC @@ -0,0 +1 @@ +imported_attributes_repo test. Take a look at imported_attributes_repo_test.cpp for details. diff --git a/searchcore/src/tests/proton/attribute/imported_attributes_repo/FILES b/searchcore/src/tests/proton/attribute/imported_attributes_repo/FILES new file mode 100644 index 00000000000..0e4f940c76c --- /dev/null +++ b/searchcore/src/tests/proton/attribute/imported_attributes_repo/FILES @@ -0,0 +1 @@ +imported_attributes_repo_test.cpp diff --git a/searchcore/src/tests/proton/attribute/imported_attributes_repo/imported_attributes_repo_test.cpp b/searchcore/src/tests/proton/attribute/imported_attributes_repo/imported_attributes_repo_test.cpp new file mode 100644 index 00000000000..bb0fb5e5ee4 --- /dev/null +++ b/searchcore/src/tests/proton/attribute/imported_attributes_repo/imported_attributes_repo_test.cpp @@ -0,0 +1,71 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +LOG_SETUP("imported_attributes_repo_test"); +#include <vespa/vespalib/testkit/testapp.h> + +#include <vespa/searchcommon/attribute/iattributevector.h> +#include <vespa/searchcore/proton/attribute/imported_attributes_repo.h> +#include <vespa/searchlib/attribute/not_implemented_attribute.h> +#include <vespa/searchcommon/attribute/basictype.h> + +using proton::ImportedAttributesRepo; +using search::attribute::BasicType; +using search::attribute::Config; +using search::attribute::IAttributeVector; +using search::NotImplementedAttribute; + +struct MyAttributeVector : public NotImplementedAttribute { +private: + virtual void onCommit() override {} + virtual void onUpdateStat() override {} + +public: + MyAttributeVector(const vespalib::string &name) + : NotImplementedAttribute(name, Config(BasicType::NONE)) + {} + static IAttributeVector::SP create(const vespalib::string &name) { + return std::make_shared<MyAttributeVector>(name); + } +}; + +struct Fixture { + ImportedAttributesRepo repo; + Fixture() : repo() {} + void add(IAttributeVector::SP attr) { + repo.add(attr->getName(), attr); + } + IAttributeVector::SP get(const vespalib::string &name) const { + return repo.get(name); + } +}; + +TEST_F("require that attributes can be added and retrieved", Fixture) +{ + IAttributeVector::SP fooAttr = MyAttributeVector::create("foo"); + IAttributeVector::SP barAttr = MyAttributeVector::create("bar"); + f.add(fooAttr); + f.add(barAttr); + EXPECT_EQUAL(f.get("foo").get(), fooAttr.get()); + EXPECT_EQUAL(f.get("bar").get(), barAttr.get()); +} + +TEST_F("require that attribute can be replaced", Fixture) +{ + IAttributeVector::SP attr1 = MyAttributeVector::create("foo"); + IAttributeVector::SP attr2 = MyAttributeVector::create("foo"); + f.add(attr1); + f.add(attr2); + EXPECT_EQUAL(f.get("foo").get(), attr2.get()); +} + +TEST_F("require that not-found attribute returns nullptr", Fixture) +{ + IAttributeVector *notFound = nullptr; + EXPECT_EQUAL(f.get("not_found").get(), notFound); +} + +TEST_MAIN() +{ + TEST_RUN_ALL(); +} |