diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2024-05-02 19:41:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 19:41:20 +0200 |
commit | 686cbeafbdf24c3d6a0ffcc3dd79425d4eba6833 (patch) | |
tree | 1e43f8860f2d7c88fc95e86f1dbde8e147093c19 /searchcore/src/tests/proton/attribute/attributes_state_explorer | |
parent | c829472b63825939ab32f701f2eb8450f48797c2 (diff) | |
parent | 23207ef234bf26140924dae31a1deefcbcf9d89d (diff) |
Merge pull request #31100 from vespa-engine/toregge/expose-imported-attributes-in-state-explorerv8.339.15
Expose imported attributes in state explorer.
Diffstat (limited to 'searchcore/src/tests/proton/attribute/attributes_state_explorer')
-rw-r--r-- | searchcore/src/tests/proton/attribute/attributes_state_explorer/attributes_state_explorer_test.cpp | 110 |
1 files changed, 88 insertions, 22 deletions
diff --git a/searchcore/src/tests/proton/attribute/attributes_state_explorer/attributes_state_explorer_test.cpp b/searchcore/src/tests/proton/attribute/attributes_state_explorer/attributes_state_explorer_test.cpp index fd202c24887..732a95e7c13 100644 --- a/searchcore/src/tests/proton/attribute/attributes_state_explorer/attributes_state_explorer_test.cpp +++ b/searchcore/src/tests/proton/attribute/attributes_state_explorer/attributes_state_explorer_test.cpp @@ -2,11 +2,19 @@ #include <vespa/searchcore/proton/attribute/attribute_manager_explorer.h> #include <vespa/searchcore/proton/attribute/attributemanager.h> +#include <vespa/searchcore/proton/attribute/imported_attributes_repo.h> +#include <vespa/searchcore/proton/bucketdb/bucket_db_owner.h> +#include <vespa/searchcore/proton/documentmetastore/documentmetastorecontext.h> #include <vespa/searchcore/proton/test/attribute_utils.h> #include <vespa/searchcore/proton/test/attribute_vectors.h> +#include <vespa/searchlib/attribute/attributefactory.h> +#include <vespa/searchlib/attribute/imported_attribute_vector.h> +#include <vespa/searchlib/attribute/imported_attribute_vector_factory.h> #include <vespa/searchlib/attribute/interlock.h> +#include <vespa/searchlib/attribute/reference_attribute.h> #include <vespa/searchlib/index/dummyfileheadercontext.h> #include <vespa/searchlib/test/directory_handler.h> +#include <vespa/searchlib/test/mock_gid_to_lid_mapping.h> #include <vespa/searchcommon/attribute/config.h> #include <vespa/vespalib/data/slime/slime.h> #include <vespa/vespalib/gtest/gtest.h> @@ -21,6 +29,12 @@ using namespace proton; using namespace proton::test; using search::AttributeVector; using search::DictionaryConfig; +using search::attribute::BasicType; +using search::attribute::Config; +using search::attribute::ImportedAttributeVector; +using search::attribute::ImportedAttributeVectorFactory; +using search::attribute::ReferenceAttribute; +using search::attribute::test::MockGidToLidMapperFactory; using vespalib::ForegroundThreadExecutor; using vespalib::ISequencedTaskExecutor; using vespalib::SequencedTaskExecutor; @@ -32,6 +46,10 @@ using vespalib::HwInfo; const vespalib::string TEST_DIR = "test_output"; +const vespalib::string ref_name("ref"); +const vespalib::string target_name("f3"); +const vespalib::string imported_name("my_f3"); + namespace { VESPA_THREAD_STACK_TAG(test_executor) } @@ -43,28 +61,13 @@ struct AttributesStateExplorerTest : public ::testing::Test std::unique_ptr<ISequencedTaskExecutor> _attribute_field_writer; ForegroundThreadExecutor _shared; HwInfo _hwInfo; + std::shared_ptr<const IDocumentMetaStoreContext> _parent_dms; + std::shared_ptr<IDocumentMetaStoreContext> _dms; + std::shared_ptr<AttributeManager> _parent_mgr; AttributeManager::SP _mgr; AttributeManagerExplorer _explorer; - AttributesStateExplorerTest() - : _dirHandler(TEST_DIR), - _fileHeaderContext(), - _attribute_field_writer(SequencedTaskExecutor::create(test_executor, 1)), - _shared(), - _hwInfo(), - _mgr(new AttributeManager(TEST_DIR, "test.subdb", TuneFileAttributes(), - _fileHeaderContext, - std::make_shared<search::attribute::Interlock>(), - *_attribute_field_writer, - _shared, - _hwInfo)), - _explorer(_mgr) - { - addAttribute("regular"); - addExtraAttribute("extra"); - add_fast_search_attribute("btree", DictionaryConfig::Type::BTREE); - add_fast_search_attribute("hybrid", DictionaryConfig::Type::BTREE_AND_HASH); - add_fast_search_attribute("hash", DictionaryConfig::Type::HASH); - } + AttributesStateExplorerTest() noexcept; + ~AttributesStateExplorerTest() override; void addAttribute(const vespalib::string &name) { _mgr->addAttribute({name, AttributeUtils::getInt32Config()}, 1); } @@ -84,16 +87,71 @@ struct AttributesStateExplorerTest : public ::testing::Test _explorer.get_child(name)->get_state(inserter, true); return result; } - + void add_reference_attribute() { + search::attribute::Config cfg(BasicType::REFERENCE); + _mgr->addAttribute({ ref_name, cfg }, 1); + auto& ref_attr = dynamic_cast<ReferenceAttribute&>(**_mgr->getAttribute(ref_name)); + ref_attr.setGidToLidMapperFactory(std::make_shared<MockGidToLidMapperFactory>()); + } + std::shared_ptr<ReferenceAttribute> get_reference_attribute() { + return std::dynamic_pointer_cast<ReferenceAttribute>(_mgr->getAttribute(ref_name)->getSP()); + } + void add_imported_attributes() { + auto repo = std::make_unique<ImportedAttributesRepo>(); + auto attr = ImportedAttributeVectorFactory::create(imported_name, + get_reference_attribute(), + _dms, + _parent_mgr->getAttribute(target_name)->getSP(), + _parent_dms, + false); + repo->add(imported_name, attr); + _mgr->setImportedAttributes(std::move(repo)); + } }; +AttributesStateExplorerTest::AttributesStateExplorerTest() noexcept + : _dirHandler(TEST_DIR), + _fileHeaderContext(), + _attribute_field_writer(SequencedTaskExecutor::create(test_executor, 1)), + _shared(), + _hwInfo(), + _parent_dms(std::make_shared<const DocumentMetaStoreContext>(std::make_shared<bucketdb::BucketDBOwner>())), + _dms(), + _parent_mgr(std::make_shared<AttributeManager> + (TEST_DIR, "test.parent.subdb", TuneFileAttributes(), + _fileHeaderContext, + std::make_shared<search::attribute::Interlock>(), + *_attribute_field_writer, + _shared, + _hwInfo)), + _mgr(new AttributeManager(TEST_DIR, "test.subdb", TuneFileAttributes(), + _fileHeaderContext, + std::make_shared<search::attribute::Interlock>(), + *_attribute_field_writer, + _shared, + _hwInfo)), + _explorer(_mgr) +{ + _parent_mgr->addAttribute({target_name, AttributeUtils::getInt32Config()}, 1); + addAttribute("regular"); + addExtraAttribute("extra"); + add_fast_search_attribute("btree", DictionaryConfig::Type::BTREE); + add_fast_search_attribute("hybrid", DictionaryConfig::Type::BTREE_AND_HASH); + add_fast_search_attribute("hash", DictionaryConfig::Type::HASH); + add_reference_attribute(); + add_imported_attributes(); +} + +AttributesStateExplorerTest::~AttributesStateExplorerTest() = default; + + using StringVector = std::vector<vespalib::string>; TEST_F(AttributesStateExplorerTest, require_that_attributes_are_exposed_as_children_names) { StringVector children = _explorer.get_children_names(); std::sort(children.begin(), children.end()); - EXPECT_EQ(StringVector({"btree", "hash", "hybrid", "regular"}), children); + EXPECT_EQ(StringVector({"btree", "hash", "hybrid", "my_f3", "ref", "regular"}), children); } TEST_F(AttributesStateExplorerTest, require_that_attributes_are_explorable) @@ -125,4 +183,12 @@ TEST_F(AttributesStateExplorerTest, require_that_dictionary_memory_usage_is_repo } } +TEST_F(AttributesStateExplorerTest, require_that_imported_attribute_shows_memory_usage) +{ + vespalib::string cache_memory_usage("cacheMemoryUsage"); + auto slime = explore_attribute(imported_name); + EXPECT_LT(0, slime[cache_memory_usage]["allocated"].asLong()); + EXPECT_LT(0, slime[cache_memory_usage]["used"].asLong()); +} + GTEST_MAIN_RUN_ALL_TESTS() |