diff options
author | Tor Brede Vekterli <vekterli@oath.com> | 2018-01-17 16:23:46 +0000 |
---|---|---|
committer | Geir Storli <geirst@oath.com> | 2018-01-29 15:32:14 +0000 |
commit | 47915939389db207457b6ec4b78dadf9670ca674 (patch) | |
tree | db00033c31d78b48cee70f9b8583497e322bd77e /documentapi/src/tests | |
parent | 81c8bb2209eaec683ac2f538bb6a768bde9b1dc6 (diff) |
Add visitor bucket space encoding to C++
Also remove MultiOperation support, since it has already been removed
from the Java DocumentProtocol.
Diffstat (limited to 'documentapi/src/tests')
-rw-r--r-- | documentapi/src/tests/messages/CMakeLists.txt | 12 | ||||
-rw-r--r-- | documentapi/src/tests/messages/messages50test.cpp | 56 | ||||
-rw-r--r-- | documentapi/src/tests/messages/messages50test.h | 2 | ||||
-rw-r--r-- | documentapi/src/tests/messages/messages52test.cpp | 2 | ||||
-rw-r--r-- | documentapi/src/tests/messages/messages52test.h | 2 | ||||
-rw-r--r-- | documentapi/src/tests/messages/messages60app.cpp | 5 | ||||
-rw-r--r-- | documentapi/src/tests/messages/messages60test.cpp | 54 | ||||
-rw-r--r-- | documentapi/src/tests/messages/messages60test.h | 13 |
8 files changed, 86 insertions, 60 deletions
diff --git a/documentapi/src/tests/messages/CMakeLists.txt b/documentapi/src/tests/messages/CMakeLists.txt index c34320bd78d..b762eaca657 100644 --- a/documentapi/src/tests/messages/CMakeLists.txt +++ b/documentapi/src/tests/messages/CMakeLists.txt @@ -29,6 +29,18 @@ vespa_add_executable(documentapi_messages52_test_app TEST documentapi ) vespa_add_test(NAME documentapi_messages52_test_app COMMAND documentapi_messages52_test_app) +vespa_add_executable(documentapi_messages60_test_app TEST + SOURCES + testbase.cpp + messages50test.cpp + messages51test.cpp + messages52test.cpp + messages60test.cpp + messages60app.cpp + DEPENDS + documentapi +) +vespa_add_test(NAME documentapi_messages60_test_app COMMAND documentapi_messages60_test_app) vespa_add_executable(documentapi_error_codes_test_app_app TEST SOURCES error_codes_test.cpp diff --git a/documentapi/src/tests/messages/messages50test.cpp b/documentapi/src/tests/messages/messages50test.cpp index b50f30c1f91..db82bdce54d 100644 --- a/documentapi/src/tests/messages/messages50test.cpp +++ b/documentapi/src/tests/messages/messages50test.cpp @@ -31,7 +31,6 @@ Messages50Test::Messages50Test() putTest(DocumentProtocol::MESSAGE_GETBUCKETSTATE, TEST_METHOD(Messages50Test::testGetBucketStateMessage)); putTest(DocumentProtocol::MESSAGE_GETDOCUMENT, TEST_METHOD(Messages50Test::testGetDocumentMessage)); putTest(DocumentProtocol::MESSAGE_MAPVISITOR, TEST_METHOD(Messages50Test::testMapVisitorMessage)); - putTest(DocumentProtocol::MESSAGE_MULTIOPERATION, TEST_METHOD(Messages50Test::testMultiOperationMessage)); putTest(DocumentProtocol::MESSAGE_PUTDOCUMENT, TEST_METHOD(Messages50Test::testPutDocumentMessage)); putTest(DocumentProtocol::MESSAGE_QUERYRESULT, TEST_METHOD(Messages50Test::testQueryResultMessage)); putTest(DocumentProtocol::MESSAGE_REMOVEDOCUMENT, TEST_METHOD(Messages50Test::testRemoveDocumentMessage)); @@ -51,7 +50,6 @@ Messages50Test::Messages50Test() putTest(DocumentProtocol::REPLY_GETBUCKETSTATE, TEST_METHOD(Messages50Test::testGetBucketStateReply)); putTest(DocumentProtocol::REPLY_GETDOCUMENT, TEST_METHOD(Messages50Test::testGetDocumentReply)); putTest(DocumentProtocol::REPLY_MAPVISITOR, TEST_METHOD(Messages50Test::testMapVisitorReply)); - putTest(DocumentProtocol::REPLY_MULTIOPERATION, TEST_METHOD(Messages50Test::testMultiOperationReply)); putTest(DocumentProtocol::REPLY_PUTDOCUMENT, TEST_METHOD(Messages50Test::testPutDocumentReply)); putTest(DocumentProtocol::REPLY_QUERYRESULT, TEST_METHOD(Messages50Test::testQueryResultReply)); putTest(DocumentProtocol::REPLY_REMOVEDOCUMENT, TEST_METHOD(Messages50Test::testRemoveDocumentReply)); @@ -325,41 +323,6 @@ Messages50Test::testDocumentSummaryMessage() } bool -Messages50Test::testMultiOperationMessage() -{ - document::Document::SP doc = - createDoc(getTypeRepo(), "testdoc", "doc:scheme:foo"); - std::vector<char> buffer(1024); - document::BucketIdFactory factory; - - vdslib::WritableDocumentList doclist(getTypeRepoSp(), - &buffer[0], buffer.size()); - ASSERT_TRUE(doclist.addPut(*doc)); - - size_t n = MESSAGE_BASE_LENGTH; - n += sizeof(uint32_t); // routable object type - n += sizeof(uint64_t); // bucket id - n += sizeof(uint32_t); // bytes in docblock - n += sizeof(uint32_t); // num operations - n += sizeof(vdslib::DocumentList::MetaEntry); - n += doc->serialize()->getLength(); - n += 1; // boolean keepTimeStamps - - MultiOperationMessage msg(document::BucketId(16, factory.getBucketId(doc->getId()).getRawId()), doclist); - EXPECT_EQUAL(n, serialize("MultiOperationMessage", msg)); - for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) { - mbus::Routable::UP obj = deserialize("MultiOperationMessage", DocumentProtocol::MESSAGE_MULTIOPERATION, lang); - if (EXPECT_TRUE(obj.get() != NULL)) { - MultiOperationMessage &ref = static_cast<MultiOperationMessage&>(*obj); - EXPECT_EQUAL((uint32_t)1, ref.getOperations().size()); - EXPECT_EQUAL(*doc, *dynamic_cast<document::Document*>(ref.getOperations().begin()->getDocument().get())); - EXPECT_EQUAL(document::BucketId(16, factory.getBucketId(doc->getId()).getRawId()), ref.getBucketId()); - } - } - return true; -} - -bool Messages50Test::testGetDocumentMessage() { GetDocumentMessage tmp(document::DocumentId("doc:scheme:"), 0); @@ -701,25 +664,6 @@ Messages50Test::testSearchResultMessage() return true; } - -bool -Messages50Test::testMultiOperationReply() -{ - WriteDocumentReply reply(DocumentProtocol::REPLY_MULTIOPERATION); - reply.setHighestModificationTimestamp(30); - - EXPECT_EQUAL(13u, serialize("MultiOperationReply", reply)); - - for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) { - mbus::Routable::UP obj = deserialize("MultiOperationReply", DocumentProtocol::REPLY_MULTIOPERATION, lang); - if (EXPECT_TRUE(obj.get() != NULL)) { - WriteDocumentReply &ref = static_cast<WriteDocumentReply&>(*obj); - EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp()); - } - } - return true; -} - bool Messages50Test::testUpdateDocumentMessage() { diff --git a/documentapi/src/tests/messages/messages50test.h b/documentapi/src/tests/messages/messages50test.h index 8711264ee7a..c764f814a45 100644 --- a/documentapi/src/tests/messages/messages50test.h +++ b/documentapi/src/tests/messages/messages50test.h @@ -33,8 +33,6 @@ public: bool testGetDocumentReply(); bool testMapVisitorMessage(); bool testMapVisitorReply(); - bool testMultiOperationMessage(); - bool testMultiOperationReply(); bool testPutDocumentMessage(); bool testPutDocumentReply(); bool testQueryResultMessage(); diff --git a/documentapi/src/tests/messages/messages52test.cpp b/documentapi/src/tests/messages/messages52test.cpp index 33eb5134dce..642fbc2fc41 100644 --- a/documentapi/src/tests/messages/messages52test.cpp +++ b/documentapi/src/tests/messages/messages52test.cpp @@ -21,7 +21,7 @@ createDoc(const DocumentTypeRepo &repo, const string &type_name, const string &i } -static const int MESSAGE_BASE_LENGTH = 5; +static constexpr int MESSAGE_BASE_LENGTH = 5; Messages52Test::Messages52Test() { diff --git a/documentapi/src/tests/messages/messages52test.h b/documentapi/src/tests/messages/messages52test.h index c45f00fb4b4..a663ae15fdc 100644 --- a/documentapi/src/tests/messages/messages52test.h +++ b/documentapi/src/tests/messages/messages52test.h @@ -15,7 +15,7 @@ public: bool testUpdateDocumentMessage(); bool testRemoveDocumentMessage(); -private: +protected: static size_t serializedLength(const string & str) { return sizeof(int32_t) + str.size(); } diff --git a/documentapi/src/tests/messages/messages60app.cpp b/documentapi/src/tests/messages/messages60app.cpp new file mode 100644 index 00000000000..a6c626d5b20 --- /dev/null +++ b/documentapi/src/tests/messages/messages60app.cpp @@ -0,0 +1,5 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "messages60test.h" + +TEST_APPHOOK(Messages60Test); diff --git a/documentapi/src/tests/messages/messages60test.cpp b/documentapi/src/tests/messages/messages60test.cpp new file mode 100644 index 00000000000..d26f1ef319f --- /dev/null +++ b/documentapi/src/tests/messages/messages60test.cpp @@ -0,0 +1,54 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "messages60test.h" +#include <vespa/documentapi/documentapi.h> + +static constexpr int MESSAGE_BASE_LENGTH = 5; + +Messages60Test::Messages60Test() { + // This list MUST mirror the list of routable factories from the DocumentProtocol constructor that support + // version 6.x. When adding tests to this list, please KEEP THEM ORDERED alphabetically like they are now. + putTest(DocumentProtocol::MESSAGE_CREATEVISITOR, TEST_METHOD(Messages60Test::testCreateVisitorMessage)); +} + +// TODO code dupe with parent classes +bool Messages60Test::testCreateVisitorMessage() { + CreateVisitorMessage tmp("SomeLibrary", "myvisitor", "newyork", "london"); + tmp.setDocumentSelection("true and false or true"); + tmp.getParameters().set("myvar", "somevalue"); + tmp.getParameters().set("anothervar", uint64_t(34)); + tmp.getBuckets().push_back(document::BucketId(16, 1234)); + tmp.setVisitRemoves(true); + tmp.setFieldSet("foo bar"); + tmp.setVisitorOrdering(document::OrderingSpecification::DESCENDING); + tmp.setMaxBucketsPerVisitor(2); + tmp.setBucketSpace("bjarne"); + + EXPECT_EQUAL(MESSAGE_BASE_LENGTH + serializedLength("bjarne") + 178, serialize("CreateVisitorMessage", tmp)); + + for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) { + mbus::Routable::UP obj = deserialize("CreateVisitorMessage", DocumentProtocol::MESSAGE_CREATEVISITOR, lang); + if (EXPECT_TRUE(obj)) { + auto& ref = dynamic_cast<CreateVisitorMessage&>(*obj); + + EXPECT_EQUAL(string("SomeLibrary"), ref.getLibraryName()); + EXPECT_EQUAL(string("myvisitor"), ref.getInstanceId()); + EXPECT_EQUAL(string("newyork"), ref.getControlDestination()); + EXPECT_EQUAL(string("london"), ref.getDataDestination()); + EXPECT_EQUAL(string("true and false or true"), ref.getDocumentSelection()); + EXPECT_EQUAL(string("foo bar"), ref.getFieldSet()); + EXPECT_EQUAL(uint32_t(8), ref.getMaximumPendingReplyCount()); + EXPECT_EQUAL(true, ref.visitRemoves()); + EXPECT_EQUAL(false, ref.visitHeadersOnly()); + EXPECT_EQUAL(false, ref.visitInconsistentBuckets()); + EXPECT_EQUAL(size_t(1), ref.getBuckets().size()); + EXPECT_EQUAL(document::BucketId(16, 1234), ref.getBuckets()[0]); + EXPECT_EQUAL(string("somevalue"), ref.getParameters().get("myvar")); + EXPECT_EQUAL(uint64_t(34), ref.getParameters().get("anothervar", uint64_t(1))); + EXPECT_EQUAL(document::OrderingSpecification::DESCENDING, ref.getVisitorOrdering()); + EXPECT_EQUAL(uint32_t(2), ref.getMaxBucketsPerVisitor()); + EXPECT_EQUAL(string("bjarne"), ref.getBucketSpace()); + } + } + return true; +}
\ No newline at end of file diff --git a/documentapi/src/tests/messages/messages60test.h b/documentapi/src/tests/messages/messages60test.h new file mode 100644 index 00000000000..2b61c118f18 --- /dev/null +++ b/documentapi/src/tests/messages/messages60test.h @@ -0,0 +1,13 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include "messages52test.h" + +class Messages60Test : public Messages52Test { +protected: + // TODO finalize version + const vespalib::Version getVersion() const override { return vespalib::Version(6, 999, 0); } +public: + Messages60Test(); + bool testCreateVisitorMessage(); +}; |