summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2018-04-23 15:17:54 +0200
committerGitHub <noreply@github.com>2018-04-23 15:17:54 +0200
commit3cd5365b10b30b0be89ed3a286510e5ffcf8f441 (patch)
treebf7084dc543956d5a52f597bb13b9877b44482d0
parent9c4c0fb0d7b6d37beab393e842833d5ffec2d524 (diff)
parent2a1efb617b960948fc62201ea6ea09c4cfead166 (diff)
Merge pull request #5675 from vespa-engine/geirst/add-unit-tests-for-document-db-reference
Geirst/add unit tests for document db reference
-rw-r--r--searchcore/CMakeLists.txt1
-rw-r--r--searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp65
-rw-r--r--searchcore/src/tests/proton/reference/document_db_reference/CMakeLists.txt9
-rw-r--r--searchcore/src/tests/proton/reference/document_db_reference/FILES1
-rw-r--r--searchcore/src/tests/proton/reference/document_db_reference/document_db_reference_test.cpp72
-rw-r--r--searchcore/src/vespa/searchcore/proton/test/mock_attribute_manager.h81
-rw-r--r--searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp4
-rw-r--r--searchlib/src/vespa/searchlib/test/mock_attribute_manager.h1
8 files changed, 172 insertions, 62 deletions
diff --git a/searchcore/CMakeLists.txt b/searchcore/CMakeLists.txt
index 2944b753dca..36e76b02b0b 100644
--- a/searchcore/CMakeLists.txt
+++ b/searchcore/CMakeLists.txt
@@ -131,6 +131,7 @@ vespa_define_module(
src/tests/proton/reference/gid_to_lid_change_listener
src/tests/proton/reference/gid_to_lid_change_registrator
src/tests/proton/reference/gid_to_lid_mapper
+ src/tests/proton/reference/document_db_reference
src/tests/proton/reference/document_db_reference_registry
src/tests/proton/reference/document_db_reference_resolver
src/tests/proton/reprocessing/attribute_reprocessing_initializer
diff --git a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp
index 9c8e2d63385..c7790f9c507 100644
--- a/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp
+++ b/searchcore/src/tests/proton/documentdb/maintenancecontroller/maintenancecontroller_test.cpp
@@ -4,9 +4,9 @@
#include <vespa/document/test/make_bucket_space.h>
#include <vespa/searchcore/proton/attribute/attribute_usage_filter.h>
#include <vespa/searchcore/proton/attribute/i_attribute_manager.h>
+#include <vespa/searchcore/proton/bucketdb/bucket_create_notifier.h>
#include <vespa/searchcore/proton/common/doctypename.h>
#include <vespa/searchcore/proton/common/feedtoken.h>
-#include <vespa/searchcore/proton/bucketdb/bucket_create_notifier.h>
#include <vespa/searchcore/proton/feedoperation/moveoperation.h>
#include <vespa/searchcore/proton/feedoperation/pruneremoveddocumentsoperation.h>
#include <vespa/searchcore/proton/feedoperation/putoperation.h>
@@ -24,6 +24,7 @@
#include <vespa/searchcore/proton/test/buckethandler.h>
#include <vespa/searchcore/proton/test/clusterstatehandler.h>
#include <vespa/searchcore/proton/test/disk_mem_usage_notifier.h>
+#include <vespa/searchcore/proton/test/mock_attribute_manager.h>
#include <vespa/searchcore/proton/test/test.h>
#include <vespa/searchlib/attribute/attributecontext.h>
#include <vespa/searchlib/attribute/attributeguard.h>
@@ -333,67 +334,7 @@ struct MyLongRunningJob : public BlockableMaintenanceJob
}
};
-
-struct MyAttributeManager : public proton::IAttributeManager
-{
- virtual AttributeGuard::UP getAttribute(const string &) const override {
- abort();
- }
- virtual std::unique_ptr<search::attribute::AttributeReadGuard> getAttributeReadGuard(const string &, bool) const override {
- abort();
- }
- virtual void getAttributeList(std::vector<AttributeGuard> &) const override {
- abort();
- }
- virtual search::attribute::IAttributeContext::UP createContext() const override {
- abort();
- }
- virtual IAttributeManager::SP create(const AttributeCollectionSpec &) const override {
- abort();
- }
- virtual std::vector<searchcorespi::IFlushTarget::SP> getFlushTargets() const override {
- abort();
- }
- virtual search::SerialNum getFlushedSerialNum(const vespalib::string &) const override {
- abort();
- }
- virtual search::SerialNum getOldestFlushedSerialNumber() const override {
- abort();
- }
- virtual search::SerialNum getNewestFlushedSerialNumber() const override {
- abort();
- }
- virtual void getAttributeListAll(std::vector<search::AttributeGuard> &) const override {
- abort();
- }
- virtual void pruneRemovedFields(search::SerialNum) override {
- abort();
- }
- virtual const IAttributeFactory::SP &getFactory() const override {
- abort();
- }
- virtual search::ISequencedTaskExecutor &getAttributeFieldWriter() const override {
- abort();
- }
- virtual search::AttributeVector *getWritableAttribute(const vespalib::string &) const override {
- abort();
- }
- virtual const std::vector<search::AttributeVector *> &getWritableAttributes() const override {
- abort();
- }
- virtual void asyncForEachAttribute(std::shared_ptr<IAttributeFunctor>)
- const override {
- }
- virtual ExclusiveAttributeReadAccessor::UP getExclusiveReadAccessor(const vespalib::string &) const override {
- abort();
- }
- virtual void setImportedAttributes(std::unique_ptr<ImportedAttributesRepo>) override {
- abort();
- }
- virtual const ImportedAttributesRepo *getImportedAttributes() const override {
- abort();
- }
-};
+using MyAttributeManager = test::MockAttributeManager;
struct MockLidSpaceCompactionHandler : public ILidSpaceCompactionHandler
{
diff --git a/searchcore/src/tests/proton/reference/document_db_reference/CMakeLists.txt b/searchcore/src/tests/proton/reference/document_db_reference/CMakeLists.txt
new file mode 100644
index 00000000000..00826843d9e
--- /dev/null
+++ b/searchcore/src/tests/proton/reference/document_db_reference/CMakeLists.txt
@@ -0,0 +1,9 @@
+# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(searchcore_document_db_reference_test_app TEST
+ SOURCES
+ document_db_reference_test.cpp
+ DEPENDS
+ searchcore_reference
+ searchcore_attribute
+)
+vespa_add_test(NAME searchcore_document_db_reference_test_app COMMAND searchcore_document_db_reference_test_app)
diff --git a/searchcore/src/tests/proton/reference/document_db_reference/FILES b/searchcore/src/tests/proton/reference/document_db_reference/FILES
new file mode 100644
index 00000000000..af035b253b8
--- /dev/null
+++ b/searchcore/src/tests/proton/reference/document_db_reference/FILES
@@ -0,0 +1 @@
+document_db_reference_test.cpp
diff --git a/searchcore/src/tests/proton/reference/document_db_reference/document_db_reference_test.cpp b/searchcore/src/tests/proton/reference/document_db_reference/document_db_reference_test.cpp
new file mode 100644
index 00000000000..13a3df2d139
--- /dev/null
+++ b/searchcore/src/tests/proton/reference/document_db_reference/document_db_reference_test.cpp
@@ -0,0 +1,72 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/vespalib/testkit/testapp.h>
+
+#include <vespa/searchcore/proton/attribute/imported_attributes_repo.h>
+#include <vespa/searchcore/proton/reference/document_db_reference.h>
+#include <vespa/searchcore/proton/test/mock_attribute_manager.h>
+#include <vespa/searchlib/attribute/attributefactory.h>
+#include <vespa/searchlib/attribute/imported_attribute_vector.h>
+
+#include <vespa/log/log.h>
+LOG_SETUP("document_db_reference_test");
+
+using namespace proton;
+
+using search::AttributeFactory;
+using search::AttributeVector;
+using search::IDocumentMetaStoreContext;
+using search::attribute::BasicType;
+using search::attribute::ImportedAttributeVector;
+using search::attribute::ReadableAttributeVector;
+using search::attribute::ReferenceAttribute;
+
+ImportedAttributesRepo::UP
+makeImportedAttributesRepo()
+{
+ ImportedAttributesRepo::UP result = std::make_unique<ImportedAttributesRepo>();
+ ImportedAttributeVector::SP attr = std::make_shared<ImportedAttributeVector>("imported",
+ std::shared_ptr<ReferenceAttribute>(),
+ std::shared_ptr<ReadableAttributeVector>(),
+ std::shared_ptr<IDocumentMetaStoreContext>(), false);
+ result->add("imported", std::move(attr));
+ return result;
+}
+
+struct Fixture {
+ std::shared_ptr<test::MockAttributeManager> attrMgr;
+ DocumentDBReference ref;
+ Fixture()
+ : attrMgr(std::make_shared<test::MockAttributeManager>()),
+ ref(attrMgr, std::shared_ptr<DocumentMetaStore>(), std::shared_ptr<IGidToLidChangeHandler>())
+ {
+ attrMgr->addAttribute("regular", AttributeFactory::createAttribute("regular", {BasicType::INT32}));
+ attrMgr->setImportedAttributes(makeImportedAttributesRepo());
+ }
+};
+
+TEST_F("regular attribute vector can be retrieved", Fixture)
+{
+ auto attr = f.ref.getAttribute("regular");
+ EXPECT_TRUE(attr.get());
+ const AttributeVector *attrPtr = dynamic_cast<const AttributeVector *>(attr.get());
+ EXPECT_TRUE(attrPtr != nullptr);
+}
+
+TEST_F("imported attribute vector can be retrieved", Fixture)
+{
+ auto attr = f.ref.getAttribute("imported");
+ EXPECT_TRUE(attr.get());
+ const ImportedAttributeVector *importedPtr = dynamic_cast<const ImportedAttributeVector *>(attr.get());
+ EXPECT_TRUE(importedPtr != nullptr);
+}
+
+TEST_F("nullptr is returned for non-existing attribute vector", Fixture)
+{
+ auto attr = f.ref.getAttribute("non-existing");
+ EXPECT_FALSE(attr.get());
+}
+
+TEST_MAIN()
+{
+ TEST_RUN_ALL();
+}
diff --git a/searchcore/src/vespa/searchcore/proton/test/mock_attribute_manager.h b/searchcore/src/vespa/searchcore/proton/test/mock_attribute_manager.h
new file mode 100644
index 00000000000..9dad0d32b61
--- /dev/null
+++ b/searchcore/src/vespa/searchcore/proton/test/mock_attribute_manager.h
@@ -0,0 +1,81 @@
+// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#pragma once
+
+#include <vespa/searchlib/test/mock_attribute_manager.h>
+#include <vespa/searchcore/proton/attribute/i_attribute_manager.h>
+#include <vespa/searchcore/proton/attribute/imported_attributes_repo.h>
+
+namespace proton::test {
+
+class MockAttributeManager : public IAttributeManager {
+private:
+ search::attribute::test::MockAttributeManager _mock;
+ std::unique_ptr<ImportedAttributesRepo> _importedAttributes;
+
+public:
+ MockAttributeManager()
+ : _mock(),
+ _importedAttributes()
+ {}
+
+ void addAttribute(const vespalib::string &name, const search::AttributeVector::SP &attr) {
+ _mock.addAttribute(name, attr);
+ }
+
+ virtual search::AttributeGuard::UP getAttribute(const vespalib::string &name) const override {
+ return _mock.getAttribute(name);
+ }
+ virtual std::unique_ptr<search::attribute::AttributeReadGuard> getAttributeReadGuard(const vespalib::string &name, bool stableEnumGuard) const override {
+ return _mock.getAttributeReadGuard(name, stableEnumGuard);
+ }
+ virtual void getAttributeList(std::vector<search::AttributeGuard> &list) const override {
+ _mock.getAttributeList(list);
+ }
+ virtual search::attribute::IAttributeContext::UP createContext() const override {
+ return _mock.createContext();
+ }
+ virtual IAttributeManager::SP create(const AttributeCollectionSpec &) const override {
+ return IAttributeManager::SP();
+ }
+ virtual std::vector<searchcorespi::IFlushTarget::SP> getFlushTargets() const override {
+ return std::vector<searchcorespi::IFlushTarget::SP>();
+ }
+ virtual search::SerialNum getFlushedSerialNum(const vespalib::string &) const override {
+ return search::SerialNum();
+ }
+ virtual search::SerialNum getOldestFlushedSerialNumber() const override {
+ return search::SerialNum();
+ }
+ virtual search::SerialNum getNewestFlushedSerialNumber() const override {
+ return search::SerialNum();
+ }
+ virtual void getAttributeListAll(std::vector<search::AttributeGuard> &) const override {
+ }
+ virtual void pruneRemovedFields(search::SerialNum) override {
+ }
+ virtual const IAttributeFactory::SP &getFactory() const override {
+ abort();
+ }
+ virtual search::ISequencedTaskExecutor &getAttributeFieldWriter() const override {
+ abort();
+ }
+ virtual search::AttributeVector *getWritableAttribute(const vespalib::string &) const override {
+ return nullptr;
+ }
+ virtual const std::vector<search::AttributeVector *> &getWritableAttributes() const override {
+ abort();
+ }
+ virtual void asyncForEachAttribute(std::shared_ptr<IAttributeFunctor>) const override {
+ }
+ virtual ExclusiveAttributeReadAccessor::UP getExclusiveReadAccessor(const vespalib::string &) const override {
+ return ExclusiveAttributeReadAccessor::UP();
+ }
+ virtual void setImportedAttributes(std::unique_ptr<ImportedAttributesRepo> importedAttributes) override {
+ _importedAttributes = std::move(importedAttributes);
+ }
+ virtual const ImportedAttributesRepo *getImportedAttributes() const override {
+ return _importedAttributes.get();
+ }
+};
+
+}
diff --git a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
index b7b6eac94ed..1e24a784fd9 100644
--- a/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
+++ b/searchlib/src/tests/attribute/imported_attribute_vector/imported_attribute_vector_test.cpp
@@ -145,6 +145,10 @@ TEST_F("asTensorAttribute() returns nullptr", Fixture) {
EXPECT_TRUE(f.get_imported_attr()->asTensorAttribute() == nullptr);
}
+TEST_F("isImported() returns true", Fixture) {
+ EXPECT_TRUE(f.get_imported_attr()->isImported());
+}
+
TEST_F("Multi-valued integer attribute values can be retrieved via reference", Fixture) {
const std::vector<int64_t> doc3_values({1234});
const std::vector<int64_t> doc7_values({5678, 9876, 555, 777});
diff --git a/searchlib/src/vespa/searchlib/test/mock_attribute_manager.h b/searchlib/src/vespa/searchlib/test/mock_attribute_manager.h
index fa12089b3cf..1e7f546d864 100644
--- a/searchlib/src/vespa/searchlib/test/mock_attribute_manager.h
+++ b/searchlib/src/vespa/searchlib/test/mock_attribute_manager.h
@@ -6,6 +6,7 @@
#include <vespa/searchlib/attribute/attributevector.h>
#include <vespa/searchlib/attribute/attribute_read_guard.h>
#include <vespa/searchlib/attribute/iattributemanager.h>
+#include <map>
namespace search {
namespace attribute {