diff options
author | Geir Storli <geirst@yahoo-inc.com> | 2017-03-07 13:50:41 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahoo-inc.com> | 2017-03-07 13:50:41 +0000 |
commit | f6c8ae09fc5959124408fcf1025d66a52c8be84d (patch) | |
tree | 93bcddbe4236a966ed9a1438eafadb435da7a3c3 /searchcore/src/tests/proton | |
parent | 12d429744ccdf13c2ff5aa6d343b7b823d93b33d (diff) |
Rename *referent* -> *reference* to align with naming elsewhere (e.g. config-model).
Diffstat (limited to 'searchcore/src/tests/proton')
11 files changed, 149 insertions, 150 deletions
diff --git a/searchcore/src/tests/proton/common/dummydbowner.h b/searchcore/src/tests/proton/common/dummydbowner.h index a514f0ae9a7..8f44985d619 100644 --- a/searchcore/src/tests/proton/common/dummydbowner.h +++ b/searchcore/src/tests/proton/common/dummydbowner.h @@ -3,7 +3,7 @@ #pragma once #include <vespa/searchcore/proton/server/idocumentdbowner.h> -#include <vespa/searchcore/proton/reference/document_db_referent_registry.h> +#include <vespa/searchcore/proton/reference/document_db_reference_registry.h> #include <vespa/searchcorespi/plugin/iindexmanagerfactory.h> #include <vespa/vespalib/stllike/string.h> @@ -11,10 +11,10 @@ namespace proton { struct DummyDBOwner : IDocumentDBOwner { - std::shared_ptr<IDocumentDBReferentRegistry> _registry; + std::shared_ptr<IDocumentDBReferenceRegistry> _registry; DummyDBOwner() - : _registry(std::make_shared<DocumentDBReferentRegistry>()) + : _registry(std::make_shared<DocumentDBReferenceRegistry>()) { } @@ -25,7 +25,7 @@ struct DummyDBOwner : IDocumentDBOwner { return searchcorespi::IIndexManagerFactory::SP(); } uint32_t getDistributionKey() const override { return -1; } - std::shared_ptr<IDocumentDBReferentRegistry> getDocumentDBReferentRegistry() const override { + std::shared_ptr<IDocumentDBReferenceRegistry> getDocumentDBReferenceRegistry() const override { return _registry; } }; diff --git a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp index 020f7696a7a..473fcba8051 100644 --- a/searchcore/src/tests/proton/documentdb/documentdb_test.cpp +++ b/searchcore/src/tests/proton/documentdb/documentdb_test.cpp @@ -14,8 +14,8 @@ #include <vespa/searchcore/proton/server/memoryconfigstore.h> #include <vespa/searchcore/proton/metrics/job_tracked_flush_target.h> #include <vespa/searchcore/proton/metrics/metricswireservice.h> -#include <vespa/searchcore/proton/reference/document_db_referent_registry.h> -#include <vespa/searchcore/proton/reference/i_document_db_referent.h> +#include <vespa/searchcore/proton/reference/document_db_reference_registry.h> +#include <vespa/searchcore/proton/reference/i_document_db_reference.h> #include <vespa/searchcorespi/index/indexflushtarget.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/searchlib/transactionlog/translogserver.h> @@ -56,13 +56,13 @@ public: struct MyDBOwner : public DummyDBOwner { - std::shared_ptr<DocumentDBReferentRegistry> _registry; + std::shared_ptr<DocumentDBReferenceRegistry> _registry; MyDBOwner() : DummyDBOwner(), - _registry(std::make_shared<DocumentDBReferentRegistry>()) + _registry(std::make_shared<DocumentDBReferenceRegistry>()) { } - std::shared_ptr<IDocumentDBReferentRegistry> getDocumentDBReferentRegistry() const override { + std::shared_ptr<IDocumentDBReferenceRegistry> getDocumentDBReferenceRegistry() const override { return _registry; } }; @@ -234,12 +234,12 @@ TEST_F("require that session manager can be explored", Fixture) EXPECT_TRUE(DocumentDBExplorer(f._db).get_child("session").get() != nullptr); } -TEST_F("require that document db registers referent", Fixture) +TEST_F("require that document db registers reference", Fixture) { auto ®istry = f._myDBOwner._registry; - auto referent = registry->get("typea"); - EXPECT_TRUE(referent.get() != nullptr); - auto attr = referent->getAttribute("attr1"); + auto reference = registry->get("typea"); + EXPECT_TRUE(reference.get() != nullptr); + auto attr = reference->getAttribute("attr1"); EXPECT_TRUE(attr.get() != nullptr); EXPECT_EQUAL(search::attribute::BasicType::INT32, attr->getBasicType()); } diff --git a/searchcore/src/tests/proton/reference/document_db_reference_registry/CMakeLists.txt b/searchcore/src/tests/proton/reference/document_db_reference_registry/CMakeLists.txt new file mode 100644 index 00000000000..1e5df364443 --- /dev/null +++ b/searchcore/src/tests/proton/reference/document_db_reference_registry/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(searchcore_document_db_reference_registry_test_app TEST + SOURCES + document_db_reference_registry_test.cpp + DEPENDS + searchcore_reference + searchcore_documentmetastore + searchcore_bucketdb +) +vespa_add_test(NAME searchcore_document_db_reference_registry_test_app COMMAND searchcore_document_db_reference_registry_test_app) diff --git a/searchcore/src/tests/proton/reference/document_db_reference_registry/DESC b/searchcore/src/tests/proton/reference/document_db_reference_registry/DESC new file mode 100644 index 00000000000..a71a62917f1 --- /dev/null +++ b/searchcore/src/tests/proton/reference/document_db_reference_registry/DESC @@ -0,0 +1 @@ +document_db_reference_registry test. Take a look at document_db_reference_registry_test.cpp for details. diff --git a/searchcore/src/tests/proton/reference/document_db_reference_registry/FILES b/searchcore/src/tests/proton/reference/document_db_reference_registry/FILES new file mode 100644 index 00000000000..3a00650715a --- /dev/null +++ b/searchcore/src/tests/proton/reference/document_db_reference_registry/FILES @@ -0,0 +1 @@ +document_db_reference_registry_test.cpp diff --git a/searchcore/src/tests/proton/reference/document_db_reference_registry/document_db_reference_registry_test.cpp b/searchcore/src/tests/proton/reference/document_db_reference_registry/document_db_reference_registry_test.cpp new file mode 100644 index 00000000000..26a2f38e640 --- /dev/null +++ b/searchcore/src/tests/proton/reference/document_db_reference_registry/document_db_reference_registry_test.cpp @@ -0,0 +1,94 @@ +// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/vespalib/testkit/testapp.h> +#include <vespa/vespalib/stllike/string.h> +#include <vespa/searchcore/proton/reference/document_db_reference_registry.h> +#include <vespa/searchcore/proton/test/mock_document_db_reference.h> +#include <thread> +#include <vespa/log/log.h> +LOG_SETUP("document_db_reference_registry_test"); + +namespace proton +{ + +namespace +{ + + +std::mutex lock; +std::shared_ptr<IDocumentDBReference> getFooResult; + +void getFooTask(const IDocumentDBReferenceRegistry *registry) +{ + auto result = registry->get("foo"); + std::lock_guard<std::mutex> guard(lock); + getFooResult = result; +} + +std::shared_ptr<IDocumentDBReference> checkFooResult() +{ + std::lock_guard<std::mutex> guard(lock); + return getFooResult; +} + +} + +struct Fixture +{ + DocumentDBReferenceRegistry _registry; + + Fixture() + : _registry() + { + } + + test::MockDocumentDBReference::SP + add(vespalib::string name) { + auto reference = std::make_shared<test::MockDocumentDBReference>(); + _registry.add(name, reference); + return reference; + } +}; + +TEST_F("Test that we can instantiate registry with two references", Fixture) +{ + auto referenceFoo = f.add("foo"); + auto referenceBar = f.add("bar"); + EXPECT_NOT_EQUAL(referenceFoo.get(), referenceBar.get()); + auto reference = f._registry.get("foo"); + EXPECT_EQUAL(referenceFoo.get(), reference.get()); + reference = f._registry.get("bar"); + EXPECT_EQUAL(referenceBar.get(), reference.get()); +} + +TEST_F("Test that we block get until related add is completed", Fixture) +{ + const IDocumentDBReferenceRegistry ®istry = f._registry; + std::thread getFooThread(getFooTask, ®istry); + sleep(1); + std::shared_ptr<IDocumentDBReference> nullResult; + EXPECT_EQUAL(nullResult.get(), checkFooResult().get()); + auto referenceFoo = f.add("foo"); + std::shared_ptr<IDocumentDBReference> checkResult; + for (int retry = 0; retry < 60 && !checkResult; ++retry) { + sleep(1); + checkResult = checkFooResult(); + } + EXPECT_EQUAL(referenceFoo.get(), checkResult.get()); + getFooThread.join(); +} + +TEST_F("Test that tryGet method can fail", Fixture) +{ + auto referenceFoo = f.add("foo"); + auto reference = f._registry.tryGet("foo"); + EXPECT_EQUAL(referenceFoo.get(), reference.get()); + reference = f._registry.tryGet("bar"); + EXPECT_TRUE(reference.get() == nullptr); +} + +} + +TEST_MAIN() +{ + TEST_RUN_ALL(); +} diff --git a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp index 187106a9818..15668427c03 100644 --- a/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp +++ b/searchcore/src/tests/proton/reference/document_db_reference_resolver/document_db_reference_resolver_test.cpp @@ -9,10 +9,10 @@ #include <vespa/searchcore/proton/common/monitored_refcount.h> #include <vespa/searchcore/proton/reference/document_db_reference_resolver.h> #include <vespa/searchcore/proton/reference/gid_to_lid_change_listener.h> -#include <vespa/searchcore/proton/reference/i_document_db_referent.h> -#include <vespa/searchcore/proton/reference/i_document_db_referent_registry.h> +#include <vespa/searchcore/proton/reference/i_document_db_reference.h> +#include <vespa/searchcore/proton/reference/i_document_db_reference_registry.h> #include <vespa/searchcore/proton/reference/i_gid_to_lid_change_listener.h> -#include <vespa/searchcore/proton/test/mock_document_db_referent.h> +#include <vespa/searchcore/proton/test/mock_document_db_reference.h> #include <vespa/searchcore/proton/test/mock_gid_to_lid_change_handler.h> #include <vespa/searchlib/attribute/attributefactory.h> #include <vespa/searchlib/attribute/imported_attribute_vector.h> @@ -29,7 +29,7 @@ using namespace document; using namespace proton; using namespace search::attribute; using namespace search; -using proton::test::MockDocumentDBReferent; +using proton::test::MockDocumentDBReference; using search::attribute::test::MockAttributeManager; using vespa::config::search::ImportedFieldsConfig; using vespa::config::search::ImportedFieldsConfigBuilder; @@ -51,15 +51,15 @@ using proton::test::MockGidToLidChangeHandler; using AddEntry = MockGidToLidChangeHandler::AddEntry; using RemoveEntry = MockGidToLidChangeHandler::RemoveEntry; -struct MyDocumentDBReferent : public MockDocumentDBReferent { - using SP = std::shared_ptr<MyDocumentDBReferent>; +struct MyDocumentDBReference : public MockDocumentDBReference { + using SP = std::shared_ptr<MyDocumentDBReference>; using AttributesMap = std::map<vespalib::string, AttributeVector::SP>; MyGidToLidMapperFactory::SP factory; AttributesMap attributes; std::shared_ptr<MockGidToLidChangeHandler> _gidToLidChangeHandler; - MyDocumentDBReferent(MyGidToLidMapperFactory::SP factory_, - std::shared_ptr<MockGidToLidChangeHandler> gidToLidChangeHandler) + MyDocumentDBReference(MyGidToLidMapperFactory::SP factory_, + std::shared_ptr<MockGidToLidChangeHandler> gidToLidChangeHandler) : factory(factory_), _gidToLidChangeHandler(std::move(gidToLidChangeHandler)) { @@ -84,24 +84,24 @@ struct MyDocumentDBReferent : public MockDocumentDBReferent { } }; -struct MyReferentRegistry : public IDocumentDBReferentRegistry { - using ReferentMap = std::map<vespalib::string, IDocumentDBReferent::SP>; - ReferentMap map; - virtual IDocumentDBReferent::SP get(vespalib::stringref name) const override { +struct MyReferenceRegistry : public IDocumentDBReferenceRegistry { + using ReferenceMap = std::map<vespalib::string, IDocumentDBReference::SP>; + ReferenceMap map; + virtual IDocumentDBReference::SP get(vespalib::stringref name) const override { auto itr = map.find(name); ASSERT_TRUE(itr != map.end()); return itr->second; } - virtual IDocumentDBReferent::SP tryGet(vespalib::stringref name) const override { + virtual IDocumentDBReference::SP tryGet(vespalib::stringref name) const override { auto itr = map.find(name); if (itr != map.end()) { return itr->second; } else { - return IDocumentDBReferent::SP(); + return IDocumentDBReference::SP(); } } - virtual void add(vespalib::stringref name, IDocumentDBReferent::SP referent) override { - map[name] = referent; + virtual void add(vespalib::stringref name, IDocumentDBReference::SP reference) override { + map[name] = reference; } virtual void remove(vespalib::stringref) override {} }; @@ -182,9 +182,9 @@ struct Fixture { MonitoredRefCount _gidToLidChangeListenerRefCount; std::shared_ptr<MockGidToLidChangeHandler> _parentGidToLidChangeHandler; std::shared_ptr<MockGidToLidChangeHandler> _parentGidToLidChangeHandler2; - MyDocumentDBReferent::SP parentReferent; - MyDocumentDBReferent::SP parentReferent2; - MyReferentRegistry registry; + MyDocumentDBReference::SP parentReference; + MyDocumentDBReference::SP parentReference2; + MyReferenceRegistry registry; MyAttributeManager attrMgr; MyAttributeManager oldAttrMgr; DocumentModel docModel; @@ -195,8 +195,8 @@ struct Fixture { _gidToLidChangeListenerRefCount(), _parentGidToLidChangeHandler(std::make_shared<MockGidToLidChangeHandler>()), _parentGidToLidChangeHandler2(std::make_shared<MockGidToLidChangeHandler>()), - parentReferent(std::make_shared<MyDocumentDBReferent>(factory, _parentGidToLidChangeHandler)), - parentReferent2(std::make_shared<MyDocumentDBReferent>(factory, _parentGidToLidChangeHandler2)), + parentReference(std::make_shared<MyDocumentDBReference>(factory, _parentGidToLidChangeHandler)), + parentReference2(std::make_shared<MyDocumentDBReference>(factory, _parentGidToLidChangeHandler2)), registry(), attrMgr(), docModel(), @@ -204,14 +204,14 @@ struct Fixture { _attributeFieldWriter(1) { - registry.add("parent", parentReferent); - registry.add("parent2", parentReferent2); + registry.add("parent", parentReference); + registry.add("parent2", parentReference2); populateTargetAttributes(); populateAttributeManagers(); } void populateTargetAttributes() { - parentReferent->addIntAttribute("target_a"); - parentReferent->addIntAttribute("target_b"); + parentReference->addIntAttribute("target_a"); + parentReference->addIntAttribute("target_b"); } void populateAttributeManagers() { attrMgr.addReferenceAttribute("ref"); @@ -238,14 +238,14 @@ struct Fixture { ASSERT_TRUE(attr.get()); EXPECT_EQUAL(name, attr->getName()); EXPECT_EQUAL(attrMgr.getReferenceAttribute(referenceField), attr->getReferenceAttribute().get()); - EXPECT_EQUAL(parentReferent->getAttribute(targetField).get(), attr->getTargetAttribute().get()); + EXPECT_EQUAL(parentReference->getAttribute(targetField).get(), attr->getTargetAttribute().get()); } MockGidToLidChangeHandler &getGidToLidChangeHandler(const vespalib::string &referencedDocTypeName) { - auto ireferent = registry.get(referencedDocTypeName); - auto referent = std::dynamic_pointer_cast<MyDocumentDBReferent>(ireferent); - assert(referent); - return referent->getGidToLidChangeHandler(); + auto ireference = registry.get(referencedDocTypeName); + auto reference = std::dynamic_pointer_cast<MyDocumentDBReference>(ireference); + assert(reference); + return reference->getGidToLidChangeHandler(); } void assertParentAdds(const vespalib::string &referencedDocTypeName, const std::vector<AddEntry> &expAdds) diff --git a/searchcore/src/tests/proton/reference/document_db_referent_registry/CMakeLists.txt b/searchcore/src/tests/proton/reference/document_db_referent_registry/CMakeLists.txt deleted file mode 100644 index d30602ce8e5..00000000000 --- a/searchcore/src/tests/proton/reference/document_db_referent_registry/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -vespa_add_executable(searchcore_document_db_referent_registry_test_app TEST - SOURCES - document_db_referent_registry_test.cpp - DEPENDS - searchcore_reference - searchcore_documentmetastore - searchcore_bucketdb -) -vespa_add_test(NAME searchcore_document_db_referent_registry_test_app COMMAND searchcore_document_db_referent_registry_test_app) diff --git a/searchcore/src/tests/proton/reference/document_db_referent_registry/DESC b/searchcore/src/tests/proton/reference/document_db_referent_registry/DESC deleted file mode 100644 index 03d7d0f167a..00000000000 --- a/searchcore/src/tests/proton/reference/document_db_referent_registry/DESC +++ /dev/null @@ -1 +0,0 @@ -document_db_referent_registry test. Take a look at document_db_referent_registry_test.cpp for details. diff --git a/searchcore/src/tests/proton/reference/document_db_referent_registry/FILES b/searchcore/src/tests/proton/reference/document_db_referent_registry/FILES deleted file mode 100644 index 6ba8e0632f0..00000000000 --- a/searchcore/src/tests/proton/reference/document_db_referent_registry/FILES +++ /dev/null @@ -1 +0,0 @@ -document_db_referent_registry_test.cpp diff --git a/searchcore/src/tests/proton/reference/document_db_referent_registry/document_db_referent_registry_test.cpp b/searchcore/src/tests/proton/reference/document_db_referent_registry/document_db_referent_registry_test.cpp deleted file mode 100644 index 3a23de37a1f..00000000000 --- a/searchcore/src/tests/proton/reference/document_db_referent_registry/document_db_referent_registry_test.cpp +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2017 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/testapp.h> -#include <vespa/vespalib/stllike/string.h> -#include <vespa/searchcore/proton/reference/document_db_referent_registry.h> -#include <vespa/searchcore/proton/test/mock_document_db_referent.h> -#include <thread> -#include <vespa/log/log.h> -LOG_SETUP("document_db_reference_registry_test"); - -namespace proton -{ - -namespace -{ - - -std::mutex lock; -std::shared_ptr<IDocumentDBReferent> getFooResult; - -void getFooTask(const IDocumentDBReferentRegistry *registry) -{ - auto result = registry->get("foo"); - std::lock_guard<std::mutex> guard(lock); - getFooResult = result; -} - -std::shared_ptr<IDocumentDBReferent> checkFooResult() -{ - std::lock_guard<std::mutex> guard(lock); - return getFooResult; -} - -} - -struct Fixture -{ - - DocumentDBReferentRegistry _registry; - - Fixture() - : _registry() - { - } - - test::MockDocumentDBReferent::SP - add(vespalib::string name) { - auto referent = std::make_shared<test::MockDocumentDBReferent>(); - _registry.add(name, referent); - return referent; - } -}; - -TEST_F("Test that we can instantiate registry with two referents", Fixture) -{ - auto referentFoo = f.add("foo"); - auto referentBar = f.add("bar"); - EXPECT_NOT_EQUAL(referentFoo.get(), referentBar.get()); - auto referent = f._registry.get("foo"); - EXPECT_EQUAL(referentFoo.get(), referent.get()); - referent = f._registry.get("bar"); - EXPECT_EQUAL(referentBar.get(), referent.get()); -} - -TEST_F("Test that we block get until related add is completed", Fixture) -{ - const IDocumentDBReferentRegistry ®istry = f._registry; - std::thread getFooThread(getFooTask, ®istry); - sleep(1); - std::shared_ptr<IDocumentDBReferent> nullResult; - EXPECT_EQUAL(nullResult.get(), checkFooResult().get()); - auto referentFoo = f.add("foo"); - std::shared_ptr<IDocumentDBReferent> checkResult; - for (int retry = 0; retry < 60 && !checkResult; ++retry) { - sleep(1); - checkResult = checkFooResult(); - } - EXPECT_EQUAL(referentFoo.get(), checkResult.get()); - getFooThread.join(); -} - -TEST_F("Test that tryGet method can fail", Fixture) -{ - auto referentFoo = f.add("foo"); - auto referent = f._registry.tryGet("foo"); - EXPECT_EQUAL(referentFoo.get(), referent.get()); - referent = f._registry.tryGet("bar"); - EXPECT_TRUE(referent.get() == nullptr); -} - -} - -TEST_MAIN() -{ - TEST_RUN_ALL(); -} |