diff options
Diffstat (limited to 'searchcore/src/tests/proton/index')
-rw-r--r-- | searchcore/src/tests/proton/index/indexcollection_test.cpp | 67 |
1 files changed, 56 insertions, 11 deletions
diff --git a/searchcore/src/tests/proton/index/indexcollection_test.cpp b/searchcore/src/tests/proton/index/indexcollection_test.cpp index 3653ea32bae..7a42fe574c2 100644 --- a/searchcore/src/tests/proton/index/indexcollection_test.cpp +++ b/searchcore/src/tests/proton/index/indexcollection_test.cpp @@ -8,13 +8,31 @@ #include <vespa/log/log.h> LOG_SETUP("indexcollection_test"); -using search::queryeval::ISourceSelector; -using search::queryeval::FakeSearchable; -using search::FixedSourceSelector; using namespace proton; using namespace searchcorespi; +using search::FixedSourceSelector; +using search::index::FieldLengthInfo; +using search::queryeval::FakeSearchable; +using search::queryeval::ISourceSelector; using searchcorespi::index::WarmupConfig; +class MockIndexSearchable : public FakeIndexSearchable { +private: + FieldLengthInfo _field_length_info; + +public: + MockIndexSearchable() + : _field_length_info() + {} + MockIndexSearchable(const FieldLengthInfo& field_length_info) + : _field_length_info(field_length_info) + {} + FieldLengthInfo get_field_length_info(const vespalib::string& field_name) const override { + (void) field_name; + return _field_length_info; + } +}; + class IndexCollectionTest : public ::testing::Test, public IWarmupDone { @@ -48,6 +66,14 @@ public: EXPECT_EQ(_source2.get(), &collection->getSearchable(0)); } + IndexCollection::UP make_unique_collection() const { + return std::make_unique<IndexCollection>(_selector); + } + + IndexCollection::SP make_shared_collection() const { + return std::make_shared<IndexCollection>(_selector); + } + IndexCollection::UP create_warmup(const IndexCollection::SP& prev, const IndexCollection::SP& next) { return std::make_unique<WarmupIndexCollection>(WarmupConfig(1.0, false), prev, next, *_warmup, _executor, *this); } @@ -58,8 +84,8 @@ public: IndexCollectionTest() : _selector(new FixedSourceSelector(0, "fs1")), - _source1(new FakeIndexSearchable), - _source2(new FakeIndexSearchable), + _source1(new MockIndexSearchable({3, 5})), + _source2(new MockIndexSearchable({7, 11})), _fusion_source(new FakeIndexSearchable), _executor(1, 128*1024), _warmup(new FakeIndexSearchable) @@ -70,18 +96,18 @@ public: TEST_F(IndexCollectionTest, searchable_can_be_appended_to_normal_collection) { - expect_searchable_can_be_appended(std::make_unique<IndexCollection>(_selector)); + expect_searchable_can_be_appended(make_unique_collection()); } TEST_F(IndexCollectionTest, searchable_can_be_replaced_in_normal_collection) { - expect_searchable_can_be_replaced(std::make_unique<IndexCollection>(_selector)); + expect_searchable_can_be_replaced(make_unique_collection()); } TEST_F(IndexCollectionTest, searchable_can_be_appended_to_warmup_collection) { - auto prev = std::make_shared<IndexCollection>(_selector); - auto next = std::make_shared<IndexCollection>(_selector); + auto prev = make_shared_collection(); + auto next = make_shared_collection(); expect_searchable_can_be_appended(create_warmup(prev, next)); EXPECT_EQ(0u, prev->getSourceCount()); EXPECT_EQ(1u, next->getSourceCount()); @@ -89,8 +115,8 @@ TEST_F(IndexCollectionTest, searchable_can_be_appended_to_warmup_collection) TEST_F(IndexCollectionTest, searchable_can_be_replaced_in_warmup_collection) { - auto prev = std::make_shared<IndexCollection>(_selector); - auto next = std::make_shared<IndexCollection>(_selector); + auto prev = make_shared_collection(); + auto next = make_shared_collection(); expect_searchable_can_be_replaced(create_warmup(prev, next)); EXPECT_EQ(0u, prev->getSourceCount()); EXPECT_EQ(1u, next->getSourceCount()); @@ -115,4 +141,23 @@ TEST_F(IndexCollectionTest, replace_and_renumber_updates_collection_after_fusion EXPECT_EQ(_source2.get(), &new_fsc->getSearchable(1)); } +TEST_F(IndexCollectionTest, returns_field_length_info_for_last_added_searchable) +{ + auto collection = make_unique_collection(); + + collection->append(3, _source1); + collection->append(4, _source2); + + EXPECT_DOUBLE_EQ(7, collection->get_field_length_info("foo").get_average_field_length()); + EXPECT_EQ(11, collection->get_field_length_info("foo").get_num_samples()); +} + +TEST_F(IndexCollectionTest, returns_empty_field_length_info_when_no_searchables_exists) +{ + auto collection = make_unique_collection(); + + EXPECT_DOUBLE_EQ(0, collection->get_field_length_info("foo").get_average_field_length()); + EXPECT_EQ(0, collection->get_field_length_info("foo").get_num_samples()); +} + GTEST_MAIN_RUN_ALL_TESTS() |