From 5d7aaba3b0e0d0060b5ddce7ee41949936ba4209 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 22 Aug 2018 13:33:27 +0200 Subject: Test non-updateable attributes. --- .../proton/matching/attribute_operation_test.cpp | 45 +++++++++++++++++----- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'searchcore') diff --git a/searchcore/src/tests/proton/matching/attribute_operation_test.cpp b/searchcore/src/tests/proton/matching/attribute_operation_test.cpp index 8aafc518487..f9334e31dbf 100644 --- a/searchcore/src/tests/proton/matching/attribute_operation_test.cpp +++ b/searchcore/src/tests/proton/matching/attribute_operation_test.cpp @@ -44,9 +44,10 @@ TEST("test illegal operations on float attribute") { } AttributeVector::SP -createAttribute(BasicType basicType, const vespalib::string &fieldName) +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); @@ -57,13 +58,15 @@ createAttribute(BasicType basicType, const vespalib::string &fieldName) } template -void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { +void verify(BasicType type, vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { + (void) expected; auto & attrT = dynamic_cast(attr); for (uint32_t docid(0); docid < attr.getNumDocs(); docid++) { - attrT.set(docid, initial); + attrT.update(docid, initial); } + attr.commit(); std::vector docs = {1,7,9,10,17,19}; - auto op = AttributeOperation::create(attr.getBasicType(), operation, docs); + auto op = AttributeOperation::create(type, operation, docs); EXPECT_TRUE(op); op->operator()(attr); for (uint32_t docid(0); docid < attr.getNumDocs(); docid++) { @@ -76,22 +79,32 @@ void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T } } -template +template void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { + verify(attr.getBasicType(), operation, attr, initial, expected); +} + +template +void verify(BasicType typeClaimed, vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { BasicType::Type type = attr.getBasicType(); if (type == BasicType::INT64) { - verify>>(operation, attr, initial, expected); + verify>(typeClaimed, operation, attr, initial, expected); } else if (type == BasicType::INT32) { - verify>>(operation, attr, initial, expected); + verify>(typeClaimed, operation, attr, initial, expected); } else if (type == BasicType::DOUBLE) { - verify>>(operation, attr, initial, expected); + verify>(typeClaimed, operation, attr, initial, expected); } else if (type == BasicType::FLOAT) { - verify>>(operation, attr, initial, expected); + verify>(typeClaimed, operation, attr, initial, expected); } else { ASSERT_TRUE(false); } } +template +void verify(vespalib::stringref operation, AttributeVector & attr, T initial, T expected) { + verify(attr.getBasicType(), operation, attr, initial, expected); +} + TEST("test all integer operations") { auto attr = createAttribute(BasicType::INT64, "ai"); const std::vector> expectedOperation = { @@ -112,4 +125,18 @@ TEST("test all float operations") { } } +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(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(BasicType::INT64, operation, *attr, 7, 7)); + } +} + TEST_MAIN() { TEST_RUN_ALL(); } -- cgit v1.2.3