aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-02 09:38:54 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-01-02 09:38:54 +0000
commit34191ac5578bb8d1fb487382a831d6901644db8d (patch)
treee7fccf53d4b411b9db51b0994bbaf9c1a42e4793
parent882f1e57e3b48d53be0806f94bcb013be26cd576 (diff)
Specify fast search explicit in test
-rw-r--r--searchlib/src/tests/attribute/imported_attribute_vector/CMakeLists.txt1
-rw-r--r--searchlib/src/tests/attribute/imported_search_context/CMakeLists.txt1
-rw-r--r--searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp28
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h3
-rw-r--r--searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_factory.h9
-rw-r--r--searchlib/src/vespa/searchlib/test/CMakeLists.txt1
-rw-r--r--searchlib/src/vespa/searchlib/test/imported_attribute_fixture.cpp115
-rw-r--r--searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h110
-rw-r--r--searchlib/src/vespa/searchlib/test/mock_gid_to_lid_mapping.h8
9 files changed, 156 insertions, 120 deletions
diff --git a/searchlib/src/tests/attribute/imported_attribute_vector/CMakeLists.txt b/searchlib/src/tests/attribute/imported_attribute_vector/CMakeLists.txt
index 2d29050aec1..3421bc34ca5 100644
--- a/searchlib/src/tests/attribute/imported_attribute_vector/CMakeLists.txt
+++ b/searchlib/src/tests/attribute/imported_attribute_vector/CMakeLists.txt
@@ -4,5 +4,6 @@ vespa_add_executable(searchlib_imported_attribute_vector_test_app TEST
imported_attribute_vector_test.cpp
DEPENDS
searchlib
+ searchlib_test
)
vespa_add_test(NAME searchlib_imported_attribute_vector_test_app COMMAND searchlib_imported_attribute_vector_test_app)
diff --git a/searchlib/src/tests/attribute/imported_search_context/CMakeLists.txt b/searchlib/src/tests/attribute/imported_search_context/CMakeLists.txt
index 9558d09da85..b77671f3c6e 100644
--- a/searchlib/src/tests/attribute/imported_search_context/CMakeLists.txt
+++ b/searchlib/src/tests/attribute/imported_search_context/CMakeLists.txt
@@ -4,5 +4,6 @@ vespa_add_executable(searchlib_imported_search_context_test_app TEST
imported_search_context_test.cpp
DEPENDS
searchlib
+ searchlib_test
)
vespa_add_test(NAME searchlib_imported_search_context_test_app COMMAND searchlib_imported_search_context_test_app)
diff --git a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
index 53ad14f3c28..1bc87ef0da5 100644
--- a/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
+++ b/searchlib/src/tests/attribute/imported_search_context/imported_search_context_test.cpp
@@ -1,7 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/searchcommon/attribute/search_context_params.h>
-#include <vespa/searchlib/attribute/attribute_read_guard.h>
#include <vespa/searchlib/attribute/imported_search_context.h>
#include <vespa/searchlib/fef/termfieldmatchdata.h>
#include <vespa/searchlib/query/query_term_ucs4.h>
@@ -19,31 +18,30 @@ using vespalib::Trinary;
struct Fixture : ImportedAttributeFixture {
- Fixture(bool useSearchCache = false) : ImportedAttributeFixture(useSearchCache) {}
+ Fixture(bool useSearchCache = false, FastSearchConfig fastSearch = FastSearchConfig::Default)
+ : ImportedAttributeFixture(useSearchCache, fastSearch)
+ {}
- std::unique_ptr<ImportedSearchContext> create_context(std::unique_ptr<QueryTermSimple> term) {
+ std::unique_ptr<ImportedSearchContext>
+ create_context(std::unique_ptr<QueryTermSimple> term) {
return std::make_unique<ImportedSearchContext>(std::move(term), SearchContextParams(), *imported_attr, *target_attr);
}
- std::unique_ptr<SearchIterator> create_iterator(
- ImportedSearchContext& ctx,
- TermFieldMatchData& match,
- bool strict) {
+ std::unique_ptr<SearchIterator>
+ create_iterator(ImportedSearchContext& ctx,TermFieldMatchData& match,bool strict) {
auto iter = ctx.createIterator(&match, strict);
assert(iter.get() != nullptr);
iter->initRange(DocId(1), reference_attr->getNumDocs());
return iter;
}
- std::unique_ptr<SearchIterator> create_non_strict_iterator(
- ImportedSearchContext& ctx,
- TermFieldMatchData& match) {
+ std::unique_ptr<SearchIterator>
+ create_non_strict_iterator(ImportedSearchContext& ctx, TermFieldMatchData& match) {
return create_iterator(ctx, match, false);
}
- std::unique_ptr<SearchIterator> create_strict_iterator(
- ImportedSearchContext& ctx,
- TermFieldMatchData& match) {
+ std::unique_ptr<SearchIterator>
+ create_strict_iterator(ImportedSearchContext& ctx,TermFieldMatchData& match) {
return create_iterator(ctx, match, true);
}
@@ -218,7 +216,7 @@ TEST_F("Strict iterator is marked as strict", Fixture) {
EXPECT_TRUE(iter->is_strict() == Trinary::True); // No EXPECT_EQUALS printing of Trinary...
}
-TEST_F("Non-strict blueprint with high hit rate is strict", Fixture) {
+TEST_F("Non-strict blueprint with high hit rate is strict", Fixture(false, FastSearchConfig::ExplicitlyEnabled)) {
auto ctx = f.create_context(word_term("5678"));
ctx->fetchPostings(queryeval::ExecuteInfo::create(false, 0.02));
TermFieldMatchData match;
@@ -227,7 +225,7 @@ TEST_F("Non-strict blueprint with high hit rate is strict", Fixture) {
EXPECT_TRUE(iter->is_strict() == Trinary::True);
}
-TEST_F("Non-strict blueprint with low hit rate is non-strict", Fixture) {
+TEST_F("Non-strict blueprint with low hit rate is non-strict", Fixture(false, FastSearchConfig::ExplicitlyEnabled)) {
auto ctx = f.create_context(word_term("5678"));
ctx->fetchPostings(queryeval::ExecuteInfo::create(false, 0.01));
TermFieldMatchData match;
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
index 33afaaf7f1e..395f20ea403 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector.h
@@ -4,7 +4,6 @@
#include "readable_attribute_vector.h"
#include <vespa/vespalib/stllike/string.h>
-#include <memory>
namespace search { struct IDocumentMetaStoreContext; }
@@ -39,7 +38,7 @@ public:
std::shared_ptr<ReadableAttributeVector> target_attribute,
std::shared_ptr<const IDocumentMetaStoreContext> target_document_meta_store,
std::shared_ptr<BitVectorSearchCache> search_cache);
- virtual ~ImportedAttributeVector();
+ ~ImportedAttributeVector() override;
const std::shared_ptr<ReferenceAttribute>& getReferenceAttribute() const noexcept {
return _reference_attribute;
diff --git a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_factory.h b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_factory.h
index 994d2b22ab9..5401a54f84f 100644
--- a/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_factory.h
+++ b/searchlib/src/vespa/searchlib/attribute/imported_attribute_vector_factory.h
@@ -5,11 +5,9 @@
#include <vespa/vespalib/stllike/string.h>
#include <memory>
-namespace search {
+namespace search { struct IDocumentMetaStoreContext; }
-struct IDocumentMetaStoreContext;
-
-namespace attribute {
+namespace search::attribute {
class BitVectorSearchCache;
class ImportedAttributeVector;
@@ -39,5 +37,4 @@ public:
std::shared_ptr<BitVectorSearchCache> search_cache);
};
-} // attribute
-} // search
+}
diff --git a/searchlib/src/vespa/searchlib/test/CMakeLists.txt b/searchlib/src/vespa/searchlib/test/CMakeLists.txt
index 1231a99920e..41084148c87 100644
--- a/searchlib/src/vespa/searchlib/test/CMakeLists.txt
+++ b/searchlib/src/vespa/searchlib/test/CMakeLists.txt
@@ -2,6 +2,7 @@
vespa_add_library(searchlib_test
SOURCES
document_weight_attribute_helper.cpp
+ imported_attribute_fixture.cpp
initrange.cpp
make_attribute_map_lookup_node.cpp
mock_attribute_context.cpp
diff --git a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.cpp b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.cpp
new file mode 100644
index 00000000000..68d2dc5472b
--- /dev/null
+++ b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.cpp
@@ -0,0 +1,115 @@
+// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "imported_attribute_fixture.h"
+#include "mock_gid_to_lid_mapping.h"
+#include <vespa/vespalib/util/stringfmt.h>
+#include <future>
+
+namespace search {
+
+namespace {
+ struct MockReadGuard : public IDocumentMetaStoreContext::IReadGuard {
+ virtual const search::IDocumentMetaStore &get() const override {
+ search::IDocumentMetaStore *nullStore = nullptr;
+ return static_cast<search::IDocumentMetaStore &>(*nullStore);
+ }
+ };
+}
+
+IDocumentMetaStoreContext::IReadGuard::UP
+MockDocumentMetaStoreContext::getReadGuard() const {
+ ++get_read_guard_cnt;
+ return std::make_unique<MockReadGuard>();
+}
+
+}
+
+namespace search::attribute {
+
+using document::DocumentId;
+using document::GlobalId;
+using DocId = IAttributeVector::DocId;
+using WeightedInt = IAttributeVector::WeightedInt;
+using WeightedFloat = IAttributeVector::WeightedFloat;
+using WeightedString = IAttributeVector::WeightedString;
+using WeightedConstChar = IAttributeVector::WeightedConstChar;
+using WeightedEnum = IAttributeVector::WeightedEnum;
+using test::MockGidToLidMapperFactory;
+
+std::shared_ptr<ReferenceAttribute> create_reference_attribute(vespalib::stringref name = "ref") {
+ return std::make_shared<ReferenceAttribute>(name, Config(BasicType::REFERENCE));
+}
+
+std::shared_ptr<MockDocumentMetaStoreContext>
+create_target_document_meta_store() {
+ return std::make_shared<MockDocumentMetaStoreContext>();
+}
+
+std::shared_ptr<MockDocumentMetaStoreContext>
+create_document_meta_store() {
+ return std::make_shared<MockDocumentMetaStoreContext>();
+}
+
+GlobalId dummy_gid(uint32_t doc_index) {
+ return DocumentId(vespalib::make_string("id:foo:bar::%u", doc_index)).getGlobalId();
+}
+
+std::unique_ptr<QueryTermSimple> word_term(vespalib::stringref term) {
+ return std::make_unique<QueryTermSimple>(term, QueryTermSimple::WORD);
+}
+
+
+void
+ImportedAttributeFixture::map_reference(DocId from_lid, GlobalId via_gid, DocId to_lid) {
+ assert(from_lid < reference_attr->getNumDocs());
+ mapper_factory->_map[via_gid] = to_lid;
+ if (to_lid != 0) {
+ reference_attr->notifyReferencedPut(via_gid, to_lid);
+ } else {
+ reference_attr->notifyReferencedRemove(via_gid);
+ }
+ reference_attr->update(from_lid, via_gid);
+ reference_attr->commit();
+}
+
+
+std::shared_ptr<ImportedAttributeVector>
+ImportedAttributeFixture::create_attribute_vector_from_members(vespalib::stringref name) {
+ return ImportedAttributeVectorFactory::create(name, reference_attr, document_meta_store, target_attr, target_document_meta_store, use_search_cache);
+}
+
+
+void
+ImportedAttributeFixture::reset_with_new_target_attr(std::shared_ptr<AttributeVector> new_target) {
+ target_attr = std::move(new_target);
+ imported_attr = create_attribute_vector_from_members();
+}
+
+
+void
+ImportedAttributeFixture::set_up_attribute_vectors_before_adding_mappings() {
+ // Make a sneaky assumption that no tests try to use a lid > 9
+ add_n_docs_with_undefined_values(*reference_attr, 10);
+ target_attr->addReservedDoc();
+ add_n_docs_with_undefined_values(*target_attr, 10);
+}
+
+ImportedAttributeFixture::ImportedAttributeFixture(bool use_search_cache_, FastSearchConfig fastSearch)
+ : use_search_cache(use_search_cache_),
+ target_attr(create_single_attribute<IntegerAttribute>(BasicType::INT32, fastSearch)),
+ target_document_meta_store(create_target_document_meta_store()),
+ reference_attr(create_reference_attribute()),
+ document_meta_store(create_document_meta_store()),
+ imported_attr(create_attribute_vector_from_members()),
+ mapper_factory(std::make_shared<MockGidToLidMapperFactory>())
+{
+ reference_attr->setGidToLidMapperFactory(mapper_factory);
+}
+
+ImportedAttributeFixture::~ImportedAttributeFixture() = default;
+
+bool has_active_enum_guards(AttributeVector &attr) {
+ return std::async(std::launch::async, [&attr] { return attr.hasActiveEnumGuards(); }).get();
+}
+
+}
diff --git a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
index 50d8030b779..be6ff5b556d 100644
--- a/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
+++ b/searchlib/src/vespa/searchlib/test/imported_attribute_fixture.h
@@ -2,10 +2,8 @@
#pragma once
-#include "mock_gid_to_lid_mapping.h"
#include "weighted_type_test_utils.h"
#include <vespa/document/base/documentid.h>
-#include <vespa/document/base/globalid.h>
#include <vespa/searchlib/attribute/attribute_read_guard.h>
#include <vespa/searchlib/attribute/attributefactory.h>
#include <vespa/searchlib/attribute/attributeguard.h>
@@ -13,43 +11,27 @@
#include <vespa/searchlib/attribute/imported_attribute_vector.h>
#include <vespa/searchlib/attribute/imported_attribute_vector_factory.h>
#include <vespa/searchlib/attribute/integerbase.h>
-#include <vespa/searchlib/attribute/not_implemented_attribute.h>
#include <vespa/searchlib/attribute/reference_attribute.h>
#include <vespa/searchlib/attribute/stringbase.h>
#include <vespa/searchlib/common/i_document_meta_store_context.h>
#include <vespa/searchlib/query/query_term_simple.h>
#include <vespa/searchcommon/attribute/attributecontent.h>
-#include <vespa/vespalib/testkit/testapp.h>
-#include <vespa/vespalib/util/stringfmt.h>
-#include <algorithm>
-#include <future>
-#include <map>
-#include <memory>
-#include <vector>
+#include <vespa/vespalib/testkit/test_kit.h>
namespace search {
struct MockDocumentMetaStoreContext : public IDocumentMetaStoreContext {
-
- struct MockReadGuard : public IDocumentMetaStoreContext::IReadGuard {
- virtual const search::IDocumentMetaStore &get() const override {
- search::IDocumentMetaStore *nullStore = nullptr;
- return static_cast<search::IDocumentMetaStore &>(*nullStore);
- }
- };
-
mutable size_t get_read_guard_cnt;
- using SP = std::shared_ptr<MockDocumentMetaStoreContext>;
MockDocumentMetaStoreContext() : get_read_guard_cnt(0) {}
-
- virtual IReadGuard::UP getReadGuard() const override {
- ++get_read_guard_cnt;
- return std::make_unique<MockReadGuard>();
- }
+ IReadGuard::UP getReadGuard() const override;
};
-namespace attribute {
+}
+
+namespace search::attribute {
+
+namespace test { class MockGidToLidMapperFactory; }
using document::DocumentId;
using document::GlobalId;
@@ -59,19 +41,6 @@ using WeightedFloat = IAttributeVector::WeightedFloat;
using WeightedString = IAttributeVector::WeightedString;
using WeightedConstChar = IAttributeVector::WeightedConstChar;
using WeightedEnum = IAttributeVector::WeightedEnum;
-using test::MockGidToLidMapperFactory;
-
-std::shared_ptr<ReferenceAttribute> create_reference_attribute(vespalib::stringref name = "ref") {
- return std::make_shared<ReferenceAttribute>(name, Config(BasicType::REFERENCE));
-}
-
-MockDocumentMetaStoreContext::SP create_target_document_meta_store() {
- return std::make_shared<MockDocumentMetaStoreContext>();
-}
-
-MockDocumentMetaStoreContext::SP create_document_meta_store() {
- return std::make_shared<MockDocumentMetaStoreContext>();
-}
enum class FastSearchConfig {
ExplicitlyEnabled,
@@ -136,13 +105,8 @@ void add_n_docs_with_undefined_values(VectorType &vec, size_t n) {
vec.commit();
}
-GlobalId dummy_gid(uint32_t doc_index) {
- return DocumentId(vespalib::make_string("id:foo:bar::%u", doc_index)).getGlobalId();
-}
-
-std::unique_ptr<QueryTermSimple> word_term(vespalib::stringref term) {
- return std::make_unique<QueryTermSimple>(term, QueryTermSimple::WORD);
-}
+GlobalId dummy_gid(uint32_t doc_index);
+std::unique_ptr<QueryTermSimple> word_term(vespalib::stringref term);
struct ReadGuardWrapper {
std::unique_ptr<AttributeReadGuard> guard;
@@ -154,13 +118,13 @@ struct ReadGuardWrapper {
struct ImportedAttributeFixture {
bool use_search_cache;
std::shared_ptr<AttributeVector> target_attr;
- MockDocumentMetaStoreContext::SP target_document_meta_store;
+ std::shared_ptr<IDocumentMetaStoreContext> target_document_meta_store;
std::shared_ptr<ReferenceAttribute> reference_attr;
- MockDocumentMetaStoreContext::SP document_meta_store;
+ std::shared_ptr<MockDocumentMetaStoreContext> document_meta_store;
std::shared_ptr<ImportedAttributeVector> imported_attr;
- std::shared_ptr<MockGidToLidMapperFactory> mapper_factory;
+ std::shared_ptr<test::MockGidToLidMapperFactory> mapper_factory;
- ImportedAttributeFixture(bool use_search_cache_ = false);
+ ImportedAttributeFixture(bool use_search_cache_ = false, FastSearchConfig fastSearch = FastSearchConfig::Default);
virtual ~ImportedAttributeFixture();
@@ -168,26 +132,14 @@ struct ImportedAttributeFixture {
return ReadGuardWrapper(imported_attr->makeReadGuard(false));
}
- void map_reference(DocId from_lid, GlobalId via_gid, DocId to_lid) {
- assert(from_lid < reference_attr->getNumDocs());
- mapper_factory->_map[via_gid] = to_lid;
- if (to_lid != 0) {
- reference_attr->notifyReferencedPut(via_gid, to_lid);
- } else {
- reference_attr->notifyReferencedRemove(via_gid);
- }
- reference_attr->update(from_lid, via_gid);
- reference_attr->commit();
- }
+ void map_reference(DocId from_lid, GlobalId via_gid, DocId to_lid);
static vespalib::stringref default_imported_attr_name() {
return "imported";
}
std::shared_ptr<ImportedAttributeVector>
- create_attribute_vector_from_members(vespalib::stringref name = default_imported_attr_name()) {
- return ImportedAttributeVectorFactory::create(name, reference_attr, document_meta_store, target_attr, target_document_meta_store, use_search_cache);
- }
+ create_attribute_vector_from_members(vespalib::stringref name = default_imported_attr_name());
template<typename AttrVecType>
std::shared_ptr<AttrVecType> target_attr_as() {
@@ -196,10 +148,7 @@ struct ImportedAttributeFixture {
return ptr;
}
- void reset_with_new_target_attr(std::shared_ptr<AttributeVector> new_target) {
- target_attr = std::move(new_target);
- imported_attr = create_attribute_vector_from_members();
- }
+ void reset_with_new_target_attr(std::shared_ptr<AttributeVector> new_target);
template<typename ValueType>
struct LidToLidMapping {
@@ -218,12 +167,7 @@ struct ImportedAttributeFixture {
_value_in_target_attr(std::move(value_in_target_attr)) {}
};
- void set_up_attribute_vectors_before_adding_mappings() {
- // Make a sneaky assumption that no tests try to use a lid > 9
- add_n_docs_with_undefined_values(*reference_attr, 10);
- target_attr->addReservedDoc();
- add_n_docs_with_undefined_values(*target_attr, 10);
- }
+ void set_up_attribute_vectors_before_adding_mappings();
template<typename AttrVecType, typename MappingsType, typename ValueAssigner>
void set_up_and_map(const MappingsType &mappings, ValueAssigner assigner) {
@@ -286,19 +230,6 @@ struct ImportedAttributeFixture {
}
};
-ImportedAttributeFixture::ImportedAttributeFixture(bool use_search_cache_)
- : use_search_cache(use_search_cache_),
- target_attr(create_single_attribute<IntegerAttribute>(BasicType::INT32, FastSearchConfig::ExplicitlyEnabled)),
- target_document_meta_store(create_target_document_meta_store()),
- reference_attr(create_reference_attribute()),
- document_meta_store(create_document_meta_store()),
- imported_attr(create_attribute_vector_from_members()),
- mapper_factory(std::make_shared<MockGidToLidMapperFactory>()) {
- reference_attr->setGidToLidMapperFactory(mapper_factory);
-}
-
-ImportedAttributeFixture::~ImportedAttributeFixture() = default;
-
template<typename AttrValueType, typename PredicateType>
void assert_multi_value_matches(const ImportedAttributeFixture &f,
DocId lid,
@@ -352,9 +283,6 @@ void reset_with_wset_value_reference_mappings(
f.reset_with_wset_value_reference_mappings<AttrVecType, WeightedValueType>(type, mappings, fast_search);
}
-bool has_active_enum_guards(AttributeVector &attr) {
- return std::async(std::launch::async, [&attr] { return attr.hasActiveEnumGuards(); }).get();
-}
+bool has_active_enum_guards(AttributeVector &attr);
-} // attribute
-} // search
+}
diff --git a/searchlib/src/vespa/searchlib/test/mock_gid_to_lid_mapping.h b/searchlib/src/vespa/searchlib/test/mock_gid_to_lid_mapping.h
index df7fff18bca..3f6a136b5dc 100644
--- a/searchlib/src/vespa/searchlib/test/mock_gid_to_lid_mapping.h
+++ b/searchlib/src/vespa/searchlib/test/mock_gid_to_lid_mapping.h
@@ -7,9 +7,7 @@
#include <map>
#include <memory>
-namespace search {
-namespace attribute {
-namespace test {
+namespace search::attribute::test {
using MockGidToLidMap = std::map<document::GlobalId, uint32_t>;
@@ -38,6 +36,4 @@ struct MockGidToLidMapperFactory : public search::IGidToLidMapperFactory {
}
};
-} // test
-} // attribute
-} // search
+}