summaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-08-22 21:34:35 +0200
committerHenning Baldersheim <balder@oath.com>2018-08-22 21:34:35 +0200
commit79ae3a5f91f368a3bc7ab2f1c4c7c284df6716bb (patch)
tree4bfc0151156c33666829a30cef3779c80895455e /searchcore/src/tests
parentf50549ea6d85de718634ead271ea30e5000b862e (diff)
Move AttributeOperation and AttributeFunctor to searc::attribute
Diffstat (limited to 'searchcore/src/tests')
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp4
-rw-r--r--searchcore/src/tests/proton/matching/CMakeLists.txt7
-rw-r--r--searchcore/src/tests/proton/matching/attribute_operation_test.cpp142
3 files changed, 2 insertions, 151 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp b/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp
index ce09a9a3742..bd539999b5d 100644
--- a/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp
+++ b/searchcore/src/tests/proton/attribute/attribute_manager/attribute_manager_test.cpp
@@ -8,7 +8,6 @@
#include <vespa/searchcore/proton/attribute/attribute_writer.h>
#include <vespa/searchcore/proton/attribute/attributemanager.h>
#include <vespa/searchcore/proton/attribute/exclusive_attribute_read_accessor.h>
-#include <vespa/searchcore/proton/attribute/i_attribute_functor.h>
#include <vespa/searchcore/proton/attribute/imported_attributes_repo.h>
#include <vespa/searchcore/proton/attribute/sequential_attributes_initializer.h>
#include <vespa/searchcore/proton/flushengine/shrink_lid_space_flush_target.h>
@@ -20,6 +19,7 @@
#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/i_attribute_functor.h>
#include <vespa/searchlib/attribute/attributevector.hpp>
#include <vespa/searchlib/attribute/attribute_read_guard.h>
#include <vespa/searchlib/attribute/imported_attribute_vector.h>
@@ -79,7 +79,7 @@ namespace {
const uint64_t createSerialNum = 42u;
-class MyAttributeFunctor : public proton::IAttributeFunctor
+class MyAttributeFunctor : public search::attribute::IAttributeFunctor
{
std::vector<vespalib::string> _names;
diff --git a/searchcore/src/tests/proton/matching/CMakeLists.txt b/searchcore/src/tests/proton/matching/CMakeLists.txt
index 3157610ca72..14f3960c43e 100644
--- a/searchcore/src/tests/proton/matching/CMakeLists.txt
+++ b/searchcore/src/tests/proton/matching/CMakeLists.txt
@@ -60,10 +60,3 @@ vespa_add_executable(searchcore_querynodes_test_app TEST
searchcore_matching
)
vespa_add_test(NAME searchcore_querynodes_test_app COMMAND searchcore_querynodes_test_app)
-vespa_add_executable(searchcore_attribute_operation_test_app TEST
- SOURCES
- attribute_operation_test.cpp
- DEPENDS
- searchcore_matching
-)
-vespa_add_test(NAME searchcore_attribute_operation_test_app COMMAND searchcore_attribute_operation_test_app)
diff --git a/searchcore/src/tests/proton/matching/attribute_operation_test.cpp b/searchcore/src/tests/proton/matching/attribute_operation_test.cpp
deleted file mode 100644
index f9334e31dbf..00000000000
--- a/searchcore/src/tests/proton/matching/attribute_operation_test.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include <vespa/searchcore/proton/matching/attribute_operation.h>
-#include <vespa/searchlib/attribute/attributefactory.h>
-#include <vespa/searchlib/attribute/singlenumericattribute.h>
-#include <vespa/vespalib/testkit/testapp.h>
-
-#include <vespa/log/log.h>
-LOG_SETUP("attribute_operation_test");
-
-using proton::matching::AttributeOperation;
-using search::attribute::BasicType;
-using search::AttributeVector;
-using search::AttributeFactory;
-using search::attribute::CollectionType;
-using search::attribute::Config;
-
-TEST("test legal operations on integer attribute") {
- const std::vector<uint32_t> docs;
- for (auto operation : {"++", "--", "+=7", "+= 7", "-=7", "*=8", "/=6", "%=7", "=3", "=-3"}) {
- EXPECT_TRUE(AttributeOperation::create(BasicType::INT64, operation, docs));
- }
-}
-
-TEST("test illegal operations on integer attribute") {
- const std::vector<uint32_t> docs;
- for (auto operation : {"", "-", "+", "+=7.1", "=a", "*=8.z", "=", "=.7", "/=0", "%=0"}) {
- EXPECT_FALSE(AttributeOperation::create(BasicType::INT64, operation, docs));
- }
-}
-
-TEST("test legal operations on float attribute") {
- const std::vector<uint32_t> docs;
- for (auto operation : {"++", "--", "+=7", "+= 7", "-=7", "*=8", "*=8.7", "*=.7", "/=6", "%=7", "=3", "=-3"}) {
- EXPECT_TRUE(AttributeOperation::create(BasicType::DOUBLE, operation, docs));
- }
-}
-
-TEST("test illegal operations on float attribute") {
- const std::vector<uint32_t> docs;
- for (auto operation : {"", "-", "+", "=a", "*=8.z", "=", "/=0", "%=0"}) {
- EXPECT_FALSE(AttributeOperation::create(BasicType::DOUBLE, operation, docs));
- }
-}
-
-AttributeVector::SP
-createAttribute(BasicType basicType, const vespalib::string &fieldName, bool fastSearch = false)
-{
- Config cfg(basicType, CollectionType::SINGLE);
- cfg.setFastSearch(fastSearch);
- auto av = search::AttributeFactory::createAttribute(fieldName, cfg);
- while (20 >= av->getNumDocs()) {
- AttributeVector::DocId checkDocId(0u);
- ASSERT_TRUE(av->addDoc(checkDocId));
- }
- av->commit();
- return av;
-}
-
-template <typename T, typename A>
-void verify(BasicType type, vespalib::stringref operation, AttributeVector & attr, T initial, T expected) {
- (void) expected;
- auto & attrT = dynamic_cast<A &>(attr);
- for (uint32_t docid(0); docid < attr.getNumDocs(); docid++) {
- attrT.update(docid, initial);
- }
- attr.commit();
- std::vector<uint32_t> docs = {1,7,9,10,17,19};
- auto op = AttributeOperation::create(type, operation, docs);
- EXPECT_TRUE(op);
- op->operator()(attr);
- for (uint32_t docid(0); docid < attr.getNumDocs(); docid++) {
- if (docs.empty() || (docid < docs.front())) {
- EXPECT_EQUAL(initial, attrT.get(docid));
- } else {
- EXPECT_EQUAL(expected, attrT.get(docid));
- docs.erase(docs.begin());
- }
- }
-}
-
-template <typename T, typename A>
-void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T expected) {
- verify<T, A>(attr.getBasicType(), operation, attr, initial, expected);
-}
-
-template <typename T>
-void verify(BasicType typeClaimed, vespalib::stringref operation, AttributeVector & attr, T initial, T expected) {
- BasicType::Type type = attr.getBasicType();
- if (type == BasicType::INT64) {
- verify<int64_t, search::IntegerAttributeTemplate<int64_t>>(typeClaimed, operation, attr, initial, expected);
- } else if (type == BasicType::INT32) {
- verify<int32_t, search::IntegerAttributeTemplate<int32_t>>(typeClaimed, operation, attr, initial, expected);
- } else if (type == BasicType::DOUBLE) {
- verify<double , search::FloatingPointAttributeTemplate<double >>(typeClaimed, operation, attr, initial, expected);
- } else if (type == BasicType::FLOAT) {
- verify<float , search::FloatingPointAttributeTemplate<float >>(typeClaimed, operation, attr, initial, expected);
- } else {
- ASSERT_TRUE(false);
- }
-}
-
-template <typename T>
-void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T expected) {
- verify<T>(attr.getBasicType(), operation, attr, initial, expected);
-}
-
-TEST("test all integer operations") {
- auto attr = createAttribute(BasicType::INT64, "ai");
- const std::vector<std::pair<const char *, int64_t>> expectedOperation = {
- {"++", 8}, {"--", 6}, {"+=7", 14}, {"-=9", -2}, {"*=3", 21}, {"/=3", 2}, {"%=3", 1}
- };
- for (auto operation : expectedOperation) {
- TEST_DO(verify<int64_t>(operation.first, *attr, 7, operation.second));
- }
-}
-
-TEST("test all float operations") {
- auto attr = createAttribute(BasicType::DOUBLE, "af");
- const std::vector<std::pair<const char *, double>> expectedOperation = {
- {"++", 8}, {"--", 6}, {"+=7.3", 14.3}, {"-=0.9", 6.1}, {"*=3.1", 21.7}, {"/=2", 3.5}, {"%=3", 7}
- };
- for (auto operation : expectedOperation) {
- TEST_DO(verify<double>(operation.first, *attr, 7, operation.second));
- }
-}
-
-TEST("test that even slightly mismatching type will fail to update") {
- auto attr = createAttribute(BasicType::INT32, "ai");
- for (auto operation : {"++", "--", "+=7", "-=9", "*=3", "/=3", "%=3"}) {
- TEST_DO(verify<int64_t>(BasicType::INT64, operation, *attr, 7, 7));
- }
-}
-
-TEST("test that fastsearch attributes will fail to update") {
- auto attr = createAttribute(BasicType::INT64, "ai", true);
- for (auto operation : {"++", "--", "+=7", "-=9", "*=3", "/=3", "%=3"}) {
- TEST_DO(verify<int64_t>(BasicType::INT64, operation, *attr, 7, 7));
- }
-}
-
-TEST_MAIN() { TEST_RUN_ALL(); }