summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@oath.com>2018-09-28 13:26:58 +0200
committerGitHub <noreply@github.com>2018-09-28 13:26:58 +0200
commit42afce7d0e0670d734366de49fa370c046644480 (patch)
tree31d8e2eece567c223c0f4c34967954ffbdf40172
parentec2f6f0fd57236fe940926f70f3c164f1c9011bd (diff)
parente71b9e613887b469f08008fe73f5b3a38fc54aa3 (diff)
Merge pull request #7130 from vespa-engine/toregge/merge-documentapi-protocol-test-classes
Merge documentapi protocol test classes (C++).
-rw-r--r--documentapi/src/tests/messages/CMakeLists.txt4
-rw-r--r--documentapi/src/tests/messages/messages50test.cpp1022
-rw-r--r--documentapi/src/tests/messages/messages50test.h52
-rw-r--r--documentapi/src/tests/messages/messages51test.cpp104
-rw-r--r--documentapi/src/tests/messages/messages51test.h18
-rw-r--r--documentapi/src/tests/messages/messages52test.cpp961
-rw-r--r--documentapi/src/tests/messages/messages52test.h51
-rw-r--r--documentapi/src/tests/routablefactory/routablefactory.cpp6
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/CMakeLists.txt4
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories41.cpp61
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories41.h81
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories42.cpp12
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories42.h84
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories50.cpp903
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories50.h445
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories51.cpp46
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories51.h99
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories52.cpp905
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories52.h398
-rw-r--r--documentapi/src/vespa/documentapi/messagebus/routablefactories60.h6
20 files changed, 2267 insertions, 2995 deletions
diff --git a/documentapi/src/tests/messages/CMakeLists.txt b/documentapi/src/tests/messages/CMakeLists.txt
index 19e1901003d..576557968e8 100644
--- a/documentapi/src/tests/messages/CMakeLists.txt
+++ b/documentapi/src/tests/messages/CMakeLists.txt
@@ -2,8 +2,6 @@
vespa_add_executable(documentapi_messages52_test_app TEST
SOURCES
testbase.cpp
- messages50test.cpp
- messages51test.cpp
messages52test.cpp
messages52app.cpp
DEPENDS
@@ -13,8 +11,6 @@ vespa_add_test(NAME documentapi_messages52_test_app COMMAND documentapi_messages
vespa_add_executable(documentapi_messages60_test_app TEST
SOURCES
testbase.cpp
- messages50test.cpp
- messages51test.cpp
messages52test.cpp
messages60test.cpp
messages60app.cpp
diff --git a/documentapi/src/tests/messages/messages50test.cpp b/documentapi/src/tests/messages/messages50test.cpp
deleted file mode 100644
index cee0af5ad8e..00000000000
--- a/documentapi/src/tests/messages/messages50test.cpp
+++ /dev/null
@@ -1,1022 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "messages50test.h"
-#include <vespa/document/bucket/bucketidfactory.h>
-#include <vespa/document/datatype/documenttype.h>
-#include <vespa/document/select/parser.h>
-#include <vespa/document/repo/documenttyperepo.h>
-#include <vespa/document/update/documentupdate.h>
-#include <vespa/document/update/fieldpathupdates.h>
-#include <vespa/documentapi/documentapi.h>
-#include <vespa/document/bucket/fixed_bucket_spaces.h>
-
-using document::DataType;
-using document::DocumentTypeRepo;
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// Setup
-//
-///////////////////////////////////////////////////////////////////////////////
-
-Messages50Test::Messages50Test()
-{
- // This list MUST mirror the list of routable factories from the DocumentProtocol constructor that support
- // version 5.0. When adding tests to this list, please KEEP THEM ORDERED alphabetically like they are now.
- putTest(DocumentProtocol::MESSAGE_CREATEVISITOR, TEST_METHOD(Messages50Test::testCreateVisitorMessage));
- putTest(DocumentProtocol::MESSAGE_DESTROYVISITOR, TEST_METHOD(Messages50Test::testDestroyVisitorMessage));
- putTest(DocumentProtocol::MESSAGE_DOCUMENTLIST, TEST_METHOD(Messages50Test::testDocumentListMessage));
- putTest(DocumentProtocol::MESSAGE_DOCUMENTSUMMARY, TEST_METHOD(Messages50Test::testDocumentSummaryMessage));
- putTest(DocumentProtocol::MESSAGE_EMPTYBUCKETS, TEST_METHOD(Messages50Test::testEmptyBucketsMessage));
- putTest(DocumentProtocol::MESSAGE_GETBUCKETLIST, TEST_METHOD(Messages50Test::testGetBucketListMessage));
- 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_PUTDOCUMENT, TEST_METHOD(Messages50Test::testPutDocumentMessage));
- putTest(DocumentProtocol::MESSAGE_QUERYRESULT, TEST_METHOD(Messages50Test::testQueryResultMessage));
- putTest(DocumentProtocol::MESSAGE_REMOVEDOCUMENT, TEST_METHOD(Messages50Test::testRemoveDocumentMessage));
- putTest(DocumentProtocol::MESSAGE_REMOVELOCATION, TEST_METHOD(Messages50Test::testRemoveLocationMessage));
- putTest(DocumentProtocol::MESSAGE_SEARCHRESULT, TEST_METHOD(Messages50Test::testSearchResultMessage));
- putTest(DocumentProtocol::MESSAGE_STATBUCKET, TEST_METHOD(Messages50Test::testStatBucketMessage));
- putTest(DocumentProtocol::MESSAGE_UPDATEDOCUMENT, TEST_METHOD(Messages50Test::testUpdateDocumentMessage));
- putTest(DocumentProtocol::MESSAGE_VISITORINFO, TEST_METHOD(Messages50Test::testVisitorInfoMessage));
-
- putTest(DocumentProtocol::REPLY_CREATEVISITOR, TEST_METHOD(Messages50Test::testCreateVisitorReply));
- putTest(DocumentProtocol::REPLY_DESTROYVISITOR, TEST_METHOD(Messages50Test::testDestroyVisitorReply));
- putTest(DocumentProtocol::REPLY_DOCUMENTLIST, TEST_METHOD(Messages50Test::testDocumentListReply));
- putTest(DocumentProtocol::REPLY_DOCUMENTSUMMARY, TEST_METHOD(Messages50Test::testDocumentSummaryReply));
- putTest(DocumentProtocol::REPLY_EMPTYBUCKETS, TEST_METHOD(Messages50Test::testEmptyBucketsReply));
- putTest(DocumentProtocol::REPLY_GETBUCKETLIST, TEST_METHOD(Messages50Test::testGetBucketListReply));
- 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_PUTDOCUMENT, TEST_METHOD(Messages50Test::testPutDocumentReply));
- putTest(DocumentProtocol::REPLY_QUERYRESULT, TEST_METHOD(Messages50Test::testQueryResultReply));
- putTest(DocumentProtocol::REPLY_REMOVEDOCUMENT, TEST_METHOD(Messages50Test::testRemoveDocumentReply));
- putTest(DocumentProtocol::REPLY_REMOVELOCATION, TEST_METHOD(Messages50Test::testRemoveLocationReply));
- putTest(DocumentProtocol::REPLY_SEARCHRESULT, TEST_METHOD(Messages50Test::testSearchResultReply));
- putTest(DocumentProtocol::REPLY_STATBUCKET, TEST_METHOD(Messages50Test::testStatBucketReply));
- putTest(DocumentProtocol::REPLY_UPDATEDOCUMENT, TEST_METHOD(Messages50Test::testUpdateDocumentReply));
- putTest(DocumentProtocol::REPLY_VISITORINFO, TEST_METHOD(Messages50Test::testVisitorInfoReply));
- putTest(DocumentProtocol::REPLY_WRONGDISTRIBUTION, TEST_METHOD(Messages50Test::testWrongDistributionReply));
-}
-
-
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// Tests
-//
-///////////////////////////////////////////////////////////////////////////////
-
-static const int MESSAGE_BASE_LENGTH = 5;
-
-namespace {
-
-document::Document::SP
-createDoc(const DocumentTypeRepo &repo, const string &type_name, const string &id)
-{
- return document::Document::SP(new document::Document(
- *repo.getDocumentType(type_name),
- document::DocumentId(id)));
-}
-
-} // namespace
-
-bool
-Messages50Test::testGetBucketListMessage()
-{
- GetBucketListMessage msg(document::BucketId(16, 123));
- msg.setLoadType(_loadTypes["foo"]);
- EXPECT_EQUAL(string("foo"), msg.getLoadType().getName());
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 12u, serialize("GetBucketListMessage", msg));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("GetBucketListMessage", DocumentProtocol::MESSAGE_GETBUCKETLIST, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- GetBucketListMessage &ref = static_cast<GetBucketListMessage&>(*obj);
- EXPECT_EQUAL(string("foo"), ref.getLoadType().getName());
- EXPECT_EQUAL(document::BucketId(16, 123), ref.getBucketId());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testEmptyBucketsMessage()
-{
- std::vector<document::BucketId> bids;
- for (size_t i=0; i < 13; ++i) {
- bids.push_back(document::BucketId(16, i));
- }
-
- EmptyBucketsMessage msg(bids);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 112u, serialize("EmptyBucketsMessage", msg));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("EmptyBucketsMessage", DocumentProtocol::MESSAGE_EMPTYBUCKETS, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- EmptyBucketsMessage &ref = static_cast<EmptyBucketsMessage&>(*obj);
- for (size_t i=0; i < 13; ++i) {
- EXPECT_EQUAL(document::BucketId(16, i), ref.getBucketIds()[i]);
- }
- }
- }
- return true;
-}
-
-
-bool
-Messages50Test::testStatBucketMessage()
-{
- StatBucketMessage msg(document::BucketId(16, 123), "id.user=123");
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 27u, serialize("StatBucketMessage", msg));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("StatBucketMessage", DocumentProtocol::MESSAGE_STATBUCKET, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- StatBucketMessage &ref = static_cast<StatBucketMessage&>(*obj);
- EXPECT_EQUAL(document::BucketId(16, 123), ref.getBucketId());
- EXPECT_EQUAL("id.user=123", ref.getDocumentSelection());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::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.setVisitorOrdering(document::OrderingSpecification::DESCENDING);
- tmp.setMaxBucketsPerVisitor(2);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)168, 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.get() != NULL)) {
- CreateVisitorMessage &ref = static_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(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());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testDestroyVisitorMessage()
-{
- DestroyVisitorMessage tmp("myvisitor");
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)17, serialize("DestroyVisitorMessage", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("DestroyVisitorMessage", DocumentProtocol::MESSAGE_DESTROYVISITOR, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- DestroyVisitorMessage &ref = static_cast<DestroyVisitorMessage&>(*obj);
- EXPECT_EQUAL(string("myvisitor"), ref.getInstanceId());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testDocumentListMessage()
-{
- document::Document::SP doc =
- createDoc(getTypeRepo(), "testdoc", "userdoc:scheme:1234:");
- DocumentListMessage::Entry entry(1234, doc, false);
-
- DocumentListMessage tmp(document::BucketId(16, 1234));
- tmp.getDocuments().push_back(entry);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)63, serialize("DocumentListMessage", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("DocumentListMessage", DocumentProtocol::MESSAGE_DOCUMENTLIST, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- DocumentListMessage &ref = static_cast<DocumentListMessage&>(*obj);
-
- EXPECT_EQUAL("userdoc:scheme:1234:", ref.getDocuments()[0].getDocument()->getId().toString());
- EXPECT_EQUAL(1234, ref.getDocuments()[0].getTimestamp());
- EXPECT_TRUE(!ref.getDocuments()[0].isRemoveEntry());
- }
- }
- return true;
-}
-
-
-bool
-Messages50Test::testRemoveLocationMessage()
-{
- {
- document::BucketIdFactory factory;
- document::select::Parser parser(getTypeRepo(), factory);
- RemoveLocationMessage msg(factory, parser, "id.group == \"mygroup\"");
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 29u, serialize("RemoveLocationMessage", msg));
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("RemoveLocationMessage", DocumentProtocol::MESSAGE_REMOVELOCATION, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- RemoveLocationMessage &ref = static_cast<RemoveLocationMessage&>(*obj);
- EXPECT_EQUAL(string("id.group == \"mygroup\""), ref.getDocumentSelection());
- // FIXME add to wire format, currently hardcoded.
- EXPECT_EQUAL(string(document::FixedBucketSpaces::default_space_name()), ref.getBucketSpace());
- }
- }
- }
-
- return true;
-}
-
-
-
-bool
-Messages50Test::testDocumentSummaryMessage()
-{
- DocumentSummaryMessage srm;
- EXPECT_EQUAL(srm.hasSequenceId(), false);
- EXPECT_EQUAL(srm.getSummaryCount(), size_t(0));
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + size_t(12), serialize("DocumentSummaryMessage-1", srm));
-
- mbus::Routable::UP routable = deserialize("DocumentSummaryMessage-1", DocumentProtocol::MESSAGE_DOCUMENTSUMMARY, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- DocumentSummaryMessage * dm = static_cast<DocumentSummaryMessage *>(routable.get());
- EXPECT_EQUAL(dm->getSummaryCount(), size_t(0));
-
- srm.addSummary("doc1", "summary1", 8);
- srm.addSummary("aoc17", "summary45", 9);
-
- const void *summary(NULL);
- const char *docId(NULL);
- size_t sz(0);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 52u, serialize("DocumentSummaryMessage-2", srm));
- routable = deserialize("DocumentSummaryMessage-2", DocumentProtocol::MESSAGE_DOCUMENTSUMMARY, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<DocumentSummaryMessage *>(routable.get());
- EXPECT_EQUAL(dm->getSummaryCount(), size_t(2));
- dm->getSummary(0, docId, summary, sz);
- EXPECT_EQUAL(sz, 8u);
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- EXPECT_EQUAL(memcmp("summary1", summary, sz), 0);
- dm->getSummary(1, docId, summary, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(strcmp("aoc17", docId), 0);
- EXPECT_EQUAL(memcmp("summary45", summary, sz), 0);
-
- srm.sort();
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 52u, serialize("DocumentSummaryMessage-3", srm));
- routable = deserialize("DocumentSummaryMessage-3", DocumentProtocol::MESSAGE_DOCUMENTSUMMARY, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<DocumentSummaryMessage *>(routable.get());
- EXPECT_EQUAL(dm->getSummaryCount(), size_t(2));
- dm->getSummary(0, docId, summary, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(strcmp("aoc17", docId), 0);
- EXPECT_EQUAL(memcmp("summary45", summary, sz), 0);
- dm->getSummary(1, docId, summary, sz);
- EXPECT_EQUAL(sz, 8u);
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- EXPECT_EQUAL(memcmp("summary1", summary, sz), 0);
- return true;
-}
-
-bool
-Messages50Test::testGetDocumentMessage()
-{
- GetDocumentMessage tmp(document::DocumentId("doc:scheme:"), 0);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)20, serialize("GetDocumentMessage", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("GetDocumentMessage", DocumentProtocol::MESSAGE_GETDOCUMENT, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- GetDocumentMessage &ref = static_cast<GetDocumentMessage&>(*obj);
- EXPECT_EQUAL(string("doc:scheme:"), ref.getDocumentId().toString());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testMapVisitorMessage()
-{
- MapVisitorMessage tmp;
- tmp.getData().set("foo", 3);
- tmp.getData().set("bar", 5);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)32, serialize("MapVisitorMessage", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("MapVisitorMessage", DocumentProtocol::MESSAGE_MAPVISITOR, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- MapVisitorMessage &ref = static_cast<MapVisitorMessage&>(*obj);
- EXPECT_EQUAL(3, ref.getData().get("foo", 0));
- EXPECT_EQUAL(5, ref.getData().get("bar", 0));
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testCreateVisitorReply()
-{
- CreateVisitorReply reply(DocumentProtocol::REPLY_CREATEVISITOR);
- reply.setLastBucket(document::BucketId(16, 123));
- vdslib::VisitorStatistics vs;
- vs.setBucketsVisited(3);
- vs.setDocumentsVisited(1000);
- vs.setBytesVisited(1024000);
- vs.setDocumentsReturned(123);
- vs.setBytesReturned(512000);
- vs.setSecondPassDocumentsReturned(456);
- vs.setSecondPassBytesReturned(789100);
- reply.setVisitorStatistics(vs);
-
- EXPECT_EQUAL(65u, serialize("CreateVisitorReply", reply));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("CreateVisitorReply", DocumentProtocol::REPLY_CREATEVISITOR, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- CreateVisitorReply &ref = static_cast<CreateVisitorReply&>(*obj);
-
- EXPECT_EQUAL(ref.getLastBucket(), document::BucketId(16, 123));
- EXPECT_EQUAL(ref.getVisitorStatistics().getBucketsVisited(), (uint32_t)3);
- EXPECT_EQUAL(ref.getVisitorStatistics().getDocumentsVisited(), (uint64_t)1000);
- EXPECT_EQUAL(ref.getVisitorStatistics().getBytesVisited(), (uint64_t)1024000);
- EXPECT_EQUAL(ref.getVisitorStatistics().getDocumentsReturned(), (uint64_t)123);
- EXPECT_EQUAL(ref.getVisitorStatistics().getBytesReturned(), (uint64_t)512000);
- EXPECT_EQUAL(ref.getVisitorStatistics().getSecondPassDocumentsReturned(), (uint64_t)456);
- EXPECT_EQUAL(ref.getVisitorStatistics().getSecondPassBytesReturned(), (uint64_t)789100);
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testPutDocumentMessage()
-{
- document::Document::SP doc =
- createDoc(getTypeRepo(), "testdoc", "doc:scheme:");
- PutDocumentMessage msg(doc);
-
- msg.setTimestamp(666);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 41u, serialize("PutDocumentMessage", msg));
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("PutDocumentMessage", DocumentProtocol::MESSAGE_PUTDOCUMENT, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- PutDocumentMessage &ref = static_cast<PutDocumentMessage&>(*obj);
- EXPECT_TRUE(ref.getDocument().getType().getName() == "testdoc");
- EXPECT_TRUE(ref.getDocument().getId().toString() == "doc:scheme:");
- EXPECT_EQUAL(666u, ref.getTimestamp());
- EXPECT_EQUAL(37u, ref.getApproxSize());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testGetBucketStateMessage()
-{
- GetBucketStateMessage tmp;
- tmp.setBucketId(document::BucketId(16, 666));
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 12u, serialize("GetBucketStateMessage", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("GetBucketStateMessage", DocumentProtocol::MESSAGE_GETBUCKETSTATE, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- GetBucketStateMessage &ref = static_cast<GetBucketStateMessage&>(*obj);
-
- EXPECT_EQUAL(16u, ref.getBucketId().getUsedBits());
- EXPECT_EQUAL(4611686018427388570ull, ref.getBucketId().getId());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testPutDocumentReply()
-{
- WriteDocumentReply reply(DocumentProtocol::REPLY_PUTDOCUMENT);
- reply.setHighestModificationTimestamp(30);
-
- EXPECT_EQUAL(13u, serialize("PutDocumentReply", reply));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("PutDocumentReply", DocumentProtocol::REPLY_PUTDOCUMENT, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- WriteDocumentReply &ref = static_cast<WriteDocumentReply&>(*obj);
- EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testUpdateDocumentReply()
-{
- UpdateDocumentReply reply;
- reply.setWasFound(false);
- reply.setHighestModificationTimestamp(30);
-
- EXPECT_EQUAL(14u, serialize("UpdateDocumentReply", reply));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("UpdateDocumentReply", DocumentProtocol::REPLY_UPDATEDOCUMENT, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- UpdateDocumentReply &ref = static_cast<UpdateDocumentReply&>(*obj);
- EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp());
- EXPECT_EQUAL(false, ref.wasFound());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testRemoveDocumentMessage()
-{
- RemoveDocumentMessage tmp(document::DocumentId("doc:scheme:"));
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)16, serialize("RemoveDocumentMessage", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("RemoveDocumentMessage", DocumentProtocol::MESSAGE_REMOVEDOCUMENT, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- RemoveDocumentMessage &ref = static_cast<RemoveDocumentMessage&>(*obj);
- EXPECT_EQUAL(string("doc:scheme:"), ref.getDocumentId().toString());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testRemoveDocumentReply()
-{
- RemoveDocumentReply reply;
- std::vector<uint64_t> ts;
- reply.setWasFound(false);
- reply.setHighestModificationTimestamp(30);
-
- EXPECT_EQUAL(14u, serialize("RemoveDocumentReply", reply));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("RemoveDocumentReply", DocumentProtocol::REPLY_REMOVEDOCUMENT, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- RemoveDocumentReply &ref = static_cast<RemoveDocumentReply&>(*obj);
- EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp());
- EXPECT_EQUAL(false, ref.wasFound());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testSearchResultMessage()
-{
- SearchResultMessage srm;
- EXPECT_EQUAL(srm.getSequenceId(), 0u);
- EXPECT_EQUAL(srm.getHitCount(), 0u);
- EXPECT_EQUAL(srm.getAggregatorList().getSerializedSize(), 4u);
- EXPECT_EQUAL(srm.vdslib::SearchResult::getSerializedSize(), 20u);
- EXPECT_EQUAL(srm.getSerializedSize(), 20u);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + size_t(24), serialize("SearchResultMessage-1", srm));
-
- mbus::Routable::UP routable = deserialize("SearchResultMessage-1", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- SearchResultMessage * dm = static_cast<SearchResultMessage *>(routable.get());
- EXPECT_EQUAL(dm->getSequenceId(), size_t(0));
- EXPECT_EQUAL(dm->getHitCount(), size_t(0));
-
- srm.addHit(0, "doc1", 89);
- srm.addHit(1, "doc17", 109);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 55u, serialize("SearchResultMessage-2", srm));
- routable = deserialize("SearchResultMessage-2", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<SearchResultMessage *>(routable.get());
- EXPECT_EQUAL(dm->getHitCount(), size_t(2));
- const char *docId;
- SearchResultMessage::RankType rank;
- dm->getHit(0, docId, rank);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- dm->getHit(1, docId, rank);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
-
- srm.sort();
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 55u, serialize("SearchResultMessage-3", srm));
- routable = deserialize("SearchResultMessage-3", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<SearchResultMessage *>(routable.get());
- EXPECT_EQUAL(dm->getHitCount(), size_t(2));
- dm->getHit(0, docId, rank);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
- dm->getHit(1, docId, rank);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
-
- SearchResultMessage srm2;
- srm2.addHit(0, "doc1", 89, "sortdata2", 9);
- srm2.addHit(1, "doc17", 109, "sortdata1", 9);
- srm2.addHit(2, "doc18", 90, "sortdata3", 9);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 108u, serialize("SearchResultMessage-4", srm2));
- routable = deserialize("SearchResultMessage-4", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<SearchResultMessage *>(routable.get());
- EXPECT_EQUAL(dm->getHitCount(), size_t(3));
- dm->getHit(0, docId, rank);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- dm->getHit(1, docId, rank);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
- dm->getHit(2, docId, rank);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", docId), 0);
-
- srm2.sort();
- const void *buf;
- size_t sz;
- srm2.getHit(0, docId, rank);
- srm2.getSortBlob(0, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
- srm2.getHit(1, docId, rank);
- srm2.getSortBlob(1, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- srm2.getHit(2, docId, rank);
- srm2.getSortBlob(2, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", docId), 0);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 108u, serialize("SearchResultMessage-5", srm2));
- routable = deserialize("SearchResultMessage-5", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<SearchResultMessage *>(routable.get());
- EXPECT_EQUAL(dm->getHitCount(), size_t(3));
- dm->getHit(0, docId, rank);
- dm->getSortBlob(0, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
- dm->getHit(1, docId, rank);
- dm->getSortBlob(1, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- dm->getHit(2, docId, rank);
- dm->getSortBlob(2, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
- EXPECT_EQUAL(rank, SearchResultMessage::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", docId), 0);
- return true;
-}
-
-bool
-Messages50Test::testUpdateDocumentMessage()
-{
- const DocumentTypeRepo &repo = getTypeRepo();
- const document::DocumentType &docType = *repo.getDocumentType("testdoc");
- auto upd(std::make_shared<document::DocumentUpdate>(repo, docType, document::DocumentId("doc:scheme:")));
- upd->addFieldPathUpdate(document::FieldPathUpdate::CP(
- new document::RemoveFieldPathUpdate("intfield", "testdoc.intfield > 0")));
- UpdateDocumentMessage msg(upd);
- msg.setOldTimestamp(666u);
- msg.setNewTimestamp(777u);
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 89u, serialize("UpdateDocumentMessage", msg));
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("UpdateDocumentMessage", DocumentProtocol::MESSAGE_UPDATEDOCUMENT, lang);
- if (EXPECT_TRUE(obj.get() != nullptr)) {
- UpdateDocumentMessage &ref = static_cast<UpdateDocumentMessage&>(*obj);
- EXPECT_EQUAL(*upd, ref.getDocumentUpdate());
- EXPECT_EQUAL(666u, ref.getOldTimestamp());
- EXPECT_EQUAL(777u, ref.getNewTimestamp());
- EXPECT_EQUAL(85u, ref.getApproxSize());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testQueryResultMessage()
-{
- QueryResultMessage srm;
- vdslib::SearchResult & sr(srm.getSearchResult());
- EXPECT_EQUAL(srm.getSequenceId(), 0u);
- EXPECT_EQUAL(sr.getHitCount(), 0u);
- EXPECT_EQUAL(sr.getAggregatorList().getSerializedSize(), 4u);
- EXPECT_EQUAL(sr.getSerializedSize(), 20u);
- EXPECT_EQUAL(srm.getApproxSize(), 28u);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + size_t(32), serialize("QueryResultMessage-1", srm));
-
- mbus::Routable::UP routable = deserialize("QueryResultMessage-1", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- QueryResultMessage * dm = static_cast<QueryResultMessage *>(routable.get());
- vdslib::SearchResult * dr(&dm->getSearchResult());
- EXPECT_EQUAL(dm->getSequenceId(), size_t(0));
- EXPECT_EQUAL(dr->getHitCount(), size_t(0));
-
- sr.addHit(0, "doc1", 89);
- sr.addHit(1, "doc17", 109);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 63u, serialize("QueryResultMessage-2", srm));
- routable = deserialize("QueryResultMessage-2", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<QueryResultMessage *>(routable.get());
- dr = &dm->getSearchResult();
- EXPECT_EQUAL(dr->getHitCount(), size_t(2));
- const char *docId;
- vdslib::SearchResult::RankType rank;
- dr->getHit(0, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- dr->getHit(1, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
-
- sr.sort();
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 63u, serialize("QueryResultMessage-3", srm));
- routable = deserialize("QueryResultMessage-3", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<QueryResultMessage *>(routable.get());
- dr = &dm->getSearchResult();
- EXPECT_EQUAL(dr->getHitCount(), size_t(2));
- dr->getHit(0, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
- dr->getHit(1, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
-
- QueryResultMessage srm2;
- vdslib::SearchResult & sr2(srm2.getSearchResult());
- sr2.addHit(0, "doc1", 89, "sortdata2", 9);
- sr2.addHit(1, "doc17", 109, "sortdata1", 9);
- sr2.addHit(2, "doc18", 90, "sortdata3", 9);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 116u, serialize("QueryResultMessage-4", srm2));
- routable = deserialize("QueryResultMessage-4", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<QueryResultMessage *>(routable.get());
- dr = &dm->getSearchResult();
- EXPECT_EQUAL(dr->getHitCount(), size_t(3));
- dr->getHit(0, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- dr->getHit(1, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
- dr->getHit(2, docId, rank);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", docId), 0);
-
- sr2.sort();
- const void *buf;
- size_t sz;
- sr2.getHit(0, docId, rank);
- sr2.getSortBlob(0, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
- sr2.getHit(1, docId, rank);
- sr2.getSortBlob(1, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- sr2.getHit(2, docId, rank);
- sr2.getSortBlob(2, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", docId), 0);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 116u, serialize("QueryResultMessage-5", srm2));
- routable = deserialize("QueryResultMessage-5", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
- if (!EXPECT_TRUE(routable.get() != NULL)) {
- return false;
- }
- dm = static_cast<QueryResultMessage *>(routable.get());
- dr = &dm->getSearchResult();
- EXPECT_EQUAL(dr->getHitCount(), size_t(3));
- dr->getHit(0, docId, rank);
- dr->getSortBlob(0, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
- EXPECT_EQUAL(strcmp("doc17", docId), 0);
- dr->getHit(1, docId, rank);
- dr->getSortBlob(1, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
- EXPECT_EQUAL(strcmp("doc1", docId), 0);
- dr->getHit(2, docId, rank);
- dr->getSortBlob(2, buf, sz);
- EXPECT_EQUAL(sz, 9u);
- EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
- EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
- EXPECT_EQUAL(strcmp("doc18", docId), 0);
- return true;
-}
-
-bool
-Messages50Test::testQueryResultReply()
-{
- return tryVisitorReply("QueryResultReply", DocumentProtocol::REPLY_QUERYRESULT);
-}
-
-bool
-Messages50Test::testVisitorInfoMessage()
-{
-
- VisitorInfoMessage tmp;
- tmp.getFinishedBuckets().push_back(document::BucketId(16, 1));
- tmp.getFinishedBuckets().push_back(document::BucketId(16, 2));
- tmp.getFinishedBuckets().push_back(document::BucketId(16, 4));
- string utf8 = "error message: \u00e6\u00c6\u00f8\u00d8\u00e5\u00c5\u00f6\u00d6";
- tmp.setErrorMessage(utf8);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 67u, serialize("VisitorInfoMessage", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("VisitorInfoMessage", DocumentProtocol::MESSAGE_VISITORINFO, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- VisitorInfoMessage &ref = static_cast<VisitorInfoMessage&>(*obj);
- EXPECT_EQUAL(document::BucketId(16, 1), ref.getFinishedBuckets()[0]);
- EXPECT_EQUAL(document::BucketId(16, 2), ref.getFinishedBuckets()[1]);
- EXPECT_EQUAL(document::BucketId(16, 4), ref.getFinishedBuckets()[2]);
- EXPECT_EQUAL(utf8, ref.getErrorMessage());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testDestroyVisitorReply()
-{
- return tryDocumentReply("DestroyVisitorReply", DocumentProtocol::REPLY_DESTROYVISITOR);
-}
-
-bool
-Messages50Test::testDocumentListReply()
-{
- return tryVisitorReply("DocumentListReply", DocumentProtocol::REPLY_DOCUMENTLIST);
-}
-
-bool
-Messages50Test::testDocumentSummaryReply()
-{
- return tryVisitorReply("DocumentSummaryReply", DocumentProtocol::REPLY_DOCUMENTSUMMARY);
-}
-
-bool
-Messages50Test::testGetDocumentReply()
-{
- document::Document::SP doc =
- createDoc(getTypeRepo(), "testdoc", "doc:scheme:");
- GetDocumentReply tmp(doc);
-
- EXPECT_EQUAL((size_t)43, serialize("GetDocumentReply", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("GetDocumentReply", DocumentProtocol::REPLY_GETDOCUMENT, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- GetDocumentReply &ref = static_cast<GetDocumentReply&>(*obj);
-
- EXPECT_EQUAL(string("testdoc"), ref.getDocument().getType().getName());
- EXPECT_EQUAL(string("doc:scheme:"), ref.getDocument().getId().toString());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testMapVisitorReply()
-{
- return tryVisitorReply("MapVisitorReply", DocumentProtocol::REPLY_MAPVISITOR);
-}
-
-bool
-Messages50Test::testSearchResultReply()
-{
- return tryVisitorReply("SearchResultReply", DocumentProtocol::REPLY_SEARCHRESULT);
-}
-
-bool
-Messages50Test::testStatBucketReply()
-{
- StatBucketReply msg;
- msg.setResults("These are the votes of the Norwegian jury");
-
- EXPECT_EQUAL(50u, serialize("StatBucketReply", msg));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("StatBucketReply", DocumentProtocol::REPLY_STATBUCKET, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- StatBucketReply &ref = static_cast<StatBucketReply&>(*obj);
- EXPECT_EQUAL("These are the votes of the Norwegian jury", ref.getResults());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testVisitorInfoReply()
-{
- return tryVisitorReply("VisitorInfoReply", DocumentProtocol::REPLY_VISITORINFO);
-}
-
-bool
-Messages50Test::testWrongDistributionReply()
-{
- WrongDistributionReply tmp("distributor:3 storage:2");
-
- serialize("WrongDistributionReply", tmp);
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("WrongDistributionReply", DocumentProtocol::REPLY_WRONGDISTRIBUTION, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- WrongDistributionReply &ref = static_cast<WrongDistributionReply&>(*obj);
- EXPECT_EQUAL(string("distributor:3 storage:2"), ref.getSystemState());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testGetBucketListReply()
-{
- GetBucketListReply reply;
- reply.getBuckets().push_back(GetBucketListReply::BucketInfo(document::BucketId(16, 123), "foo"));
- reply.getBuckets().push_back(GetBucketListReply::BucketInfo(document::BucketId(17, 1123), "bar"));
- reply.getBuckets().push_back(GetBucketListReply::BucketInfo(document::BucketId(18, 11123), "zoink"));
-
- EXPECT_EQUAL(56u, serialize("GetBucketListReply", reply));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("GetBucketListReply", DocumentProtocol::REPLY_GETBUCKETLIST, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- GetBucketListReply &ref = static_cast<GetBucketListReply&>(*obj);
-
- EXPECT_EQUAL(ref.getBuckets()[0], GetBucketListReply::BucketInfo(document::BucketId(16, 123), "foo"));
- EXPECT_EQUAL(ref.getBuckets()[1], GetBucketListReply::BucketInfo(document::BucketId(17, 1123), "bar"));
- EXPECT_EQUAL(ref.getBuckets()[2], GetBucketListReply::BucketInfo(document::BucketId(18, 11123), "zoink"));
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testGetBucketStateReply()
-{
- document::GlobalId foo = document::DocumentId("doc:scheme:foo").getGlobalId();
- document::GlobalId bar = document::DocumentId("doc:scheme:bar").getGlobalId();
-
- GetBucketStateReply reply;
- reply.getBucketState().push_back(DocumentState(foo, 777, false));
- reply.getBucketState().push_back(DocumentState(bar, 888, true));
- EXPECT_EQUAL(53u, serialize("GetBucketStateReply", reply));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("GetBucketStateReply", DocumentProtocol::REPLY_GETBUCKETSTATE, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- GetBucketStateReply &ref = static_cast<GetBucketStateReply&>(*obj);
-
- EXPECT_EQUAL(777u, ref.getBucketState()[0].getTimestamp());
- EXPECT_EQUAL(foo, ref.getBucketState()[0].getGlobalId());
- EXPECT_EQUAL(false, ref.getBucketState()[0].isRemoveEntry());
- EXPECT_EQUAL(888u, ref.getBucketState()[1].getTimestamp());
- EXPECT_EQUAL(bar, ref.getBucketState()[1].getGlobalId());
- EXPECT_EQUAL(true, ref.getBucketState()[1].isRemoveEntry());
- }
- }
- return true;
-}
-
-bool
-Messages50Test::testEmptyBucketsReply()
-{
- return tryVisitorReply("EmptyBucketsReply", DocumentProtocol::REPLY_EMPTYBUCKETS);
-}
-
-bool
-Messages50Test::testRemoveLocationReply()
-{
- DocumentReply tmp(DocumentProtocol::REPLY_REMOVELOCATION);
-
- EXPECT_EQUAL((uint32_t)5, serialize("RemoveLocationReply", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("RemoveLocationReply", DocumentProtocol::REPLY_REMOVELOCATION, lang);
- EXPECT_TRUE(obj.get() != NULL);
- }
- return true;
-}
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// Utilities
-//
-////////////////////////////////////////////////////////////////////////////////
-
-bool
-Messages50Test::tryDocumentReply(const string &filename, uint32_t type)
-{
- DocumentReply tmp(type);
-
- EXPECT_EQUAL((uint32_t)5, serialize(filename, tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize(filename, type, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- DocumentReply *ref = dynamic_cast<DocumentReply*>(obj.get());
- EXPECT_TRUE(ref != NULL);
- }
- }
- return true;
-}
-
-bool
-Messages50Test::tryVisitorReply(const string &filename, uint32_t type)
-{
- VisitorReply tmp(type);
-
- EXPECT_EQUAL((uint32_t)5, serialize(filename, tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize(filename, type, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- VisitorReply *ref = dynamic_cast<VisitorReply*>(obj.get());
- EXPECT_TRUE(ref != NULL);
- }
- }
- return true;
-}
diff --git a/documentapi/src/tests/messages/messages50test.h b/documentapi/src/tests/messages/messages50test.h
deleted file mode 100644
index 96c1be78c27..00000000000
--- a/documentapi/src/tests/messages/messages50test.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include "testbase.h"
-
-class Messages50Test : public TestBase {
-protected:
- const vespalib::Version getVersion() const override { return vespalib::Version(5, 0); }
- bool shouldTestCoverage() const override { return false; }
- bool tryDocumentReply(const string &filename, uint32_t type);
- bool tryVisitorReply(const string &filename, uint32_t type);
-
-public:
- Messages50Test();
-
- bool testCreateVisitorMessage();
- bool testCreateVisitorReply();
- bool testDestroyVisitorMessage();
- bool testDestroyVisitorReply();
- bool testDocumentListMessage();
- bool testDocumentListReply();
- bool testDocumentSummaryMessage();
- bool testDocumentSummaryReply();
- bool testEmptyBucketsMessage();
- bool testEmptyBucketsReply();
- bool testGetBucketListMessage();
- bool testGetBucketListReply();
- bool testGetBucketStateMessage();
- bool testGetBucketStateReply();
- bool testGetDocumentMessage();
- bool testGetDocumentReply();
- bool testMapVisitorMessage();
- bool testMapVisitorReply();
- bool testPutDocumentMessage();
- bool testPutDocumentReply();
- bool testQueryResultMessage();
- bool testQueryResultReply();
- bool testRemoveDocumentMessage();
- bool testRemoveDocumentReply();
- bool testRemoveLocationMessage();
- bool testRemoveLocationReply();
- bool testSearchResultMessage();
- bool testSearchResultReply();
- bool testStatBucketMessage();
- bool testStatBucketReply();
- bool testUpdateDocumentMessage();
- bool testUpdateDocumentReply();
- bool testVisitorInfoMessage();
- bool testVisitorInfoReply();
- bool testWrongDistributionReply();
-};
-
diff --git a/documentapi/src/tests/messages/messages51test.cpp b/documentapi/src/tests/messages/messages51test.cpp
deleted file mode 100644
index 1fca5b8c473..00000000000
--- a/documentapi/src/tests/messages/messages51test.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "messages51test.h"
-#include <vespa/documentapi/documentapi.h>
-#include <vespa/document/update/fieldpathupdates.h>
-
-using document::DataType;
-using document::DocumentTypeRepo;
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// Setup
-//
-///////////////////////////////////////////////////////////////////////////////
-
-Messages51Test::Messages51Test()
-{
- // This list MUST mirror the list of routable factories from the DocumentProtocol constructor that support
- // version 5.0. When adding tests to this list, please KEEP THEM ORDERED alphabetically like they are now.
- putTest(DocumentProtocol::MESSAGE_CREATEVISITOR, TEST_METHOD(Messages51Test::testCreateVisitorMessage));
- putTest(DocumentProtocol::MESSAGE_GETDOCUMENT, TEST_METHOD(Messages51Test::testGetDocumentMessage));
- putTest(DocumentProtocol::REPLY_DOCUMENTIGNORED, TEST_METHOD(Messages51Test::testDocumentIgnoredReply));
-}
-
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// Tests
-//
-///////////////////////////////////////////////////////////////////////////////
-
-static const int MESSAGE_BASE_LENGTH = 5;
-
-bool
-Messages51Test::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);
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)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.get() != NULL)) {
- CreateVisitorMessage &ref = static_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());
- }
- }
- return true;
-}
-
-bool
-Messages51Test::testGetDocumentMessage()
-{
- GetDocumentMessage tmp(document::DocumentId("doc:scheme:"), "foo bar");
-
- EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)27, serialize("GetDocumentMessage", tmp));
-
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj = deserialize("GetDocumentMessage", DocumentProtocol::MESSAGE_GETDOCUMENT, lang);
- if (EXPECT_TRUE(obj.get() != NULL)) {
- GetDocumentMessage &ref = static_cast<GetDocumentMessage&>(*obj);
- EXPECT_EQUAL(string("doc:scheme:"), ref.getDocumentId().toString());
- EXPECT_EQUAL(string("foo bar"), ref.getFieldSet());
- }
- }
- return true;
-}
-
-bool
-Messages51Test::testDocumentIgnoredReply()
-{
- DocumentIgnoredReply tmp;
- serialize("DocumentIgnoredReply", tmp);
- for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
- mbus::Routable::UP obj(
- deserialize("DocumentIgnoredReply",
- DocumentProtocol::REPLY_DOCUMENTIGNORED, lang));
- EXPECT_TRUE(obj.get() != NULL);
- }
- return true;
-}
diff --git a/documentapi/src/tests/messages/messages51test.h b/documentapi/src/tests/messages/messages51test.h
deleted file mode 100644
index 897491af892..00000000000
--- a/documentapi/src/tests/messages/messages51test.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include "messages50test.h"
-
-class Messages51Test : public Messages50Test {
-protected:
- const vespalib::Version getVersion() const override { return vespalib::Version(5, 1); }
- bool shouldTestCoverage() const override { return true; }
-
-public:
- Messages51Test();
-
- bool testCreateVisitorMessage();
- bool testGetDocumentMessage();
- bool testDocumentIgnoredReply();
-};
-
diff --git a/documentapi/src/tests/messages/messages52test.cpp b/documentapi/src/tests/messages/messages52test.cpp
index 1da48d4aa41..21307326a75 100644
--- a/documentapi/src/tests/messages/messages52test.cpp
+++ b/documentapi/src/tests/messages/messages52test.cpp
@@ -1,16 +1,78 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// @author Vegard Sjonfjell
-
#include "messages52test.h"
-#include <vespa/documentapi/documentapi.h>
+#include <vespa/document/bucket/bucketidfactory.h>
+#include <vespa/document/datatype/documenttype.h>
+#include <vespa/document/select/parser.h>
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/document/update/documentupdate.h>
#include <vespa/document/update/fieldpathupdates.h>
-#include <vespa/document/datatype/documenttype.h>
+#include <vespa/documentapi/documentapi.h>
+#include <vespa/document/bucket/fixed_bucket_spaces.h>
+using document::DataType;
using document::DocumentTypeRepo;
+///////////////////////////////////////////////////////////////////////////////
+//
+// Setup
+//
+///////////////////////////////////////////////////////////////////////////////
+
+Messages52Test::Messages52Test()
+{
+ // This list MUST mirror the list of routable factories from the DocumentProtocol constructor that support
+ // version 5.0. When adding tests to this list, please KEEP THEM ORDERED alphabetically like they are now.
+ putTest(DocumentProtocol::MESSAGE_CREATEVISITOR, TEST_METHOD(Messages52Test::testCreateVisitorMessage));
+ putTest(DocumentProtocol::MESSAGE_DESTROYVISITOR, TEST_METHOD(Messages52Test::testDestroyVisitorMessage));
+ putTest(DocumentProtocol::MESSAGE_DOCUMENTLIST, TEST_METHOD(Messages52Test::testDocumentListMessage));
+ putTest(DocumentProtocol::MESSAGE_DOCUMENTSUMMARY, TEST_METHOD(Messages52Test::testDocumentSummaryMessage));
+ putTest(DocumentProtocol::MESSAGE_EMPTYBUCKETS, TEST_METHOD(Messages52Test::testEmptyBucketsMessage));
+ putTest(DocumentProtocol::MESSAGE_GETBUCKETLIST, TEST_METHOD(Messages52Test::testGetBucketListMessage));
+ putTest(DocumentProtocol::MESSAGE_GETBUCKETSTATE, TEST_METHOD(Messages52Test::testGetBucketStateMessage));
+ putTest(DocumentProtocol::MESSAGE_GETDOCUMENT, TEST_METHOD(Messages52Test::testGetDocumentMessage));
+ putTest(DocumentProtocol::MESSAGE_MAPVISITOR, TEST_METHOD(Messages52Test::testMapVisitorMessage));
+ putTest(DocumentProtocol::MESSAGE_PUTDOCUMENT, TEST_METHOD(Messages52Test::testPutDocumentMessage));
+ putTest(DocumentProtocol::MESSAGE_QUERYRESULT, TEST_METHOD(Messages52Test::testQueryResultMessage));
+ putTest(DocumentProtocol::MESSAGE_REMOVEDOCUMENT, TEST_METHOD(Messages52Test::testRemoveDocumentMessage));
+ putTest(DocumentProtocol::MESSAGE_REMOVELOCATION, TEST_METHOD(Messages52Test::testRemoveLocationMessage));
+ putTest(DocumentProtocol::MESSAGE_SEARCHRESULT, TEST_METHOD(Messages52Test::testSearchResultMessage));
+ putTest(DocumentProtocol::MESSAGE_STATBUCKET, TEST_METHOD(Messages52Test::testStatBucketMessage));
+ putTest(DocumentProtocol::MESSAGE_UPDATEDOCUMENT, TEST_METHOD(Messages52Test::testUpdateDocumentMessage));
+ putTest(DocumentProtocol::MESSAGE_VISITORINFO, TEST_METHOD(Messages52Test::testVisitorInfoMessage));
+
+ putTest(DocumentProtocol::REPLY_CREATEVISITOR, TEST_METHOD(Messages52Test::testCreateVisitorReply));
+ putTest(DocumentProtocol::REPLY_DESTROYVISITOR, TEST_METHOD(Messages52Test::testDestroyVisitorReply));
+ putTest(DocumentProtocol::REPLY_DOCUMENTIGNORED, TEST_METHOD(Messages52Test::testDocumentIgnoredReply));
+ putTest(DocumentProtocol::REPLY_DOCUMENTLIST, TEST_METHOD(Messages52Test::testDocumentListReply));
+ putTest(DocumentProtocol::REPLY_DOCUMENTSUMMARY, TEST_METHOD(Messages52Test::testDocumentSummaryReply));
+ putTest(DocumentProtocol::REPLY_EMPTYBUCKETS, TEST_METHOD(Messages52Test::testEmptyBucketsReply));
+ putTest(DocumentProtocol::REPLY_GETBUCKETLIST, TEST_METHOD(Messages52Test::testGetBucketListReply));
+ putTest(DocumentProtocol::REPLY_GETBUCKETSTATE, TEST_METHOD(Messages52Test::testGetBucketStateReply));
+ putTest(DocumentProtocol::REPLY_GETDOCUMENT, TEST_METHOD(Messages52Test::testGetDocumentReply));
+ putTest(DocumentProtocol::REPLY_MAPVISITOR, TEST_METHOD(Messages52Test::testMapVisitorReply));
+ putTest(DocumentProtocol::REPLY_PUTDOCUMENT, TEST_METHOD(Messages52Test::testPutDocumentReply));
+ putTest(DocumentProtocol::REPLY_QUERYRESULT, TEST_METHOD(Messages52Test::testQueryResultReply));
+ putTest(DocumentProtocol::REPLY_REMOVEDOCUMENT, TEST_METHOD(Messages52Test::testRemoveDocumentReply));
+ putTest(DocumentProtocol::REPLY_REMOVELOCATION, TEST_METHOD(Messages52Test::testRemoveLocationReply));
+ putTest(DocumentProtocol::REPLY_SEARCHRESULT, TEST_METHOD(Messages52Test::testSearchResultReply));
+ putTest(DocumentProtocol::REPLY_STATBUCKET, TEST_METHOD(Messages52Test::testStatBucketReply));
+ putTest(DocumentProtocol::REPLY_UPDATEDOCUMENT, TEST_METHOD(Messages52Test::testUpdateDocumentReply));
+ putTest(DocumentProtocol::REPLY_VISITORINFO, TEST_METHOD(Messages52Test::testVisitorInfoReply));
+ putTest(DocumentProtocol::REPLY_WRONGDISTRIBUTION, TEST_METHOD(Messages52Test::testWrongDistributionReply));
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Tests
+//
+///////////////////////////////////////////////////////////////////////////////
+
+static const int MESSAGE_BASE_LENGTH = 5;
+
namespace {
document::Document::SP
@@ -21,18 +83,308 @@ createDoc(const DocumentTypeRepo &repo, const string &type_name, const string &i
document::DocumentId(id)));
}
+} // namespace
+
+bool
+Messages52Test::testGetBucketListMessage()
+{
+ GetBucketListMessage msg(document::BucketId(16, 123));
+ msg.setLoadType(_loadTypes["foo"]);
+ EXPECT_EQUAL(string("foo"), msg.getLoadType().getName());
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 12u, serialize("GetBucketListMessage", msg));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("GetBucketListMessage", DocumentProtocol::MESSAGE_GETBUCKETLIST, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ GetBucketListMessage &ref = static_cast<GetBucketListMessage&>(*obj);
+ EXPECT_EQUAL(string("foo"), ref.getLoadType().getName());
+ EXPECT_EQUAL(document::BucketId(16, 123), ref.getBucketId());
+ }
+ }
+ return true;
}
-static constexpr int MESSAGE_BASE_LENGTH = 5;
+bool
+Messages52Test::testEmptyBucketsMessage()
+{
+ std::vector<document::BucketId> bids;
+ for (size_t i=0; i < 13; ++i) {
+ bids.push_back(document::BucketId(16, i));
+ }
-Messages52Test::Messages52Test()
+ EmptyBucketsMessage msg(bids);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 112u, serialize("EmptyBucketsMessage", msg));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("EmptyBucketsMessage", DocumentProtocol::MESSAGE_EMPTYBUCKETS, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ EmptyBucketsMessage &ref = static_cast<EmptyBucketsMessage&>(*obj);
+ for (size_t i=0; i < 13; ++i) {
+ EXPECT_EQUAL(document::BucketId(16, i), ref.getBucketIds()[i]);
+ }
+ }
+ }
+ return true;
+}
+
+
+bool
+Messages52Test::testStatBucketMessage()
{
- // This list MUST mirror the list of routable factories from the DocumentProtocol constructor that support
- // version 5.2. When adding tests to this list, please KEEP THEM ORDERED alphabetically like they are now.
+ StatBucketMessage msg(document::BucketId(16, 123), "id.user=123");
- putTest(DocumentProtocol::MESSAGE_PUTDOCUMENT, TEST_METHOD(Messages52Test::testPutDocumentMessage));
- putTest(DocumentProtocol::MESSAGE_REMOVEDOCUMENT, TEST_METHOD(Messages52Test::testRemoveDocumentMessage));
- putTest(DocumentProtocol::MESSAGE_UPDATEDOCUMENT, TEST_METHOD(Messages52Test::testUpdateDocumentMessage));
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 27u, serialize("StatBucketMessage", msg));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("StatBucketMessage", DocumentProtocol::MESSAGE_STATBUCKET, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ StatBucketMessage &ref = static_cast<StatBucketMessage&>(*obj);
+ EXPECT_EQUAL(document::BucketId(16, 123), ref.getBucketId());
+ EXPECT_EQUAL("id.user=123", ref.getDocumentSelection());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::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);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)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.get() != NULL)) {
+ CreateVisitorMessage &ref = static_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());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testDestroyVisitorMessage()
+{
+ DestroyVisitorMessage tmp("myvisitor");
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)17, serialize("DestroyVisitorMessage", tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("DestroyVisitorMessage", DocumentProtocol::MESSAGE_DESTROYVISITOR, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ DestroyVisitorMessage &ref = static_cast<DestroyVisitorMessage&>(*obj);
+ EXPECT_EQUAL(string("myvisitor"), ref.getInstanceId());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testDocumentListMessage()
+{
+ document::Document::SP doc =
+ createDoc(getTypeRepo(), "testdoc", "userdoc:scheme:1234:");
+ DocumentListMessage::Entry entry(1234, doc, false);
+
+ DocumentListMessage tmp(document::BucketId(16, 1234));
+ tmp.getDocuments().push_back(entry);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)63, serialize("DocumentListMessage", tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("DocumentListMessage", DocumentProtocol::MESSAGE_DOCUMENTLIST, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ DocumentListMessage &ref = static_cast<DocumentListMessage&>(*obj);
+
+ EXPECT_EQUAL("userdoc:scheme:1234:", ref.getDocuments()[0].getDocument()->getId().toString());
+ EXPECT_EQUAL(1234, ref.getDocuments()[0].getTimestamp());
+ EXPECT_TRUE(!ref.getDocuments()[0].isRemoveEntry());
+ }
+ }
+ return true;
+}
+
+
+bool
+Messages52Test::testRemoveLocationMessage()
+{
+ {
+ document::BucketIdFactory factory;
+ document::select::Parser parser(getTypeRepo(), factory);
+ RemoveLocationMessage msg(factory, parser, "id.group == \"mygroup\"");
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 29u, serialize("RemoveLocationMessage", msg));
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("RemoveLocationMessage", DocumentProtocol::MESSAGE_REMOVELOCATION, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ RemoveLocationMessage &ref = static_cast<RemoveLocationMessage&>(*obj);
+ EXPECT_EQUAL(string("id.group == \"mygroup\""), ref.getDocumentSelection());
+ // FIXME add to wire format, currently hardcoded.
+ EXPECT_EQUAL(string(document::FixedBucketSpaces::default_space_name()), ref.getBucketSpace());
+ }
+ }
+ }
+
+ return true;
+}
+
+
+
+bool
+Messages52Test::testDocumentSummaryMessage()
+{
+ DocumentSummaryMessage srm;
+ EXPECT_EQUAL(srm.hasSequenceId(), false);
+ EXPECT_EQUAL(srm.getSummaryCount(), size_t(0));
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + size_t(12), serialize("DocumentSummaryMessage-1", srm));
+
+ mbus::Routable::UP routable = deserialize("DocumentSummaryMessage-1", DocumentProtocol::MESSAGE_DOCUMENTSUMMARY, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ DocumentSummaryMessage * dm = static_cast<DocumentSummaryMessage *>(routable.get());
+ EXPECT_EQUAL(dm->getSummaryCount(), size_t(0));
+
+ srm.addSummary("doc1", "summary1", 8);
+ srm.addSummary("aoc17", "summary45", 9);
+
+ const void *summary(NULL);
+ const char *docId(NULL);
+ size_t sz(0);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 52u, serialize("DocumentSummaryMessage-2", srm));
+ routable = deserialize("DocumentSummaryMessage-2", DocumentProtocol::MESSAGE_DOCUMENTSUMMARY, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<DocumentSummaryMessage *>(routable.get());
+ EXPECT_EQUAL(dm->getSummaryCount(), size_t(2));
+ dm->getSummary(0, docId, summary, sz);
+ EXPECT_EQUAL(sz, 8u);
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ EXPECT_EQUAL(memcmp("summary1", summary, sz), 0);
+ dm->getSummary(1, docId, summary, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(strcmp("aoc17", docId), 0);
+ EXPECT_EQUAL(memcmp("summary45", summary, sz), 0);
+
+ srm.sort();
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 52u, serialize("DocumentSummaryMessage-3", srm));
+ routable = deserialize("DocumentSummaryMessage-3", DocumentProtocol::MESSAGE_DOCUMENTSUMMARY, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<DocumentSummaryMessage *>(routable.get());
+ EXPECT_EQUAL(dm->getSummaryCount(), size_t(2));
+ dm->getSummary(0, docId, summary, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(strcmp("aoc17", docId), 0);
+ EXPECT_EQUAL(memcmp("summary45", summary, sz), 0);
+ dm->getSummary(1, docId, summary, sz);
+ EXPECT_EQUAL(sz, 8u);
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ EXPECT_EQUAL(memcmp("summary1", summary, sz), 0);
+ return true;
+}
+
+bool
+Messages52Test::testGetDocumentMessage()
+{
+ GetDocumentMessage tmp(document::DocumentId("doc:scheme:"), "foo bar");
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)27, serialize("GetDocumentMessage", tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("GetDocumentMessage", DocumentProtocol::MESSAGE_GETDOCUMENT, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ GetDocumentMessage &ref = static_cast<GetDocumentMessage&>(*obj);
+ EXPECT_EQUAL(string("doc:scheme:"), ref.getDocumentId().toString());
+ EXPECT_EQUAL(string("foo bar"), ref.getFieldSet());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testMapVisitorMessage()
+{
+ MapVisitorMessage tmp;
+ tmp.getData().set("foo", 3);
+ tmp.getData().set("bar", 5);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + (size_t)32, serialize("MapVisitorMessage", tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("MapVisitorMessage", DocumentProtocol::MESSAGE_MAPVISITOR, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ MapVisitorMessage &ref = static_cast<MapVisitorMessage&>(*obj);
+ EXPECT_EQUAL(3, ref.getData().get("foo", 0));
+ EXPECT_EQUAL(5, ref.getData().get("bar", 0));
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testCreateVisitorReply()
+{
+ CreateVisitorReply reply(DocumentProtocol::REPLY_CREATEVISITOR);
+ reply.setLastBucket(document::BucketId(16, 123));
+ vdslib::VisitorStatistics vs;
+ vs.setBucketsVisited(3);
+ vs.setDocumentsVisited(1000);
+ vs.setBytesVisited(1024000);
+ vs.setDocumentsReturned(123);
+ vs.setBytesReturned(512000);
+ vs.setSecondPassDocumentsReturned(456);
+ vs.setSecondPassBytesReturned(789100);
+ reply.setVisitorStatistics(vs);
+
+ EXPECT_EQUAL(65u, serialize("CreateVisitorReply", reply));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("CreateVisitorReply", DocumentProtocol::REPLY_CREATEVISITOR, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ CreateVisitorReply &ref = static_cast<CreateVisitorReply&>(*obj);
+
+ EXPECT_EQUAL(ref.getLastBucket(), document::BucketId(16, 123));
+ EXPECT_EQUAL(ref.getVisitorStatistics().getBucketsVisited(), (uint32_t)3);
+ EXPECT_EQUAL(ref.getVisitorStatistics().getDocumentsVisited(), (uint64_t)1000);
+ EXPECT_EQUAL(ref.getVisitorStatistics().getBytesVisited(), (uint64_t)1024000);
+ EXPECT_EQUAL(ref.getVisitorStatistics().getDocumentsReturned(), (uint64_t)123);
+ EXPECT_EQUAL(ref.getVisitorStatistics().getBytesReturned(), (uint64_t)512000);
+ EXPECT_EQUAL(ref.getVisitorStatistics().getSecondPassDocumentsReturned(), (uint64_t)456);
+ EXPECT_EQUAL(ref.getVisitorStatistics().getSecondPassBytesReturned(), (uint64_t)789100);
+ }
+ }
+ return true;
}
bool
@@ -66,6 +418,63 @@ Messages52Test::testPutDocumentMessage()
}
bool
+Messages52Test::testGetBucketStateMessage()
+{
+ GetBucketStateMessage tmp;
+ tmp.setBucketId(document::BucketId(16, 666));
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 12u, serialize("GetBucketStateMessage", tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("GetBucketStateMessage", DocumentProtocol::MESSAGE_GETBUCKETSTATE, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ GetBucketStateMessage &ref = static_cast<GetBucketStateMessage&>(*obj);
+
+ EXPECT_EQUAL(16u, ref.getBucketId().getUsedBits());
+ EXPECT_EQUAL(4611686018427388570ull, ref.getBucketId().getId());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testPutDocumentReply()
+{
+ WriteDocumentReply reply(DocumentProtocol::REPLY_PUTDOCUMENT);
+ reply.setHighestModificationTimestamp(30);
+
+ EXPECT_EQUAL(13u, serialize("PutDocumentReply", reply));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("PutDocumentReply", DocumentProtocol::REPLY_PUTDOCUMENT, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ WriteDocumentReply &ref = static_cast<WriteDocumentReply&>(*obj);
+ EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testUpdateDocumentReply()
+{
+ UpdateDocumentReply reply;
+ reply.setWasFound(false);
+ reply.setHighestModificationTimestamp(30);
+
+ EXPECT_EQUAL(14u, serialize("UpdateDocumentReply", reply));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("UpdateDocumentReply", DocumentProtocol::REPLY_UPDATEDOCUMENT, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ UpdateDocumentReply &ref = static_cast<UpdateDocumentReply&>(*obj);
+ EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp());
+ EXPECT_EQUAL(false, ref.wasFound());
+ }
+ }
+ return true;
+}
+
+bool
Messages52Test::testRemoveDocumentMessage()
{
RemoveDocumentMessage msg(document::DocumentId("doc:scheme:"));
@@ -87,6 +496,154 @@ Messages52Test::testRemoveDocumentMessage()
}
bool
+Messages52Test::testRemoveDocumentReply()
+{
+ RemoveDocumentReply reply;
+ std::vector<uint64_t> ts;
+ reply.setWasFound(false);
+ reply.setHighestModificationTimestamp(30);
+
+ EXPECT_EQUAL(14u, serialize("RemoveDocumentReply", reply));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("RemoveDocumentReply", DocumentProtocol::REPLY_REMOVEDOCUMENT, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ RemoveDocumentReply &ref = static_cast<RemoveDocumentReply&>(*obj);
+ EXPECT_EQUAL(30u, ref.getHighestModificationTimestamp());
+ EXPECT_EQUAL(false, ref.wasFound());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testSearchResultMessage()
+{
+ SearchResultMessage srm;
+ EXPECT_EQUAL(srm.getSequenceId(), 0u);
+ EXPECT_EQUAL(srm.getHitCount(), 0u);
+ EXPECT_EQUAL(srm.getAggregatorList().getSerializedSize(), 4u);
+ EXPECT_EQUAL(srm.vdslib::SearchResult::getSerializedSize(), 20u);
+ EXPECT_EQUAL(srm.getSerializedSize(), 20u);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + size_t(24), serialize("SearchResultMessage-1", srm));
+
+ mbus::Routable::UP routable = deserialize("SearchResultMessage-1", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ SearchResultMessage * dm = static_cast<SearchResultMessage *>(routable.get());
+ EXPECT_EQUAL(dm->getSequenceId(), size_t(0));
+ EXPECT_EQUAL(dm->getHitCount(), size_t(0));
+
+ srm.addHit(0, "doc1", 89);
+ srm.addHit(1, "doc17", 109);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 55u, serialize("SearchResultMessage-2", srm));
+ routable = deserialize("SearchResultMessage-2", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<SearchResultMessage *>(routable.get());
+ EXPECT_EQUAL(dm->getHitCount(), size_t(2));
+ const char *docId;
+ SearchResultMessage::RankType rank;
+ dm->getHit(0, docId, rank);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ dm->getHit(1, docId, rank);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+
+ srm.sort();
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 55u, serialize("SearchResultMessage-3", srm));
+ routable = deserialize("SearchResultMessage-3", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<SearchResultMessage *>(routable.get());
+ EXPECT_EQUAL(dm->getHitCount(), size_t(2));
+ dm->getHit(0, docId, rank);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ dm->getHit(1, docId, rank);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+
+ SearchResultMessage srm2;
+ srm2.addHit(0, "doc1", 89, "sortdata2", 9);
+ srm2.addHit(1, "doc17", 109, "sortdata1", 9);
+ srm2.addHit(2, "doc18", 90, "sortdata3", 9);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 108u, serialize("SearchResultMessage-4", srm2));
+ routable = deserialize("SearchResultMessage-4", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<SearchResultMessage *>(routable.get());
+ EXPECT_EQUAL(dm->getHitCount(), size_t(3));
+ dm->getHit(0, docId, rank);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ dm->getHit(1, docId, rank);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ dm->getHit(2, docId, rank);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(90));
+ EXPECT_EQUAL(strcmp("doc18", docId), 0);
+
+ srm2.sort();
+ const void *buf;
+ size_t sz;
+ srm2.getHit(0, docId, rank);
+ srm2.getSortBlob(0, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ srm2.getHit(1, docId, rank);
+ srm2.getSortBlob(1, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ srm2.getHit(2, docId, rank);
+ srm2.getSortBlob(2, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(90));
+ EXPECT_EQUAL(strcmp("doc18", docId), 0);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 108u, serialize("SearchResultMessage-5", srm2));
+ routable = deserialize("SearchResultMessage-5", DocumentProtocol::MESSAGE_SEARCHRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<SearchResultMessage *>(routable.get());
+ EXPECT_EQUAL(dm->getHitCount(), size_t(3));
+ dm->getHit(0, docId, rank);
+ dm->getSortBlob(0, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ dm->getHit(1, docId, rank);
+ dm->getSortBlob(1, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ dm->getHit(2, docId, rank);
+ dm->getSortBlob(2, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
+ EXPECT_EQUAL(rank, SearchResultMessage::RankType(90));
+ EXPECT_EQUAL(strcmp("doc18", docId), 0);
+ return true;
+}
+
+bool
Messages52Test::testUpdateDocumentMessage()
{
const DocumentTypeRepo & repo = getTypeRepo();
@@ -118,3 +675,387 @@ Messages52Test::testUpdateDocumentMessage()
}
return true;
}
+
+bool
+Messages52Test::testQueryResultMessage()
+{
+ QueryResultMessage srm;
+ vdslib::SearchResult & sr(srm.getSearchResult());
+ EXPECT_EQUAL(srm.getSequenceId(), 0u);
+ EXPECT_EQUAL(sr.getHitCount(), 0u);
+ EXPECT_EQUAL(sr.getAggregatorList().getSerializedSize(), 4u);
+ EXPECT_EQUAL(sr.getSerializedSize(), 20u);
+ EXPECT_EQUAL(srm.getApproxSize(), 28u);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + size_t(32), serialize("QueryResultMessage-1", srm));
+
+ mbus::Routable::UP routable = deserialize("QueryResultMessage-1", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ QueryResultMessage * dm = static_cast<QueryResultMessage *>(routable.get());
+ vdslib::SearchResult * dr(&dm->getSearchResult());
+ EXPECT_EQUAL(dm->getSequenceId(), size_t(0));
+ EXPECT_EQUAL(dr->getHitCount(), size_t(0));
+
+ sr.addHit(0, "doc1", 89);
+ sr.addHit(1, "doc17", 109);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 63u, serialize("QueryResultMessage-2", srm));
+ routable = deserialize("QueryResultMessage-2", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<QueryResultMessage *>(routable.get());
+ dr = &dm->getSearchResult();
+ EXPECT_EQUAL(dr->getHitCount(), size_t(2));
+ const char *docId;
+ vdslib::SearchResult::RankType rank;
+ dr->getHit(0, docId, rank);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ dr->getHit(1, docId, rank);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+
+ sr.sort();
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 63u, serialize("QueryResultMessage-3", srm));
+ routable = deserialize("QueryResultMessage-3", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<QueryResultMessage *>(routable.get());
+ dr = &dm->getSearchResult();
+ EXPECT_EQUAL(dr->getHitCount(), size_t(2));
+ dr->getHit(0, docId, rank);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ dr->getHit(1, docId, rank);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+
+ QueryResultMessage srm2;
+ vdslib::SearchResult & sr2(srm2.getSearchResult());
+ sr2.addHit(0, "doc1", 89, "sortdata2", 9);
+ sr2.addHit(1, "doc17", 109, "sortdata1", 9);
+ sr2.addHit(2, "doc18", 90, "sortdata3", 9);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 116u, serialize("QueryResultMessage-4", srm2));
+ routable = deserialize("QueryResultMessage-4", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<QueryResultMessage *>(routable.get());
+ dr = &dm->getSearchResult();
+ EXPECT_EQUAL(dr->getHitCount(), size_t(3));
+ dr->getHit(0, docId, rank);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ dr->getHit(1, docId, rank);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ dr->getHit(2, docId, rank);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
+ EXPECT_EQUAL(strcmp("doc18", docId), 0);
+
+ sr2.sort();
+ const void *buf;
+ size_t sz;
+ sr2.getHit(0, docId, rank);
+ sr2.getSortBlob(0, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ sr2.getHit(1, docId, rank);
+ sr2.getSortBlob(1, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ sr2.getHit(2, docId, rank);
+ sr2.getSortBlob(2, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
+ EXPECT_EQUAL(strcmp("doc18", docId), 0);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 116u, serialize("QueryResultMessage-5", srm2));
+ routable = deserialize("QueryResultMessage-5", DocumentProtocol::MESSAGE_QUERYRESULT, LANG_CPP);
+ if (!EXPECT_TRUE(routable.get() != NULL)) {
+ return false;
+ }
+ dm = static_cast<QueryResultMessage *>(routable.get());
+ dr = &dm->getSearchResult();
+ EXPECT_EQUAL(dr->getHitCount(), size_t(3));
+ dr->getHit(0, docId, rank);
+ dr->getSortBlob(0, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata1", buf, sz), 0);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(109));
+ EXPECT_EQUAL(strcmp("doc17", docId), 0);
+ dr->getHit(1, docId, rank);
+ dr->getSortBlob(1, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata2", buf, sz), 0);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(89));
+ EXPECT_EQUAL(strcmp("doc1", docId), 0);
+ dr->getHit(2, docId, rank);
+ dr->getSortBlob(2, buf, sz);
+ EXPECT_EQUAL(sz, 9u);
+ EXPECT_EQUAL(memcmp("sortdata3", buf, sz), 0);
+ EXPECT_EQUAL(rank, vdslib::SearchResult::RankType(90));
+ EXPECT_EQUAL(strcmp("doc18", docId), 0);
+ return true;
+}
+
+bool
+Messages52Test::testQueryResultReply()
+{
+ return tryVisitorReply("QueryResultReply", DocumentProtocol::REPLY_QUERYRESULT);
+}
+
+bool
+Messages52Test::testVisitorInfoMessage()
+{
+
+ VisitorInfoMessage tmp;
+ tmp.getFinishedBuckets().push_back(document::BucketId(16, 1));
+ tmp.getFinishedBuckets().push_back(document::BucketId(16, 2));
+ tmp.getFinishedBuckets().push_back(document::BucketId(16, 4));
+ string utf8 = "error message: \u00e6\u00c6\u00f8\u00d8\u00e5\u00c5\u00f6\u00d6";
+ tmp.setErrorMessage(utf8);
+
+ EXPECT_EQUAL(MESSAGE_BASE_LENGTH + 67u, serialize("VisitorInfoMessage", tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("VisitorInfoMessage", DocumentProtocol::MESSAGE_VISITORINFO, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ VisitorInfoMessage &ref = static_cast<VisitorInfoMessage&>(*obj);
+ EXPECT_EQUAL(document::BucketId(16, 1), ref.getFinishedBuckets()[0]);
+ EXPECT_EQUAL(document::BucketId(16, 2), ref.getFinishedBuckets()[1]);
+ EXPECT_EQUAL(document::BucketId(16, 4), ref.getFinishedBuckets()[2]);
+ EXPECT_EQUAL(utf8, ref.getErrorMessage());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testDestroyVisitorReply()
+{
+ return tryDocumentReply("DestroyVisitorReply", DocumentProtocol::REPLY_DESTROYVISITOR);
+}
+
+bool
+Messages52Test::testDocumentIgnoredReply()
+{
+ DocumentIgnoredReply tmp;
+ serialize("DocumentIgnoredReply", tmp);
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj(
+ deserialize("DocumentIgnoredReply",
+ DocumentProtocol::REPLY_DOCUMENTIGNORED, lang));
+ EXPECT_TRUE(obj.get() != NULL);
+ }
+ return true;
+}
+
+bool
+Messages52Test::testDocumentListReply()
+{
+ return tryVisitorReply("DocumentListReply", DocumentProtocol::REPLY_DOCUMENTLIST);
+}
+
+bool
+Messages52Test::testDocumentSummaryReply()
+{
+ return tryVisitorReply("DocumentSummaryReply", DocumentProtocol::REPLY_DOCUMENTSUMMARY);
+}
+
+bool
+Messages52Test::testGetDocumentReply()
+{
+ document::Document::SP doc =
+ createDoc(getTypeRepo(), "testdoc", "doc:scheme:");
+ GetDocumentReply tmp(doc);
+
+ EXPECT_EQUAL((size_t)43, serialize("GetDocumentReply", tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("GetDocumentReply", DocumentProtocol::REPLY_GETDOCUMENT, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ GetDocumentReply &ref = static_cast<GetDocumentReply&>(*obj);
+
+ EXPECT_EQUAL(string("testdoc"), ref.getDocument().getType().getName());
+ EXPECT_EQUAL(string("doc:scheme:"), ref.getDocument().getId().toString());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testMapVisitorReply()
+{
+ return tryVisitorReply("MapVisitorReply", DocumentProtocol::REPLY_MAPVISITOR);
+}
+
+bool
+Messages52Test::testSearchResultReply()
+{
+ return tryVisitorReply("SearchResultReply", DocumentProtocol::REPLY_SEARCHRESULT);
+}
+
+bool
+Messages52Test::testStatBucketReply()
+{
+ StatBucketReply msg;
+ msg.setResults("These are the votes of the Norwegian jury");
+
+ EXPECT_EQUAL(50u, serialize("StatBucketReply", msg));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("StatBucketReply", DocumentProtocol::REPLY_STATBUCKET, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ StatBucketReply &ref = static_cast<StatBucketReply&>(*obj);
+ EXPECT_EQUAL("These are the votes of the Norwegian jury", ref.getResults());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testVisitorInfoReply()
+{
+ return tryVisitorReply("VisitorInfoReply", DocumentProtocol::REPLY_VISITORINFO);
+}
+
+bool
+Messages52Test::testWrongDistributionReply()
+{
+ WrongDistributionReply tmp("distributor:3 storage:2");
+
+ serialize("WrongDistributionReply", tmp);
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("WrongDistributionReply", DocumentProtocol::REPLY_WRONGDISTRIBUTION, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ WrongDistributionReply &ref = static_cast<WrongDistributionReply&>(*obj);
+ EXPECT_EQUAL(string("distributor:3 storage:2"), ref.getSystemState());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testGetBucketListReply()
+{
+ GetBucketListReply reply;
+ reply.getBuckets().push_back(GetBucketListReply::BucketInfo(document::BucketId(16, 123), "foo"));
+ reply.getBuckets().push_back(GetBucketListReply::BucketInfo(document::BucketId(17, 1123), "bar"));
+ reply.getBuckets().push_back(GetBucketListReply::BucketInfo(document::BucketId(18, 11123), "zoink"));
+
+ EXPECT_EQUAL(56u, serialize("GetBucketListReply", reply));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("GetBucketListReply", DocumentProtocol::REPLY_GETBUCKETLIST, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ GetBucketListReply &ref = static_cast<GetBucketListReply&>(*obj);
+
+ EXPECT_EQUAL(ref.getBuckets()[0], GetBucketListReply::BucketInfo(document::BucketId(16, 123), "foo"));
+ EXPECT_EQUAL(ref.getBuckets()[1], GetBucketListReply::BucketInfo(document::BucketId(17, 1123), "bar"));
+ EXPECT_EQUAL(ref.getBuckets()[2], GetBucketListReply::BucketInfo(document::BucketId(18, 11123), "zoink"));
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testGetBucketStateReply()
+{
+ document::GlobalId foo = document::DocumentId("doc:scheme:foo").getGlobalId();
+ document::GlobalId bar = document::DocumentId("doc:scheme:bar").getGlobalId();
+
+ GetBucketStateReply reply;
+ reply.getBucketState().push_back(DocumentState(foo, 777, false));
+ reply.getBucketState().push_back(DocumentState(bar, 888, true));
+ EXPECT_EQUAL(53u, serialize("GetBucketStateReply", reply));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("GetBucketStateReply", DocumentProtocol::REPLY_GETBUCKETSTATE, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ GetBucketStateReply &ref = static_cast<GetBucketStateReply&>(*obj);
+
+ EXPECT_EQUAL(777u, ref.getBucketState()[0].getTimestamp());
+ EXPECT_EQUAL(foo, ref.getBucketState()[0].getGlobalId());
+ EXPECT_EQUAL(false, ref.getBucketState()[0].isRemoveEntry());
+ EXPECT_EQUAL(888u, ref.getBucketState()[1].getTimestamp());
+ EXPECT_EQUAL(bar, ref.getBucketState()[1].getGlobalId());
+ EXPECT_EQUAL(true, ref.getBucketState()[1].isRemoveEntry());
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::testEmptyBucketsReply()
+{
+ return tryVisitorReply("EmptyBucketsReply", DocumentProtocol::REPLY_EMPTYBUCKETS);
+}
+
+bool
+Messages52Test::testRemoveLocationReply()
+{
+ DocumentReply tmp(DocumentProtocol::REPLY_REMOVELOCATION);
+
+ EXPECT_EQUAL((uint32_t)5, serialize("RemoveLocationReply", tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize("RemoveLocationReply", DocumentProtocol::REPLY_REMOVELOCATION, lang);
+ EXPECT_TRUE(obj.get() != NULL);
+ }
+ return true;
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Utilities
+//
+////////////////////////////////////////////////////////////////////////////////
+
+bool
+Messages52Test::tryDocumentReply(const string &filename, uint32_t type)
+{
+ DocumentReply tmp(type);
+
+ EXPECT_EQUAL((uint32_t)5, serialize(filename, tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize(filename, type, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ DocumentReply *ref = dynamic_cast<DocumentReply*>(obj.get());
+ EXPECT_TRUE(ref != NULL);
+ }
+ }
+ return true;
+}
+
+bool
+Messages52Test::tryVisitorReply(const string &filename, uint32_t type)
+{
+ VisitorReply tmp(type);
+
+ EXPECT_EQUAL((uint32_t)5, serialize(filename, tmp));
+
+ for (uint32_t lang = 0; lang < NUM_LANGUAGES; ++lang) {
+ mbus::Routable::UP obj = deserialize(filename, type, lang);
+ if (EXPECT_TRUE(obj.get() != NULL)) {
+ VisitorReply *ref = dynamic_cast<VisitorReply*>(obj.get());
+ EXPECT_TRUE(ref != NULL);
+ }
+ }
+ return true;
+}
diff --git a/documentapi/src/tests/messages/messages52test.h b/documentapi/src/tests/messages/messages52test.h
index a663ae15fdc..6b019d77bde 100644
--- a/documentapi/src/tests/messages/messages52test.h
+++ b/documentapi/src/tests/messages/messages52test.h
@@ -2,22 +2,55 @@
// @author Vegard Sjonfjell
#pragma once
-#include "messages51test.h"
+#include "testbase.h"
-class Messages52Test : public Messages51Test {
+class Messages52Test : public TestBase {
protected:
- const vespalib::Version getVersion() const override { return vespalib::Version(5, 115, 0); }
+ const vespalib::Version getVersion() const override { return vespalib::Version(5, 115); }
+ bool shouldTestCoverage() const override { return true; }
+ bool tryDocumentReply(const string &filename, uint32_t type);
+ bool tryVisitorReply(const string &filename, uint32_t type);
+
+ static size_t serializedLength(const string & str) { return sizeof(int32_t) + str.size(); }
public:
Messages52Test();
+ bool testCreateVisitorMessage();
+ bool testCreateVisitorReply();
+ bool testDestroyVisitorMessage();
+ bool testDestroyVisitorReply();
+ bool testDocumentIgnoredReply();
+ bool testDocumentListMessage();
+ bool testDocumentListReply();
+ bool testDocumentSummaryMessage();
+ bool testDocumentSummaryReply();
+ bool testEmptyBucketsMessage();
+ bool testEmptyBucketsReply();
+ bool testGetBucketListMessage();
+ bool testGetBucketListReply();
+ bool testGetBucketStateMessage();
+ bool testGetBucketStateReply();
+ bool testGetDocumentMessage();
+ bool testGetDocumentReply();
+ bool testMapVisitorMessage();
+ bool testMapVisitorReply();
bool testPutDocumentMessage();
- bool testUpdateDocumentMessage();
+ bool testPutDocumentReply();
+ bool testQueryResultMessage();
+ bool testQueryResultReply();
bool testRemoveDocumentMessage();
-
-protected:
- static size_t serializedLength(const string & str) {
- return sizeof(int32_t) + str.size();
- }
+ bool testRemoveDocumentReply();
+ bool testRemoveLocationMessage();
+ bool testRemoveLocationReply();
+ bool testSearchResultMessage();
+ bool testSearchResultReply();
+ bool testStatBucketMessage();
+ bool testStatBucketReply();
+ bool testUpdateDocumentMessage();
+ bool testUpdateDocumentReply();
+ bool testVisitorInfoMessage();
+ bool testVisitorInfoReply();
+ bool testWrongDistributionReply();
};
diff --git a/documentapi/src/tests/routablefactory/routablefactory.cpp b/documentapi/src/tests/routablefactory/routablefactory.cpp
index 1abecdbf6c5..63d37de8c65 100644
--- a/documentapi/src/tests/routablefactory/routablefactory.cpp
+++ b/documentapi/src/tests/routablefactory/routablefactory.cpp
@@ -1,7 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/documentapi/messagebus/documentprotocol.h>
-#include <vespa/documentapi/messagebus/routablefactories51.h>
+#include <vespa/documentapi/messagebus/routablefactories52.h>
#include <vespa/messagebus/testlib/receptor.h>
#include <vespa/messagebus/testlib/slobrok.h>
#include <vespa/messagebus/testlib/testserver.h>
@@ -48,7 +48,7 @@ public:
}
};
-class MyMessageFactory : public RoutableFactories51::DocumentMessageFactory {
+class MyMessageFactory : public RoutableFactories52::DocumentMessageFactory {
protected:
DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override {
(void)buf;
@@ -62,7 +62,7 @@ protected:
}
};
-class MyReplyFactory : public RoutableFactories51::DocumentReplyFactory {
+class MyReplyFactory : public RoutableFactories52::DocumentReplyFactory {
protected:
DocumentReply::UP doDecode(document::ByteBuffer &buf) const override {
(void)buf;
diff --git a/documentapi/src/vespa/documentapi/messagebus/CMakeLists.txt b/documentapi/src/vespa/documentapi/messagebus/CMakeLists.txt
index 1df761b8af5..6f65b3c67a9 100644
--- a/documentapi/src/vespa/documentapi/messagebus/CMakeLists.txt
+++ b/documentapi/src/vespa/documentapi/messagebus/CMakeLists.txt
@@ -3,10 +3,6 @@ vespa_add_library(documentapi_documentapimessagebus OBJECT
SOURCES
documentprotocol.cpp
replymerger.cpp
- routablefactories41.cpp
- routablefactories42.cpp
- routablefactories50.cpp
- routablefactories51.cpp
routablefactories52.cpp
routablefactories60.cpp
routablerepository.cpp
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories41.cpp b/documentapi/src/vespa/documentapi/messagebus/routablefactories41.cpp
deleted file mode 100644
index a77f793ae89..00000000000
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories41.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "routablefactories41.h"
-#include <vespa/document/document.h>
-#include <vespa/documentapi/documentapi.h>
-#include <vespa/vespalib/objects/nbostream.h>
-
-using vespalib::nbostream;
-
-namespace documentapi {
-
-string
-RoutableFactories41::decodeString(document::ByteBuffer &in)
-{
- int32_t len = decodeInt(in);
- string ret = string(in.getBufferAtPos(), len);
- in.incPos(len);
- return ret;
-}
-
-bool
-RoutableFactories41::decodeBoolean(document::ByteBuffer &in)
-{
- char ret;
- in.getBytes(&ret, 1);
- return (bool)ret;
-}
-
-int32_t
-RoutableFactories41::decodeInt(document::ByteBuffer &in)
-{
- int32_t ret;
- in.getIntNetwork(ret);
- return ret;
-}
-
-int64_t
-RoutableFactories41::decodeLong(document::ByteBuffer &in)
-{
- int64_t ret;
- in.getLongNetwork(ret);
- return ret;
-}
-
-document::DocumentId
-RoutableFactories41::decodeDocumentId(document::ByteBuffer &in)
-{
- nbostream stream(in.getBufferAtPos(), in.getRemaining());
- document::DocumentId ret(stream);
- in.incPos(stream.rp());
- return ret;
-}
-
-void
-RoutableFactories41::encodeDocumentId(const document::DocumentId &id, vespalib::GrowableByteBuffer &out)
-{
- string str = id.toString();
- out.putBytes(str.c_str(), str.size() + 1);
-}
-
-}
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories41.h b/documentapi/src/vespa/documentapi/messagebus/routablefactories41.h
deleted file mode 100644
index aecf0f73892..00000000000
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories41.h
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include <vespa/documentapi/messagebus/messages/feedmessage.h>
-#include <vespa/documentapi/messagebus/messages/feedreply.h>
-#include <vespa/messagebus/routable.h>
-#include <vespa/messagebus/blob.h>
-#include <vespa/messagebus/blobref.h>
-#include <vespa/document/base/documentid.h>
-#include <vespa/document/util/bytebuffer.h>
-#include <vespa/vespalib/util/growablebytebuffer.h>
-
-namespace documentapi {
-
-/**
- * This class encapsulates all the {@link RoutableFactory} classes needed to implement factories for the document
- * routable. When adding new factories to this class, please KEEP THE THEM ORDERED alphabetically like they are now.
- */
-class RoutableFactories41 {
-private:
- RoutableFactories41() { /* abstract */ }
-
-public:
-
- ///////////////////////////////////////////////////////////////////////////
- //
- // Utilities
- //
- ///////////////////////////////////////////////////////////////////////////
-
- /**
- * This is a complement for the vespalib::GrowableByteBuffer.putString() method.
- *
- * @param in The byte buffer to read from.
- * @return The decoded string.
- */
- static string decodeString(document::ByteBuffer &in);
-
- /**
- * This is a complement for the vespalib::GrowableByteBuffer.putBoolean() method.
- *
- * @param in The byte buffer to read from.
- * @return The decoded bool.
- */
- static bool decodeBoolean(document::ByteBuffer &in);
-
- /**
- * Convenience method to decode a 32-bit int from the given byte buffer.
- *
- * @param in The byte buffer to read from.
- * @return The decoded int.
- */
- static int32_t decodeInt(document::ByteBuffer &in);
-
- /**
- * Convenience method to decode a 64-bit int from the given byte buffer.
- *
- * @param in The byte buffer to read from.
- * @return The decoded int.
- */
- static int64_t decodeLong(document::ByteBuffer &in);
-
- /**
- * Convenience method to decode a document id from the given byte buffer.
- *
- * @param in The byte buffer to read from.
- * @return The decoded document id.
- */
- static document::DocumentId decodeDocumentId(document::ByteBuffer &in);
-
- /**
- * Convenience method to encode a document id to the given byte buffer.
- *
- * @param id The document id to encode.
- * @param out The byte buffer to write to.
- */
- static void encodeDocumentId(const document::DocumentId &id, vespalib::GrowableByteBuffer &out);
-};
-
-}
-
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories42.cpp b/documentapi/src/vespa/documentapi/messagebus/routablefactories42.cpp
deleted file mode 100644
index 20f1f241900..00000000000
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories42.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "routablefactories42.h"
-#include <vespa/document/document.h>
-#include <vespa/documentapi/documentapi.h>
-#include <vespa/vespalib/objects/nbostream.h>
-
-using vespalib::nbostream;
-
-namespace documentapi {
-
-}
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories42.h b/documentapi/src/vespa/documentapi/messagebus/routablefactories42.h
deleted file mode 100644
index ede108f5157..00000000000
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories42.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include "routablefactories41.h"
-
-namespace document { class DocumentTypeRepo; }
-
-namespace documentapi {
-/**
- * This class encapsulates all the {@link RoutableFactory} classes needed to implement factories for the document
- * routable. When adding new factories to this class, please KEEP THE THEM ORDERED alphabetically like they are now.
- */
-class RoutableFactories42 {
-private:
- RoutableFactories42() { /* abstract */ }
- typedef RoutableFactories41 RF41;
-
-public:
-
- ///////////////////////////////////////////////////////////////////////////
- //
- // Utilities
- //
- ///////////////////////////////////////////////////////////////////////////
-
- /**
- * This is a complement for the vespalib::GrowableByteBuffer.putString() method.
- *
- * @param in The byte buffer to read from.
- * @return The decoded string.
- */
- static string decodeString(document::ByteBuffer &in)
- { return RF41::decodeString(in); }
-
- /**
- * This is a complement for the vespalib::GrowableByteBuffer.putBoolean() method.
- *
- * @param in The byte buffer to read from.
- * @return The decoded bool.
- */
- static bool decodeBoolean(document::ByteBuffer &in)
- { return RF41::decodeBoolean(in); }
-
- /**
- * Convenience method to decode a 32-bit int from the given byte buffer.
- *
- * @param in The byte buffer to read from.
- * @return The decoded int.
- */
- static int32_t decodeInt(document::ByteBuffer &in)
- { return RF41::decodeInt(in); }
-
- /**
- * Convenience method to decode a 64-bit int from the given byte buffer.
- *
- * @param in The byte buffer to read from.
- * @return The decoded int.
- */
- static int64_t decodeLong(document::ByteBuffer &in)
- { return RF41::decodeLong(in); }
-
-
- /**
- * Convenience method to decode a document id from the given byte buffer.
- *
- * @param in The byte buffer to read from.
- * @return The decoded document id.
- */
- static document::DocumentId decodeDocumentId(document::ByteBuffer &in)
- { return RF41::decodeDocumentId(in); }
-
- /**
- * Convenience method to encode a document id to the given byte buffer.
- *
- * @param id The document id to encode.
- * @param out The byte buffer to write to.
- */
- static void encodeDocumentId(const document::DocumentId &id,
- vespalib::GrowableByteBuffer &out)
- { return RF41::encodeDocumentId(id, out); }
-};
-
-}
-
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories50.cpp b/documentapi/src/vespa/documentapi/messagebus/routablefactories50.cpp
deleted file mode 100644
index 120ee1facd0..00000000000
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories50.cpp
+++ /dev/null
@@ -1,903 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#include "routablefactories50.h"
-#include <vespa/document/bucket/bucketidfactory.h>
-#include <vespa/document/bucket/fixed_bucket_spaces.h>
-#include <vespa/document/select/parser.h>
-#include <vespa/document/update/documentupdate.h>
-#include <vespa/documentapi/documentapi.h>
-#include <vespa/documentapi/loadtypes/loadtypeset.h>
-#include <vespa/vespalib/objects/nbostream.h>
-
-using document::FixedBucketSpaces;
-using vespalib::nbostream;
-using std::make_unique;
-using std::make_shared;
-
-namespace documentapi {
-
-bool
-RoutableFactories50::DocumentMessageFactory::encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const
-{
- const DocumentMessage &msg = static_cast<const DocumentMessage&>(obj);
- out.putByte(msg.getPriority());
- out.putInt(msg.getLoadType().getId());
- return doEncode(msg, out);
-}
-
-mbus::Routable::UP
-RoutableFactories50::DocumentMessageFactory::decode(document::ByteBuffer &in, const LoadTypeSet& loadTypes) const
-{
- uint8_t pri;
- in.getByte(pri);
- uint32_t loadClass = decodeInt(in);
-
- DocumentMessage::UP msg = doDecode(in);
- if (msg) {
- msg->setPriority((Priority::Value)pri);
- msg->setLoadType(loadTypes[loadClass]);
- }
-
- return mbus::Routable::UP(msg.release());
-}
-
-bool
-RoutableFactories50::DocumentReplyFactory::encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const
-{
- const DocumentReply &msg = static_cast<const DocumentReply&>(obj);
- out.putByte(msg.getPriority());
- return doEncode(msg, out);
-}
-
-mbus::Routable::UP
-RoutableFactories50::DocumentReplyFactory::decode(document::ByteBuffer &in, const LoadTypeSet&) const
-{
- uint8_t pri;
- in.getByte(pri);
- DocumentReply::UP reply = doDecode(in);
- if (reply) {
- reply->setPriority((Priority::Value)pri);
- }
- return mbus::Routable::UP(reply.release());
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// Factories
-//
-////////////////////////////////////////////////////////////////////////////////
-
-DocumentMessage::UP
-RoutableFactories50::CreateVisitorMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<CreateVisitorMessage>();
-
- msg->setLibraryName(decodeString(buf));
- msg->setInstanceId(decodeString(buf));
- msg->setControlDestination(decodeString(buf));
- msg->setDataDestination(decodeString(buf));
- msg->setDocumentSelection(decodeString(buf));
- msg->setMaximumPendingReplyCount(decodeInt(buf));
-
- int32_t len = decodeInt(buf);
- for (int32_t i = 0; i < len; i++) {
- int64_t val;
- buf.getLong(val); // NOT using getLongNetwork
- msg->getBuckets().push_back(document::BucketId(val));
- }
-
- msg->setFromTimestamp(decodeLong(buf));
- msg->setToTimestamp(decodeLong(buf));
- msg->setVisitRemoves(decodeBoolean(buf));
- msg->setVisitHeadersOnly(decodeBoolean(buf));
- msg->setVisitInconsistentBuckets(decodeBoolean(buf));
- msg->getParameters().deserialize(_repo, buf);
- msg->setVisitorDispatcherVersion(50);
- msg->setVisitorOrdering((document::OrderingSpecification::Order)decodeInt(buf));
- msg->setMaxBucketsPerVisitor(decodeInt(buf));
-
- return msg;
-}
-
-bool
-RoutableFactories50::CreateVisitorMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const CreateVisitorMessage &msg = static_cast<const CreateVisitorMessage&>(obj);
-
- buf.putString(msg.getLibraryName());
- buf.putString(msg.getInstanceId());
- buf.putString(msg.getControlDestination());
- buf.putString(msg.getDataDestination());
- buf.putString(msg.getDocumentSelection());
- buf.putInt(msg.getMaximumPendingReplyCount());
- buf.putInt(msg.getBuckets().size());
-
- for (const auto & bucketId : msg.getBuckets()) {
- uint64_t val = bucketId.getRawId();
- buf.putBytes((const char*)&val, 8);
- }
-
- buf.putLong(msg.getFromTimestamp());
- buf.putLong(msg.getToTimestamp());
- buf.putBoolean(msg.visitRemoves());
- buf.putBoolean(msg.visitHeadersOnly());
- buf.putBoolean(msg.visitInconsistentBuckets());
-
- int len = msg.getParameters().getSerializedSize();
- char *tmp = buf.allocate(len);
- document::ByteBuffer dbuf(tmp, len);
- msg.getParameters().serialize(dbuf);
-
- buf.putInt(msg.getVisitorOrdering());
- buf.putInt(msg.getMaxBucketsPerVisitor());
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::CreateVisitorReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = std::make_unique<CreateVisitorReply>(DocumentProtocol::REPLY_CREATEVISITOR);
- reply->setLastBucket(document::BucketId((uint64_t)decodeLong(buf)));
- vdslib::VisitorStatistics vs;
- vs.setBucketsVisited(decodeInt(buf));
- vs.setDocumentsVisited(decodeLong(buf));
- vs.setBytesVisited(decodeLong(buf));
- vs.setDocumentsReturned(decodeLong(buf));
- vs.setBytesReturned(decodeLong(buf));
- vs.setSecondPassDocumentsReturned(decodeLong(buf));
- vs.setSecondPassBytesReturned(decodeLong(buf));
- reply->setVisitorStatistics(vs);
-
- return reply;
-}
-
-bool
-RoutableFactories50::CreateVisitorReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const CreateVisitorReply &reply = static_cast<const CreateVisitorReply&>(obj);
- buf.putLong(reply.getLastBucket().getRawId());
- buf.putInt(reply.getVisitorStatistics().getBucketsVisited());
- buf.putLong(reply.getVisitorStatistics().getDocumentsVisited());
- buf.putLong(reply.getVisitorStatistics().getBytesVisited());
- buf.putLong(reply.getVisitorStatistics().getDocumentsReturned());
- buf.putLong(reply.getVisitorStatistics().getBytesReturned());
- buf.putLong(reply.getVisitorStatistics().getSecondPassDocumentsReturned());
- buf.putLong(reply.getVisitorStatistics().getSecondPassBytesReturned());
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::DestroyVisitorMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<DestroyVisitorMessage>();
- msg->setInstanceId(decodeString(buf));
- return msg;
-}
-
-bool
-RoutableFactories50::DestroyVisitorMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const DestroyVisitorMessage &msg = static_cast<const DestroyVisitorMessage&>(obj);
- buf.putString(msg.getInstanceId());
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::DestroyVisitorReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_DESTROYVISITOR);
-}
-
-bool
-RoutableFactories50::DestroyVisitorReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::DocumentListMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<DocumentListMessage>();
- msg->setBucketId(document::BucketId(decodeLong(buf)));
-
- int32_t len = decodeInt(buf);
- for (int32_t i = 0; i < len; i++) {
- DocumentListMessage::Entry entry(_repo, buf);
- msg->getDocuments().push_back(entry);
- }
-
- return msg;
-}
-
-bool
-RoutableFactories50::DocumentListMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const DocumentListMessage &msg = static_cast<const DocumentListMessage&>(obj);
-
- buf.putLong(msg.getBucketId().getRawId());
- buf.putInt(msg.getDocuments().size());
- for (const auto & document : msg.getDocuments()) {
- int len = document.getSerializedSize();
- char *tmp = buf.allocate(len);
- document::ByteBuffer dbuf(tmp, len);
- document.serialize(dbuf);
- }
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::DocumentListReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_DOCUMENTLIST);
-}
-
-bool
-RoutableFactories50::DocumentListReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::DocumentSummaryMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<DocumentSummaryMessage>();
-
- msg->deserialize(buf);
-
- return msg;
-}
-
-bool
-RoutableFactories50::DocumentSummaryMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const DocumentSummaryMessage &msg = static_cast<const DocumentSummaryMessage&>(obj);
-
- int32_t len = msg.getSerializedSize();
- char *tmp = buf.allocate(len);
- document::ByteBuffer dbuf(tmp, len);
- msg.serialize(dbuf);
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::DocumentSummaryReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_DOCUMENTSUMMARY);
-}
-
-bool
-RoutableFactories50::DocumentSummaryReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::EmptyBucketsMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<EmptyBucketsMessage>();
-
- int32_t len = decodeInt(buf);
- std::vector<document::BucketId> buckets(len);
- for (int32_t i = 0; i < len; ++i) {
- buckets[i] = document::BucketId(decodeLong(buf));
- }
- msg->getBucketIds().swap(buckets);
-
- return msg;
-}
-
-bool
-RoutableFactories50::EmptyBucketsMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const EmptyBucketsMessage &msg = static_cast<const EmptyBucketsMessage&>(obj);
-
- buf.putInt(msg.getBucketIds().size());
- for (const auto & bucketId : msg.getBucketIds()) {
- buf.putLong(bucketId.getRawId());
- }
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::EmptyBucketsReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_EMPTYBUCKETS);
-}
-
-bool
-RoutableFactories50::EmptyBucketsReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return true;
-}
-
-bool RoutableFactories50::GetBucketListMessageFactory::encodeBucketSpace(vespalib::stringref bucketSpace,
- vespalib::GrowableByteBuffer& ) const
-{
- return (bucketSpace == FixedBucketSpaces::default_space_name());
-}
-
-string RoutableFactories50::GetBucketListMessageFactory::decodeBucketSpace(document::ByteBuffer&) const {
- return FixedBucketSpaces::default_space_name();
-}
-
-DocumentMessage::UP
-RoutableFactories50::GetBucketListMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- document::BucketId bucketId(decodeLong(buf));
- auto msg = std::make_unique<GetBucketListMessage>(bucketId);
- msg->setBucketSpace(decodeBucketSpace(buf));
- return msg;
-}
-
-bool
-RoutableFactories50::GetBucketListMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const GetBucketListMessage &msg = static_cast<const GetBucketListMessage&>(obj);
- buf.putLong(msg.getBucketId().getRawId());
- return encodeBucketSpace(msg.getBucketSpace(), buf);
-}
-
-DocumentReply::UP
-RoutableFactories50::GetBucketListReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = std::make_unique<GetBucketListReply>();
-
- int32_t len = decodeInt(buf);
- reply->getBuckets().reserve(len);
- for (int32_t i = 0; i < len; i++) {
- GetBucketListReply::BucketInfo info;
- info._bucket = document::BucketId((uint64_t)decodeLong(buf));
- info._bucketInformation = decodeString(buf);
- reply->getBuckets().push_back(info);
- }
-
- return reply;
-}
-
-bool
-RoutableFactories50::GetBucketListReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const GetBucketListReply &reply = static_cast<const GetBucketListReply&>(obj);
-
- const std::vector<GetBucketListReply::BucketInfo> &buckets = reply.getBuckets();
- buf.putInt(buckets.size());
- for (const auto & bucketInfo : buckets) {
- buf.putLong(bucketInfo._bucket.getRawId());
- buf.putString(bucketInfo._bucketInformation);
- }
-
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::GetBucketStateMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<GetBucketStateMessage>();
-
- msg->setBucketId(document::BucketId((uint64_t)decodeLong(buf)));
-
- return msg;
-}
-
-bool
-RoutableFactories50::GetBucketStateMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const GetBucketStateMessage &msg = static_cast<const GetBucketStateMessage&>(obj);
- buf.putLong(msg.getBucketId().getRawId());
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::GetBucketStateReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = std::make_unique<GetBucketStateReply>();
-
- int32_t len = decodeInt(buf);
- reply->getBucketState().reserve(len);
- for (int32_t i = 0; i < len; i++) {
- reply->getBucketState().emplace_back(buf);
- }
-
- return reply;
-}
-
-bool
-RoutableFactories50::GetBucketStateReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const GetBucketStateReply &reply = static_cast<const GetBucketStateReply&>(obj);
-
- buf.putInt(reply.getBucketState().size());
- for (const auto & state : reply.getBucketState()) {
- state.serialize(buf);
- }
-
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::GetDocumentMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<GetDocumentMessage>();
- msg->setDocumentId(decodeDocumentId(buf));
- msg->setFlags(decodeInt(buf));
-
- return msg;
-}
-
-bool
-RoutableFactories50::GetDocumentMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const GetDocumentMessage &msg = static_cast<const GetDocumentMessage&>(obj);
-
- encodeDocumentId(msg.getDocumentId(), buf);
- buf.putInt(msg.getFlags());
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::GetDocumentReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = std::make_unique<GetDocumentReply>();
-
- bool hasDocument = decodeBoolean(buf);
- document::Document * document = nullptr;
- if (hasDocument) {
- auto doc = std::make_shared<document::Document>(_repo, buf);
- document = doc.get();
- reply->setDocument(std::move(doc));
- }
- int64_t lastModified = decodeLong(buf);
- reply->setLastModified(lastModified);
- if (hasDocument) {
- document->setLastModified(lastModified);
- }
-
- return reply;
-}
-
-bool
-RoutableFactories50::GetDocumentReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const GetDocumentReply &reply = static_cast<const GetDocumentReply&>(obj);
-
- buf.putByte(reply.hasDocument() ? 1 : 0);
- if (reply.hasDocument()) {
- nbostream stream;
- reply.getDocument().serialize(stream);
- buf.putBytes(stream.peek(), stream.size());
- }
- buf.putLong(reply.getLastModified());
-
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::MapVisitorMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<MapVisitorMessage>();
- msg->getData().deserialize(_repo, buf);
- return msg;
-}
-
-bool
-RoutableFactories50::MapVisitorMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const MapVisitorMessage &msg = static_cast<const MapVisitorMessage&>(obj);
-
- int32_t len = msg.getData().getSerializedSize();
- char *tmp = buf.allocate(len);
- document::ByteBuffer dbuf(tmp, len);
- msg.getData().serialize(dbuf);
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::MapVisitorReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_MAPVISITOR);
-}
-
-bool
-RoutableFactories50::MapVisitorReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return true;
-}
-
-void
-RoutableFactories50::PutDocumentMessageFactory::decodeInto(PutDocumentMessage & msg, document::ByteBuffer & buf) const {
- msg.setDocument(make_shared<document::Document>(_repo, buf));
- msg.setTimestamp(static_cast<uint64_t>(decodeLong(buf)));
-}
-
-bool
-RoutableFactories50::PutDocumentMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- auto & msg = static_cast<const PutDocumentMessage &>(obj);
- nbostream stream;
-
- msg.getDocument().serialize(stream);
- buf.putBytes(stream.peek(), stream.size());
- buf.putLong(static_cast<int64_t>(msg.getTimestamp()));
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::PutDocumentReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = make_unique<WriteDocumentReply>(DocumentProtocol::REPLY_PUTDOCUMENT);
- reply->setHighestModificationTimestamp(decodeLong(buf));
-
- // Doing an explicit move here to force converting result to an rvalue.
- // This is done automatically in GCC >= 5.
- return std::move(reply);
-}
-
-bool
-RoutableFactories50::PutDocumentReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const WriteDocumentReply& reply = (const WriteDocumentReply&)obj;
- buf.putLong(reply.getHighestModificationTimestamp());
- return true;
-}
-
-void
-RoutableFactories50::RemoveDocumentMessageFactory::decodeInto(RemoveDocumentMessage & msg, document::ByteBuffer & buf) const {
- msg.setDocumentId(decodeDocumentId(buf));
-}
-
-bool
-RoutableFactories50::RemoveDocumentMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const RemoveDocumentMessage &msg = static_cast<const RemoveDocumentMessage&>(obj);
- encodeDocumentId(msg.getDocumentId(), buf);
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::RemoveDocumentReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = std::make_unique<RemoveDocumentReply>();
- reply->setWasFound(decodeBoolean(buf));
- reply->setHighestModificationTimestamp(decodeLong(buf));
- return reply;
-}
-
-bool
-RoutableFactories50::RemoveDocumentReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const RemoveDocumentReply &reply = static_cast<const RemoveDocumentReply&>(obj);
- buf.putBoolean(reply.getWasFound());
- buf.putLong(reply.getHighestModificationTimestamp());
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::RemoveLocationMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- string selection = decodeString(buf);
-
- document::BucketIdFactory factory;
- document::select::Parser parser(_repo, factory);
-
- auto msg = std::make_unique<RemoveLocationMessage>(factory, parser, selection);
- // FIXME bucket space not part of wire format, implicitly limiting to only default space for now.
- msg->setBucketSpace(document::FixedBucketSpaces::default_space_name());
- return msg;
-}
-
-bool
-RoutableFactories50::RemoveLocationMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const RemoveLocationMessage &msg = static_cast<const RemoveLocationMessage&>(obj);
- buf.putString(msg.getDocumentSelection());
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::RemoveLocationReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return std::make_unique<DocumentReply>(DocumentProtocol::REPLY_REMOVELOCATION);
-}
-
-bool
-RoutableFactories50::RemoveLocationReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::SearchResultMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<SearchResultMessage>();
- msg->deserialize(buf);
- return msg;
-}
-
-bool
-RoutableFactories50::SearchResultMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const SearchResultMessage &msg = static_cast<const SearchResultMessage&>(obj);
-
- int len = msg.getSerializedSize();
- char *tmp = buf.allocate(len);
- document::ByteBuffer dbuf(tmp, len);
- msg.serialize(dbuf);
-
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::QueryResultMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<QueryResultMessage>();
- msg->getSearchResult().deserialize(buf);
- msg->getDocumentSummary().deserialize(buf);
-
- return msg;
-}
-
-bool
-RoutableFactories50::QueryResultMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const QueryResultMessage &msg = static_cast<const QueryResultMessage&>(obj);
-
- int len = msg.getSearchResult().getSerializedSize() + msg.getDocumentSummary().getSerializedSize();
- char *tmp = buf.allocate(len);
- document::ByteBuffer dbuf(tmp, len);
- msg.getSearchResult().serialize(dbuf);
- msg.getDocumentSummary().serialize(dbuf);
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::SearchResultReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_SEARCHRESULT);
-}
-
-bool
-RoutableFactories50::SearchResultReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::QueryResultReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_QUERYRESULT);
-}
-
-bool
-RoutableFactories50::QueryResultReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return true;
-}
-
-bool RoutableFactories50::StatBucketMessageFactory::encodeBucketSpace(vespalib::stringref bucketSpace,
- vespalib::GrowableByteBuffer& ) const
-{
- return (bucketSpace == FixedBucketSpaces::default_space_name());
-}
-
-string RoutableFactories50::StatBucketMessageFactory::decodeBucketSpace(document::ByteBuffer&) const {
- return FixedBucketSpaces::default_space_name();
-}
-
-DocumentMessage::UP
-RoutableFactories50::StatBucketMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<StatBucketMessage>();
-
- msg->setBucketId(document::BucketId(decodeLong(buf)));
- msg->setDocumentSelection(decodeString(buf));
- msg->setBucketSpace(decodeBucketSpace(buf));
-
- return msg;
-}
-
-bool
-RoutableFactories50::StatBucketMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const StatBucketMessage &msg = static_cast<const StatBucketMessage&>(obj);
-
- buf.putLong(msg.getBucketId().getRawId());
- buf.putString(msg.getDocumentSelection());
- return encodeBucketSpace(msg.getBucketSpace(), buf);
-}
-
-DocumentReply::UP
-RoutableFactories50::StatBucketReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = std::make_unique<StatBucketReply>();
- reply->setResults(decodeString(buf));
- return reply;
-}
-
-bool
-RoutableFactories50::StatBucketReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const StatBucketReply &reply = static_cast<const StatBucketReply&>(obj);
- buf.putString(reply.getResults());
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::StatDocumentMessageFactory::doDecode(document::ByteBuffer &) const
-{
- return DocumentMessage::UP(); // TODO: remove message type
-}
-
-bool
-RoutableFactories50::StatDocumentMessageFactory::doEncode(const DocumentMessage &, vespalib::GrowableByteBuffer &) const
-{
- return false;
-}
-
-DocumentReply::UP
-RoutableFactories50::StatDocumentReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return DocumentReply::UP(); // TODO: remove reply type
-}
-
-bool
-RoutableFactories50::StatDocumentReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return false;
-}
-
-void
-RoutableFactories50::UpdateDocumentMessageFactory::decodeInto(UpdateDocumentMessage & msg, document::ByteBuffer & buf) const {
- msg.setDocumentUpdate(document::DocumentUpdate::createHEAD(_repo, buf));
- msg.setOldTimestamp(static_cast<uint64_t>(decodeLong(buf)));
- msg.setNewTimestamp(static_cast<uint64_t>(decodeLong(buf)));
-}
-
-bool
-RoutableFactories50::UpdateDocumentMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const UpdateDocumentMessage &msg = static_cast<const UpdateDocumentMessage&>(obj);
-
- vespalib::nbostream stream;
- msg.getDocumentUpdate().serializeHEAD(stream);
- buf.putBytes(stream.peek(), stream.size());
- buf.putLong((int64_t)msg.getOldTimestamp());
- buf.putLong((int64_t)msg.getNewTimestamp());
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::UpdateDocumentReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = std::make_unique<UpdateDocumentReply>();
- reply->setWasFound(decodeBoolean(buf));
- reply->setHighestModificationTimestamp(decodeLong(buf));
- return reply;
-}
-
-bool
-RoutableFactories50::UpdateDocumentReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const UpdateDocumentReply &reply = static_cast<const UpdateDocumentReply&>(obj);
- buf.putBoolean(reply.getWasFound());
- buf.putLong(reply.getHighestModificationTimestamp());
- return true;
-}
-
-DocumentMessage::UP
-RoutableFactories50::VisitorInfoMessageFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto msg = std::make_unique<VisitorInfoMessage>();
-
- int32_t len = decodeInt(buf);
- msg->getFinishedBuckets().reserve(len);
- for (int32_t i = 0; i < len; i++) {
- int64_t val;
- buf.getLong(val); // NOT using getLongNetwork
- msg->getFinishedBuckets().emplace_back(val);
- }
- msg->setErrorMessage(decodeString(buf));
-
- return msg;
-}
-
-bool
-RoutableFactories50::VisitorInfoMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const VisitorInfoMessage &msg = static_cast<const VisitorInfoMessage&>(obj);
-
- buf.putInt(msg.getFinishedBuckets().size());
- for (const auto & bucketId : msg.getFinishedBuckets()) {
- uint64_t val = bucketId.getRawId();
- buf.putBytes((const char*)&val, 8);
- }
- buf.putString(msg.getErrorMessage());
-
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::VisitorInfoReplyFactory::doDecode(document::ByteBuffer &) const
-{
- return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_VISITORINFO);
-}
-
-bool
-RoutableFactories50::VisitorInfoReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
-{
- return true;
-}
-
-DocumentReply::UP
-RoutableFactories50::WrongDistributionReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = std::make_unique<WrongDistributionReply>();
- reply->setSystemState(decodeString(buf));
- return reply;
-}
-
-bool
-RoutableFactories50::WrongDistributionReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const WrongDistributionReply &reply = static_cast<const WrongDistributionReply&>(obj);
- buf.putString(reply.getSystemState());
- return true;
-}
-
-void
-RoutableFactories50::FeedMessageFactory::myDecode(FeedMessage &msg, document::ByteBuffer &buf) const
-{
- msg.setName(decodeString(buf));
- msg.setGeneration(decodeInt(buf));
- msg.setIncrement(decodeInt(buf));
-}
-
-void
-RoutableFactories50::FeedMessageFactory::myEncode(const FeedMessage &msg, vespalib::GrowableByteBuffer &buf) const
-{
- buf.putString(msg.getName());
- buf.putInt(msg.getGeneration());
- buf.putInt(msg.getIncrement());
-}
-
-DocumentReply::UP
-RoutableFactories50::FeedReplyFactory::doDecode(document::ByteBuffer &buf) const
-{
- auto reply = std::make_unique<FeedReply>(getType());
-
- std::vector<FeedAnswer> &answers = reply->getFeedAnswers();
- int32_t len = decodeInt(buf);
- answers.reserve(len);
- for (int32_t i = 0; i < len; ++i) {
- int32_t typeCode = decodeInt(buf);
- int32_t wantedIncrement = decodeInt(buf);
- string recipient = decodeString(buf);
- string moreInfo = decodeString(buf);
- answers.emplace_back(typeCode, wantedIncrement, recipient, moreInfo);
- }
- return reply;
-}
-
-bool
-RoutableFactories50::FeedReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
-{
- const FeedReply &reply = static_cast<const FeedReply&>(obj);
- buf.putInt(reply.getFeedAnswers().size());
- for (const auto & answer : reply.getFeedAnswers()) {
- buf.putInt(answer.getAnswerCode());
- buf.putInt(answer.getWantedIncrement());
- buf.putString(answer.getRecipient());
- buf.putString(answer.getMoreInfo());
- }
- return true;
-}
-
-}
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories50.h b/documentapi/src/vespa/documentapi/messagebus/routablefactories50.h
deleted file mode 100644
index f96b9641800..00000000000
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories50.h
+++ /dev/null
@@ -1,445 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#pragma once
-
-#include "routablefactories42.h"
-#include "iroutablefactory.h"
-#include <vespa/documentapi/messagebus/messages/putdocumentmessage.h>
-#include <vespa/documentapi/messagebus/messages/removedocumentmessage.h>
-#include <vespa/documentapi/messagebus/messages/updatedocumentmessage.h>
-
-namespace document { class DocumentTypeRepo; }
-
-/**
- * Utility class for invoking setApproxSize on a DocumentMessage with the delta
- * between the read position of a ByteBuffer at construction and destruction
- * time. The assumption being made is that the in-memory footprint of a message
- * is reasonably close to its wire-serialized form.
- */
-class ScopedApproxSizeSetter {
-public:
- ScopedApproxSizeSetter(documentapi::DocumentMessage& msg,
- const document::ByteBuffer& buf)
- : _msg(msg),
- _buf(buf),
- _posBefore(_buf.getPos())
- {
- }
-
- ~ScopedApproxSizeSetter() {
- _msg.setApproxSize(static_cast<uint32_t>(_buf.getPos() - _posBefore));
- }
-
-private:
- documentapi::DocumentMessage& _msg;
- const document::ByteBuffer& _buf;
- const size_t _posBefore;
-};
-
-namespace documentapi {
-
-template<typename MessageType, typename FactoryType>
-DocumentMessage::UP
-decodeMessage(const FactoryType * self, document::ByteBuffer & buf) {
- auto msg = std::make_unique<MessageType>();
- ScopedApproxSizeSetter sizeSetter(*msg, buf);
- self->decodeInto(*msg, buf);
- return msg;
-}
-
-/**
- * This class encapsulates all the {@link RoutableFactory} classes needed to implement factories for the document
- * routable. When adding new factories to this class, please KEEP THE THEM ORDERED alphabetically like they are now.
- */
-class RoutableFactories50 {
-public:
- RoutableFactories50() = delete;
-
- /**
- * Implements the shared factory logic required for {@link DocumentMessage} objects, and it offers a more
- * convenient interface for implementing {@link RoutableFactory}.
- */
- class DocumentMessageFactory : public IRoutableFactory {
- protected:
- /**
- * This method encodes the given message into the given byte buffer. You are guaranteed to only receive messages of
- * the type that this factory was registered for.
- *
- * This method is NOT exception safe. Return false to signal failure.
- *
- * @param msg The message to encode.
- * @param buf The byte buffer to write to.
- * @return True if the message was encoded.
- */
- virtual bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const = 0;
-
- /**
- * This method decodes a message from the given byte buffer. You are guaranteed to only receive byte buffers
- * generated by a previous call to {@link #doEncode(DocumentMessage, GrowableByteBuffer)}.
- *
- * This method is NOT exception safe. Return null to signal failure.
- *
- * @param buf The byte buffer to read from.
- * @return The decoded message.
- */
- virtual DocumentMessage::UP doDecode(document::ByteBuffer &buf) const = 0;
-
- public:
- /**
- * Convenience typedefs.
- */
- typedef std::unique_ptr<IRoutableFactory> UP;
- typedef std::shared_ptr<IRoutableFactory> SP;
- bool encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const override;
- mbus::Routable::UP decode(document::ByteBuffer &in, const LoadTypeSet& loadTypes) const override;
- };
-
- /**
- * Implements the shared factory logic required for {@link DocumentReply} objects, and it offers a more
- * convenient interface for implementing {@link RoutableFactory}.
- */
- class DocumentReplyFactory : public IRoutableFactory {
- protected:
- /**
- * This method encodes the given reply into the given byte buffer. You are guaranteed to only receive
- * replies of the type that this factory was registered for.
- *
- * This method is NOT exception safe. Return false to signal failure.
- *
- * @param reply The reply to encode.
- * @param buf The byte buffer to write to.
- * @return True if the message was encoded.
- */
- virtual bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const = 0;
-
- /**
- * This method decodes a reply from the given byte buffer. You are guaranteed to only receive byte buffers
- * generated by a previous call to {@link #doEncode(DocumentReply, GrowableByteBuffer)}.
- *
- * This method is NOT exception safe. Return null to signal failure.
- *
- * @param buf The byte buffer to read from.
- * @return The decoded reply.
- */
- virtual DocumentReply::UP doDecode(document::ByteBuffer &buf) const = 0;
-
- public:
- /**
- * Convenience typedefs.
- */
- typedef std::unique_ptr<IRoutableFactory> UP;
- typedef std::shared_ptr<IRoutableFactory> SP;
-
- bool encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const override;
- mbus::Routable::UP decode(document::ByteBuffer &in, const LoadTypeSet& loadTypes) const override;
- };
-
- /**
- * Implements a helper class to do feed message factories.
- */
- class FeedMessageFactory : public DocumentMessageFactory {
- protected:
- void myDecode(FeedMessage &msg, document::ByteBuffer &buf) const;
- void myEncode(const FeedMessage &msg, vespalib::GrowableByteBuffer &buf) const;
- };
-
- /**
- * Implements a helper class to do feed reply factories.
- */
- class FeedReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- virtual uint32_t getType() const = 0;
- };
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Factories
- //
- ////////////////////////////////////////////////////////////////////////////////
- class CreateVisitorMessageFactory : public DocumentMessageFactory {
- const document::DocumentTypeRepo &_repo;
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- public:
- CreateVisitorMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
- };
- class CreateVisitorReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class DestroyVisitorMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class DestroyVisitorReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class DocumentListMessageFactory : public DocumentMessageFactory {
- const document::DocumentTypeRepo &_repo;
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- public:
- DocumentListMessageFactory(const document::DocumentTypeRepo &r)
- : _repo(r) {}
- };
- class DocumentListReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class DocumentSummaryMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class DocumentSummaryReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class EmptyBucketsMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class EmptyBucketsReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class GetBucketListMessageFactory : public DocumentMessageFactory {
- virtual bool encodeBucketSpace(vespalib::stringref bucketSpace, vespalib::GrowableByteBuffer& buf) const;
- virtual string decodeBucketSpace(document::ByteBuffer&) const;
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class GetBucketListReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class GetBucketStateMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class GetBucketStateReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class GetDocumentMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class GetDocumentReplyFactory : public DocumentReplyFactory {
- const document::DocumentTypeRepo &_repo;
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &msg, vespalib::GrowableByteBuffer &buf) const override;
- public:
- GetDocumentReplyFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
- };
- class MapVisitorMessageFactory : public DocumentMessageFactory {
- const document::DocumentTypeRepo &_repo;
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- public:
- MapVisitorMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
- };
- class MapVisitorReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class PutDocumentMessageFactory : public DocumentMessageFactory {
- protected:
- const document::DocumentTypeRepo &_repo;
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override {
- return decodeMessage<PutDocumentMessage>(this, buf);
- }
-
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- public:
- void decodeInto(PutDocumentMessage & msg, document::ByteBuffer & buf) const;
- PutDocumentMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
- };
- class PutDocumentReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class RemoveDocumentMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override {
- return decodeMessage<RemoveDocumentMessage>(this, buf);
- }
-
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- public:
- void decodeInto(RemoveDocumentMessage & msg, document::ByteBuffer & buf) const;
- };
- class RemoveDocumentReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class RemoveLocationMessageFactory : public DocumentMessageFactory {
- const document::DocumentTypeRepo &_repo;
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- public:
- RemoveLocationMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
- };
- class RemoveLocationReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class SearchResultMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class SearchResultReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class StatBucketMessageFactory : public DocumentMessageFactory {
- virtual bool encodeBucketSpace(vespalib::stringref bucketSpace, vespalib::GrowableByteBuffer& buf) const;
- virtual string decodeBucketSpace(document::ByteBuffer&) const;
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class StatBucketReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class StatDocumentMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class StatDocumentReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class UpdateDocumentMessageFactory : public DocumentMessageFactory {
- protected:
- const document::DocumentTypeRepo &_repo;
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override {
- return decodeMessage<UpdateDocumentMessage>(this, buf);
- }
-
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- public:
- void decodeInto(UpdateDocumentMessage & msg, document::ByteBuffer & buf) const;
- UpdateDocumentMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
- };
- class UpdateDocumentReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class VisitorInfoMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class VisitorInfoReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class WrongDistributionReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
- class QueryResultMessageFactory : public DocumentMessageFactory {
- protected:
- DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
- };
- class QueryResultReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- };
-
- ///////////////////////////////////////////////////////////////////////////
- //
- // Utilities
- //
- ///////////////////////////////////////////////////////////////////////////
-
- /**
- * This is a complement for the vespalib::GrowableByteBuffer.putString() method.
- *
- * @param in The byte buffer to read from.
- * @return The decoded string.
- */
- static string decodeString(document::ByteBuffer &in)
- { return RoutableFactories42::decodeString(in); }
-
- /**
- * This is a complement for the vespalib::GrowableByteBuffer.putBoolean() method.
- *
- * @param in The byte buffer to read from.
- * @return The decoded bool.
- */
- static bool decodeBoolean(document::ByteBuffer &in)
- { return RoutableFactories42::decodeBoolean(in); }
-
- /**
- * Convenience method to decode a 32-bit int from the given byte buffer.
- *
- * @param in The byte buffer to read from.
- * @return The decoded int.
- */
- static int32_t decodeInt(document::ByteBuffer &in)
- { return RoutableFactories42::decodeInt(in); }
-
- /**
- * Convenience method to decode a 64-bit int from the given byte buffer.
- *
- * @param in The byte buffer to read from.
- * @return The decoded int.
- */
- static int64_t decodeLong(document::ByteBuffer &in)
- { return RoutableFactories42::decodeLong(in); }
-
-
- /**
- * Convenience method to decode a document id from the given byte buffer.
- *
- * @param in The byte buffer to read from.
- * @return The decoded document id.
- */
- static document::DocumentId decodeDocumentId(document::ByteBuffer &in)
- { return RoutableFactories42::decodeDocumentId(in); }
-
- /**
- * Convenience method to encode a document id to the given byte buffer.
- *
- * @param id The document id to encode.
- * @param out The byte buffer to write to.
- */
- static void encodeDocumentId(const document::DocumentId &id,
- vespalib::GrowableByteBuffer &out)
- { return RoutableFactories42::encodeDocumentId(id, out); }
-};
-
-}
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories51.cpp b/documentapi/src/vespa/documentapi/messagebus/routablefactories51.cpp
index ee51bd306a6..01d0c5b6c0e 100644
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories51.cpp
+++ b/documentapi/src/vespa/documentapi/messagebus/routablefactories51.cpp
@@ -12,52 +12,6 @@ using vespalib::nbostream;
namespace documentapi {
-bool
-RoutableFactories51::DocumentMessageFactory::encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const
-{
- const DocumentMessage &msg = static_cast<const DocumentMessage&>(obj);
- out.putByte(msg.getPriority());
- out.putInt(msg.getLoadType().getId());
- return doEncode(msg, out);
-}
-
-mbus::Routable::UP
-RoutableFactories51::DocumentMessageFactory::decode(document::ByteBuffer &in,
- const LoadTypeSet& loadTypes) const
-{
- uint8_t pri;
- in.getByte(pri);
- uint32_t loadClass = decodeInt(in);
-
- DocumentMessage::UP msg = doDecode(in);
- if (msg.get() != NULL) {
- msg->setPriority((Priority::Value)pri);
- msg->setLoadType(loadTypes[loadClass]);
- }
-
- return mbus::Routable::UP(msg.release());
-}
-
-bool
-RoutableFactories51::DocumentReplyFactory::encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const
-{
- const DocumentReply &msg = static_cast<const DocumentReply&>(obj);
- out.putByte(msg.getPriority());
- return doEncode(msg, out);
-}
-
-mbus::Routable::UP
-RoutableFactories51::DocumentReplyFactory::decode(document::ByteBuffer &in, const LoadTypeSet&) const
-{
- uint8_t pri;
- in.getByte(pri);
- DocumentReply::UP reply = doDecode(in);
- if (reply.get() != NULL) {
- reply->setPriority((Priority::Value)pri);
- }
- return mbus::Routable::UP(reply.release());
-}
-
DocumentMessage::UP
RoutableFactories51::CreateVisitorMessageFactory::doDecode(document::ByteBuffer &buf) const
{
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories51.h b/documentapi/src/vespa/documentapi/messagebus/routablefactories51.h
index b71c478c540..913b05f109b 100644
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories51.h
+++ b/documentapi/src/vespa/documentapi/messagebus/routablefactories51.h
@@ -14,111 +14,12 @@ class RoutableFactories51 : public RoutableFactories50 {
public:
RoutableFactories51() = delete;
- /**
- * Implements the shared factory logic required for {@link DocumentMessage} objects, and it offers a more
- * convenient interface for implementing {@link RoutableFactory}.
- */
- class DocumentMessageFactory : public IRoutableFactory {
- protected:
- /**
- * This method encodes the given message into the given byte buffer. You are guaranteed to only receive messages of
- * the type that this factory was registered for.
- *
- * This method is NOT exception safe. Return false to signal failure.
- *
- * @param msg The message to encode.
- * @param buf The byte buffer to write to.
- * @return True if the message was encoded.
- */
- virtual bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const = 0;
-
- /**
- * This method decodes a message from the given byte buffer. You are guaranteed to only receive byte buffers
- * generated by a previous call to {@link #doEncode(DocumentMessage, GrowableByteBuffer)}.
- *
- * This method is NOT exception safe. Return null to signal failure.
- *
- * @param buf The byte buffer to read from.
- * @return The decoded message.
- */
- virtual DocumentMessage::UP doDecode(document::ByteBuffer &buf) const = 0;
-
- public:
- /**
- * Convenience typedefs.
- */
- typedef std::unique_ptr<IRoutableFactory> UP;
- typedef std::shared_ptr<IRoutableFactory> SP;
-
- bool encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const override;
- mbus::Routable::UP decode(document::ByteBuffer &in, const LoadTypeSet& loadTypes) const override;
- };
-
- /**
- * Implements the shared factory logic required for {@link DocumentReply} objects, and it offers a more
- * convenient interface for implementing {@link RoutableFactory}.
- */
- class DocumentReplyFactory : public IRoutableFactory {
- protected:
- /**
- * This method encodes the given reply into the given byte buffer. You are guaranteed to only receive
- * replies of the type that this factory was registered for.
- *
- * This method is NOT exception safe. Return false to signal failure.
- *
- * @param reply The reply to encode.
- * @param buf The byte buffer to write to.
- * @return True if the message was encoded.
- */
- virtual bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const = 0;
-
- /**
- * This method decodes a reply from the given byte buffer. You are guaranteed to only receive byte buffers
- * generated by a previous call to {@link #doEncode(DocumentReply, GrowableByteBuffer)}.
- *
- * This method is NOT exception safe. Return null to signal failure.
- *
- * @param buf The byte buffer to read from.
- * @return The decoded reply.
- */
- virtual DocumentReply::UP doDecode(document::ByteBuffer &buf) const = 0;
-
- public:
- /**
- * Convenience typedefs.
- */
- typedef std::unique_ptr<IRoutableFactory> UP;
- typedef std::shared_ptr<IRoutableFactory> SP;
-
- bool encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const override;
- mbus::Routable::UP decode(document::ByteBuffer &in, const LoadTypeSet& loadTypes) const override;
- };
-
class DocumentIgnoredReplyFactory : public DocumentReplyFactory {
protected:
DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
};
- /**
- * Implements a helper class to do feed message factories.
- */
- class FeedMessageFactory : public DocumentMessageFactory {
- protected:
- void myDecode(FeedMessage &msg, document::ByteBuffer &buf) const;
- void myEncode(const FeedMessage &msg, vespalib::GrowableByteBuffer &buf) const;
- };
-
- /**
- * Implements a helper class to do feed reply factories.
- */
- class FeedReplyFactory : public DocumentReplyFactory {
- protected:
- DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
- bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
- virtual uint32_t getType() const = 0;
- };
-
////////////////////////////////////////////////////////////////////////////////
//
// Factories
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories52.cpp b/documentapi/src/vespa/documentapi/messagebus/routablefactories52.cpp
index 89f6e9c1fe1..6a49d812957 100644
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories52.cpp
+++ b/documentapi/src/vespa/documentapi/messagebus/routablefactories52.cpp
@@ -2,67 +2,939 @@
// @author Vegard Sjonfjell
#include "routablefactories52.h"
+#include <vespa/document/bucket/bucketidfactory.h>
+#include <vespa/document/bucket/fixed_bucket_spaces.h>
+#include <vespa/document/select/parser.h>
+#include <vespa/document/update/documentupdate.h>
#include <vespa/documentapi/documentapi.h>
+#include <vespa/documentapi/loadtypes/loadtypeset.h>
#include <vespa/vespalib/objects/nbostream.h>
+using document::FixedBucketSpaces;
using vespalib::nbostream;
using std::make_shared;
using std::make_unique;
namespace documentapi {
+bool
+RoutableFactories52::DocumentMessageFactory::encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const
+{
+ const DocumentMessage &msg = static_cast<const DocumentMessage&>(obj);
+ out.putByte(msg.getPriority());
+ out.putInt(msg.getLoadType().getId());
+ return doEncode(msg, out);
+}
+
+mbus::Routable::UP
+RoutableFactories52::DocumentMessageFactory::decode(document::ByteBuffer &in, const LoadTypeSet& loadTypes) const
+{
+ uint8_t pri;
+ in.getByte(pri);
+ uint32_t loadClass = decodeInt(in);
+
+ DocumentMessage::UP msg = doDecode(in);
+ if (msg) {
+ msg->setPriority((Priority::Value)pri);
+ msg->setLoadType(loadTypes[loadClass]);
+ }
+
+ return mbus::Routable::UP(msg.release());
+}
+
+bool
+RoutableFactories52::DocumentReplyFactory::encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const
+{
+ const DocumentReply &msg = static_cast<const DocumentReply&>(obj);
+ out.putByte(msg.getPriority());
+ return doEncode(msg, out);
+}
+
+mbus::Routable::UP
+RoutableFactories52::DocumentReplyFactory::decode(document::ByteBuffer &in, const LoadTypeSet&) const
+{
+ uint8_t pri;
+ in.getByte(pri);
+ DocumentReply::UP reply = doDecode(in);
+ if (reply) {
+ reply->setPriority((Priority::Value)pri);
+ }
+ return mbus::Routable::UP(reply.release());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// Factories
+//
+////////////////////////////////////////////////////////////////////////////////
+
+DocumentMessage::UP
+RoutableFactories52::CreateVisitorMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<CreateVisitorMessage>();
+
+ msg->setLibraryName(decodeString(buf));
+ msg->setInstanceId(decodeString(buf));
+ msg->setControlDestination(decodeString(buf));
+ msg->setDataDestination(decodeString(buf));
+ msg->setDocumentSelection(decodeString(buf));
+ msg->setMaximumPendingReplyCount(decodeInt(buf));
+
+ int32_t len = decodeInt(buf);
+ msg->getBuckets().reserve(len);
+ for (int32_t i = 0; i < len; i++) {
+ int64_t val;
+ buf.getLong(val); // NOT using getLongNetwork
+ msg->getBuckets().push_back(document::BucketId(val));
+ }
+
+ msg->setFromTimestamp(decodeLong(buf));
+ msg->setToTimestamp(decodeLong(buf));
+ msg->setVisitRemoves(decodeBoolean(buf));
+ msg->setFieldSet(decodeString(buf));
+ msg->setVisitInconsistentBuckets(decodeBoolean(buf));
+ msg->getParameters().deserialize(_repo, buf);
+ msg->setVisitorDispatcherVersion(50);
+ msg->setVisitorOrdering((document::OrderingSpecification::Order)decodeInt(buf));
+ msg->setMaxBucketsPerVisitor(decodeInt(buf));
+ msg->setBucketSpace(decodeBucketSpace(buf));
+
+ return msg;
+}
+
+bool
+RoutableFactories52::CreateVisitorMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const CreateVisitorMessage &msg = static_cast<const CreateVisitorMessage&>(obj);
+
+ buf.putString(msg.getLibraryName());
+ buf.putString(msg.getInstanceId());
+ buf.putString(msg.getControlDestination());
+ buf.putString(msg.getDataDestination());
+ buf.putString(msg.getDocumentSelection());
+ buf.putInt(msg.getMaximumPendingReplyCount());
+ buf.putInt(msg.getBuckets().size());
+
+ for (const auto & bucketId : msg.getBuckets()) {
+ uint64_t val = bucketId.getRawId();
+ buf.putBytes((const char*)&val, 8);
+ }
+
+ buf.putLong(msg.getFromTimestamp());
+ buf.putLong(msg.getToTimestamp());
+ buf.putBoolean(msg.visitRemoves());
+ buf.putString(msg.getFieldSet());
+ buf.putBoolean(msg.visitInconsistentBuckets());
+
+ int len = msg.getParameters().getSerializedSize();
+ char *tmp = buf.allocate(len);
+ document::ByteBuffer dbuf(tmp, len);
+ msg.getParameters().serialize(dbuf);
+
+ buf.putInt(msg.getVisitorOrdering());
+ buf.putInt(msg.getMaxBucketsPerVisitor());
+ return encodeBucketSpace(msg.getBucketSpace(), buf);
+}
+
+bool RoutableFactories52::CreateVisitorMessageFactory::encodeBucketSpace(
+ vespalib::stringref bucketSpace,
+ vespalib::GrowableByteBuffer& buf) const {
+ (void) buf;
+ return (bucketSpace == FixedBucketSpaces::default_space_name());
+}
+
+string RoutableFactories52::CreateVisitorMessageFactory::decodeBucketSpace(document::ByteBuffer&) const {
+ return FixedBucketSpaces::default_space_name();
+}
+
+DocumentMessage::UP
+RoutableFactories52::DestroyVisitorMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<DestroyVisitorMessage>();
+ msg->setInstanceId(decodeString(buf));
+ return msg;
+}
+
+bool
+RoutableFactories52::DestroyVisitorMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const DestroyVisitorMessage &msg = static_cast<const DestroyVisitorMessage&>(obj);
+ buf.putString(msg.getInstanceId());
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::CreateVisitorReplyFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto reply = std::make_unique<CreateVisitorReply>(DocumentProtocol::REPLY_CREATEVISITOR);
+ reply->setLastBucket(document::BucketId((uint64_t)decodeLong(buf)));
+ vdslib::VisitorStatistics vs;
+ vs.setBucketsVisited(decodeInt(buf));
+ vs.setDocumentsVisited(decodeLong(buf));
+ vs.setBytesVisited(decodeLong(buf));
+ vs.setDocumentsReturned(decodeLong(buf));
+ vs.setBytesReturned(decodeLong(buf));
+ vs.setSecondPassDocumentsReturned(decodeLong(buf));
+ vs.setSecondPassBytesReturned(decodeLong(buf));
+ reply->setVisitorStatistics(vs);
+
+ return reply;
+}
+
+bool
+RoutableFactories52::CreateVisitorReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const CreateVisitorReply &reply = static_cast<const CreateVisitorReply&>(obj);
+ buf.putLong(reply.getLastBucket().getRawId());
+ buf.putInt(reply.getVisitorStatistics().getBucketsVisited());
+ buf.putLong(reply.getVisitorStatistics().getDocumentsVisited());
+ buf.putLong(reply.getVisitorStatistics().getBytesVisited());
+ buf.putLong(reply.getVisitorStatistics().getDocumentsReturned());
+ buf.putLong(reply.getVisitorStatistics().getBytesReturned());
+ buf.putLong(reply.getVisitorStatistics().getSecondPassDocumentsReturned());
+ buf.putLong(reply.getVisitorStatistics().getSecondPassBytesReturned());
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::DestroyVisitorReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_DESTROYVISITOR);
+}
+
+bool
+RoutableFactories52::DestroyVisitorReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::DocumentIgnoredReplyFactory::doDecode(document::ByteBuffer& buf) const
+{
+ (void) buf;
+ return DocumentReply::UP(new DocumentIgnoredReply());
+}
+
+bool
+RoutableFactories52::DocumentIgnoredReplyFactory::doEncode(
+ const DocumentReply& obj,
+ vespalib::GrowableByteBuffer& buf) const
+{
+ (void) obj;
+ (void) buf;
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::DocumentListMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<DocumentListMessage>();
+ msg->setBucketId(document::BucketId(decodeLong(buf)));
+
+ int32_t len = decodeInt(buf);
+ for (int32_t i = 0; i < len; i++) {
+ DocumentListMessage::Entry entry(_repo, buf);
+ msg->getDocuments().push_back(entry);
+ }
+
+ return msg;
+}
+
+bool
+RoutableFactories52::DocumentListMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const DocumentListMessage &msg = static_cast<const DocumentListMessage&>(obj);
+
+ buf.putLong(msg.getBucketId().getRawId());
+ buf.putInt(msg.getDocuments().size());
+ for (const auto & document : msg.getDocuments()) {
+ int len = document.getSerializedSize();
+ char *tmp = buf.allocate(len);
+ document::ByteBuffer dbuf(tmp, len);
+ document.serialize(dbuf);
+ }
+
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::DocumentListReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_DOCUMENTLIST);
+}
+
+bool
+RoutableFactories52::DocumentListReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::DocumentSummaryMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<DocumentSummaryMessage>();
+
+ msg->deserialize(buf);
+
+ return msg;
+}
+
+bool
+RoutableFactories52::DocumentSummaryMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const DocumentSummaryMessage &msg = static_cast<const DocumentSummaryMessage&>(obj);
+
+ int32_t len = msg.getSerializedSize();
+ char *tmp = buf.allocate(len);
+ document::ByteBuffer dbuf(tmp, len);
+ msg.serialize(dbuf);
+
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::DocumentSummaryReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_DOCUMENTSUMMARY);
+}
+
+bool
+RoutableFactories52::DocumentSummaryReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::EmptyBucketsMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<EmptyBucketsMessage>();
+
+ int32_t len = decodeInt(buf);
+ std::vector<document::BucketId> buckets(len);
+ for (int32_t i = 0; i < len; ++i) {
+ buckets[i] = document::BucketId(decodeLong(buf));
+ }
+ msg->getBucketIds().swap(buckets);
+
+ return msg;
+}
+
+bool
+RoutableFactories52::EmptyBucketsMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const EmptyBucketsMessage &msg = static_cast<const EmptyBucketsMessage&>(obj);
+
+ buf.putInt(msg.getBucketIds().size());
+ for (const auto & bucketId : msg.getBucketIds()) {
+ buf.putLong(bucketId.getRawId());
+ }
+
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::EmptyBucketsReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_EMPTYBUCKETS);
+}
+
+bool
+RoutableFactories52::EmptyBucketsReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return true;
+}
+
+bool RoutableFactories52::GetBucketListMessageFactory::encodeBucketSpace(vespalib::stringref bucketSpace,
+ vespalib::GrowableByteBuffer& ) const
+{
+ return (bucketSpace == FixedBucketSpaces::default_space_name());
+}
+
+string RoutableFactories52::GetBucketListMessageFactory::decodeBucketSpace(document::ByteBuffer&) const {
+ return FixedBucketSpaces::default_space_name();
+}
+
+DocumentMessage::UP
+RoutableFactories52::GetBucketListMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ document::BucketId bucketId(decodeLong(buf));
+ auto msg = std::make_unique<GetBucketListMessage>(bucketId);
+ msg->setBucketSpace(decodeBucketSpace(buf));
+ return msg;
+}
+
+bool
+RoutableFactories52::GetBucketListMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const GetBucketListMessage &msg = static_cast<const GetBucketListMessage&>(obj);
+ buf.putLong(msg.getBucketId().getRawId());
+ return encodeBucketSpace(msg.getBucketSpace(), buf);
+}
+
+DocumentReply::UP
+RoutableFactories52::GetBucketListReplyFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto reply = std::make_unique<GetBucketListReply>();
+
+ int32_t len = decodeInt(buf);
+ reply->getBuckets().reserve(len);
+ for (int32_t i = 0; i < len; i++) {
+ GetBucketListReply::BucketInfo info;
+ info._bucket = document::BucketId((uint64_t)decodeLong(buf));
+ info._bucketInformation = decodeString(buf);
+ reply->getBuckets().push_back(info);
+ }
+
+ return reply;
+}
+
+bool
+RoutableFactories52::GetBucketListReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const GetBucketListReply &reply = static_cast<const GetBucketListReply&>(obj);
+
+ const std::vector<GetBucketListReply::BucketInfo> &buckets = reply.getBuckets();
+ buf.putInt(buckets.size());
+ for (const auto & bucketInfo : buckets) {
+ buf.putLong(bucketInfo._bucket.getRawId());
+ buf.putString(bucketInfo._bucketInformation);
+ }
+
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::GetBucketStateMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<GetBucketStateMessage>();
+
+ msg->setBucketId(document::BucketId((uint64_t)decodeLong(buf)));
+
+ return msg;
+}
+
+bool
+RoutableFactories52::GetBucketStateMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const GetBucketStateMessage &msg = static_cast<const GetBucketStateMessage&>(obj);
+ buf.putLong(msg.getBucketId().getRawId());
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::GetBucketStateReplyFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto reply = std::make_unique<GetBucketStateReply>();
+
+ int32_t len = decodeInt(buf);
+ reply->getBucketState().reserve(len);
+ for (int32_t i = 0; i < len; i++) {
+ reply->getBucketState().emplace_back(buf);
+ }
+
+ return reply;
+}
+
+bool
+RoutableFactories52::GetBucketStateReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const GetBucketStateReply &reply = static_cast<const GetBucketStateReply&>(obj);
+
+ buf.putInt(reply.getBucketState().size());
+ for (const auto & state : reply.getBucketState()) {
+ state.serialize(buf);
+ }
+
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::GetDocumentMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ return DocumentMessage::UP(
+ new GetDocumentMessage(decodeDocumentId(buf),
+ decodeString(buf)));
+}
+
+bool
+RoutableFactories52::GetDocumentMessageFactory::doEncode(const DocumentMessage &obj,
+ vespalib::GrowableByteBuffer &buf) const
+{
+ const GetDocumentMessage &msg = static_cast<const GetDocumentMessage&>(obj);
+
+ encodeDocumentId(msg.getDocumentId(), buf);
+ buf.putString(msg.getFieldSet());
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::GetDocumentReplyFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto reply = std::make_unique<GetDocumentReply>();
+
+ bool hasDocument = decodeBoolean(buf);
+ document::Document * document = nullptr;
+ if (hasDocument) {
+ auto doc = std::make_shared<document::Document>(_repo, buf);
+ document = doc.get();
+ reply->setDocument(std::move(doc));
+ }
+ int64_t lastModified = decodeLong(buf);
+ reply->setLastModified(lastModified);
+ if (hasDocument) {
+ document->setLastModified(lastModified);
+ }
+
+ return reply;
+}
+
+bool
+RoutableFactories52::GetDocumentReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const GetDocumentReply &reply = static_cast<const GetDocumentReply&>(obj);
+
+ buf.putByte(reply.hasDocument() ? 1 : 0);
+ if (reply.hasDocument()) {
+ nbostream stream;
+ reply.getDocument().serialize(stream);
+ buf.putBytes(stream.peek(), stream.size());
+ }
+ buf.putLong(reply.getLastModified());
+
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::MapVisitorMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<MapVisitorMessage>();
+ msg->getData().deserialize(_repo, buf);
+ return msg;
+}
+
+bool
+RoutableFactories52::MapVisitorMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const MapVisitorMessage &msg = static_cast<const MapVisitorMessage&>(obj);
+
+ int32_t len = msg.getData().getSerializedSize();
+ char *tmp = buf.allocate(len);
+ document::ByteBuffer dbuf(tmp, len);
+ msg.getData().serialize(dbuf);
+
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::MapVisitorReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_MAPVISITOR);
+}
+
+bool
+RoutableFactories52::MapVisitorReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return true;
+}
+
void
RoutableFactories52::PutDocumentMessageFactory::decodeInto(PutDocumentMessage & msg, document::ByteBuffer & buf) const {
- super::decodeInto(msg, buf);
+ msg.setDocument(make_shared<document::Document>(_repo, buf));
+ msg.setTimestamp(static_cast<uint64_t>(decodeLong(buf)));
decodeTasCondition(msg, buf);
}
bool
-RoutableFactories52::PutDocumentMessageFactory::doEncode(const DocumentMessage & msg, vespalib::GrowableByteBuffer & buf) const
+RoutableFactories52::PutDocumentMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
{
- if (! super::doEncode(msg, buf)) {
- return false;
- }
+ auto & msg = static_cast<const PutDocumentMessage &>(obj);
+ nbostream stream;
+ msg.getDocument().serialize(stream);
+ buf.putBytes(stream.peek(), stream.size());
+ buf.putLong(static_cast<int64_t>(msg.getTimestamp()));
encodeTasCondition(buf, msg);
+
return true;
}
+DocumentReply::UP
+RoutableFactories52::PutDocumentReplyFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto reply = make_unique<WriteDocumentReply>(DocumentProtocol::REPLY_PUTDOCUMENT);
+ reply->setHighestModificationTimestamp(decodeLong(buf));
+
+ // Doing an explicit move here to force converting result to an rvalue.
+ // This is done automatically in GCC >= 5.
+ return std::move(reply);
+}
+
+bool
+RoutableFactories52::PutDocumentReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const WriteDocumentReply& reply = (const WriteDocumentReply&)obj;
+ buf.putLong(reply.getHighestModificationTimestamp());
+ return true;
+}
+
void
RoutableFactories52::RemoveDocumentMessageFactory::decodeInto(RemoveDocumentMessage & msg, document::ByteBuffer & buf) const {
- super::decodeInto(msg, buf);
+ msg.setDocumentId(decodeDocumentId(buf));
decodeTasCondition(msg, buf);
}
+bool
+RoutableFactories52::RemoveDocumentMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const RemoveDocumentMessage &msg = static_cast<const RemoveDocumentMessage&>(obj);
+ encodeDocumentId(msg.getDocumentId(), buf);
+ encodeTasCondition(buf, msg);
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::RemoveDocumentReplyFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto reply = std::make_unique<RemoveDocumentReply>();
+ reply->setWasFound(decodeBoolean(buf));
+ reply->setHighestModificationTimestamp(decodeLong(buf));
+ return reply;
+}
bool
-RoutableFactories52::RemoveDocumentMessageFactory::doEncode(const DocumentMessage & msg, vespalib::GrowableByteBuffer & buf) const
+RoutableFactories52::RemoveDocumentReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
{
- if (! super::doEncode(msg, buf)) {
- return false;
- }
+ const RemoveDocumentReply &reply = static_cast<const RemoveDocumentReply&>(obj);
+ buf.putBoolean(reply.getWasFound());
+ buf.putLong(reply.getHighestModificationTimestamp());
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::RemoveLocationMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ string selection = decodeString(buf);
+
+ document::BucketIdFactory factory;
+ document::select::Parser parser(_repo, factory);
+
+ auto msg = std::make_unique<RemoveLocationMessage>(factory, parser, selection);
+ // FIXME bucket space not part of wire format, implicitly limiting to only default space for now.
+ msg->setBucketSpace(document::FixedBucketSpaces::default_space_name());
+ return msg;
+}
+
+bool
+RoutableFactories52::RemoveLocationMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const RemoveLocationMessage &msg = static_cast<const RemoveLocationMessage&>(obj);
+ buf.putString(msg.getDocumentSelection());
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::RemoveLocationReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return std::make_unique<DocumentReply>(DocumentProtocol::REPLY_REMOVELOCATION);
+}
+
+bool
+RoutableFactories52::RemoveLocationReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::SearchResultMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<SearchResultMessage>();
+ msg->deserialize(buf);
+ return msg;
+}
+
+bool
+RoutableFactories52::SearchResultMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const SearchResultMessage &msg = static_cast<const SearchResultMessage&>(obj);
+
+ int len = msg.getSerializedSize();
+ char *tmp = buf.allocate(len);
+ document::ByteBuffer dbuf(tmp, len);
+ msg.serialize(dbuf);
- encodeTasCondition(buf, msg);
return true;
}
+DocumentMessage::UP
+RoutableFactories52::QueryResultMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<QueryResultMessage>();
+ msg->getSearchResult().deserialize(buf);
+ msg->getDocumentSummary().deserialize(buf);
+
+ return msg;
+}
+
+bool
+RoutableFactories52::QueryResultMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const QueryResultMessage &msg = static_cast<const QueryResultMessage&>(obj);
+
+ int len = msg.getSearchResult().getSerializedSize() + msg.getDocumentSummary().getSerializedSize();
+ char *tmp = buf.allocate(len);
+ document::ByteBuffer dbuf(tmp, len);
+ msg.getSearchResult().serialize(dbuf);
+ msg.getDocumentSummary().serialize(dbuf);
+
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::SearchResultReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_SEARCHRESULT);
+}
+
+bool
+RoutableFactories52::SearchResultReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::QueryResultReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_QUERYRESULT);
+}
+
+bool
+RoutableFactories52::QueryResultReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return true;
+}
+
+bool RoutableFactories52::StatBucketMessageFactory::encodeBucketSpace(vespalib::stringref bucketSpace,
+ vespalib::GrowableByteBuffer& ) const
+{
+ return (bucketSpace == FixedBucketSpaces::default_space_name());
+}
+
+string RoutableFactories52::StatBucketMessageFactory::decodeBucketSpace(document::ByteBuffer&) const {
+ return FixedBucketSpaces::default_space_name();
+}
+
+DocumentMessage::UP
+RoutableFactories52::StatBucketMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<StatBucketMessage>();
+
+ msg->setBucketId(document::BucketId(decodeLong(buf)));
+ msg->setDocumentSelection(decodeString(buf));
+ msg->setBucketSpace(decodeBucketSpace(buf));
+
+ return msg;
+}
+
+bool
+RoutableFactories52::StatBucketMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const StatBucketMessage &msg = static_cast<const StatBucketMessage&>(obj);
+
+ buf.putLong(msg.getBucketId().getRawId());
+ buf.putString(msg.getDocumentSelection());
+ return encodeBucketSpace(msg.getBucketSpace(), buf);
+}
+
+DocumentReply::UP
+RoutableFactories52::StatBucketReplyFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto reply = std::make_unique<StatBucketReply>();
+ reply->setResults(decodeString(buf));
+ return reply;
+}
+
+bool
+RoutableFactories52::StatBucketReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const StatBucketReply &reply = static_cast<const StatBucketReply&>(obj);
+ buf.putString(reply.getResults());
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::StatDocumentMessageFactory::doDecode(document::ByteBuffer &) const
+{
+ return DocumentMessage::UP(); // TODO: remove message type
+}
+
+bool
+RoutableFactories52::StatDocumentMessageFactory::doEncode(const DocumentMessage &, vespalib::GrowableByteBuffer &) const
+{
+ return false;
+}
+
+DocumentReply::UP
+RoutableFactories52::StatDocumentReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return DocumentReply::UP(); // TODO: remove reply type
+}
+
+bool
+RoutableFactories52::StatDocumentReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return false;
+}
+
void
RoutableFactories52::UpdateDocumentMessageFactory::decodeInto(UpdateDocumentMessage & msg, document::ByteBuffer & buf) const {
- super::decodeInto(msg, buf);
+ msg.setDocumentUpdate(document::DocumentUpdate::createHEAD(_repo, buf));
+ msg.setOldTimestamp(static_cast<uint64_t>(decodeLong(buf)));
+ msg.setNewTimestamp(static_cast<uint64_t>(decodeLong(buf)));
decodeTasCondition(msg, buf);
}
bool
-RoutableFactories52::UpdateDocumentMessageFactory::doEncode(const DocumentMessage & msg, vespalib::GrowableByteBuffer & buf) const
+RoutableFactories52::UpdateDocumentMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
{
- if (! super::doEncode(msg, buf)) {
- return false;
- }
+ const UpdateDocumentMessage &msg = static_cast<const UpdateDocumentMessage&>(obj);
+ vespalib::nbostream stream;
+ msg.getDocumentUpdate().serializeHEAD(stream);
+ buf.putBytes(stream.peek(), stream.size());
+ buf.putLong((int64_t)msg.getOldTimestamp());
+ buf.putLong((int64_t)msg.getNewTimestamp());
encodeTasCondition(buf, msg);
+
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::UpdateDocumentReplyFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto reply = std::make_unique<UpdateDocumentReply>();
+ reply->setWasFound(decodeBoolean(buf));
+ reply->setHighestModificationTimestamp(decodeLong(buf));
+ return reply;
+}
+
+bool
+RoutableFactories52::UpdateDocumentReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const UpdateDocumentReply &reply = static_cast<const UpdateDocumentReply&>(obj);
+ buf.putBoolean(reply.getWasFound());
+ buf.putLong(reply.getHighestModificationTimestamp());
+ return true;
+}
+
+DocumentMessage::UP
+RoutableFactories52::VisitorInfoMessageFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto msg = std::make_unique<VisitorInfoMessage>();
+
+ int32_t len = decodeInt(buf);
+ msg->getFinishedBuckets().reserve(len);
+ for (int32_t i = 0; i < len; i++) {
+ int64_t val;
+ buf.getLong(val); // NOT using getLongNetwork
+ msg->getFinishedBuckets().emplace_back(val);
+ }
+ msg->setErrorMessage(decodeString(buf));
+
+ return msg;
+}
+
+bool
+RoutableFactories52::VisitorInfoMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const VisitorInfoMessage &msg = static_cast<const VisitorInfoMessage&>(obj);
+
+ buf.putInt(msg.getFinishedBuckets().size());
+ for (const auto & bucketId : msg.getFinishedBuckets()) {
+ uint64_t val = bucketId.getRawId();
+ buf.putBytes((const char*)&val, 8);
+ }
+ buf.putString(msg.getErrorMessage());
+
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::VisitorInfoReplyFactory::doDecode(document::ByteBuffer &) const
+{
+ return std::make_unique<VisitorReply>(DocumentProtocol::REPLY_VISITORINFO);
+}
+
+bool
+RoutableFactories52::VisitorInfoReplyFactory::doEncode(const DocumentReply &, vespalib::GrowableByteBuffer &) const
+{
+ return true;
+}
+
+DocumentReply::UP
+RoutableFactories52::WrongDistributionReplyFactory::doDecode(document::ByteBuffer &buf) const
+{
+ auto reply = std::make_unique<WrongDistributionReply>();
+ reply->setSystemState(decodeString(buf));
+ return reply;
+}
+
+bool
+RoutableFactories52::WrongDistributionReplyFactory::doEncode(const DocumentReply &obj, vespalib::GrowableByteBuffer &buf) const
+{
+ const WrongDistributionReply &reply = static_cast<const WrongDistributionReply&>(obj);
+ buf.putString(reply.getSystemState());
return true;
}
+string
+RoutableFactories52::decodeString(document::ByteBuffer &in)
+{
+ int32_t len = decodeInt(in);
+ string ret = string(in.getBufferAtPos(), len);
+ in.incPos(len);
+ return ret;
+}
+
+bool
+RoutableFactories52::decodeBoolean(document::ByteBuffer &in)
+{
+ char ret;
+ in.getBytes(&ret, 1);
+ return (bool)ret;
+}
+
+int32_t
+RoutableFactories52::decodeInt(document::ByteBuffer &in)
+{
+ int32_t ret;
+ in.getIntNetwork(ret);
+ return ret;
+}
+
+int64_t
+RoutableFactories52::decodeLong(document::ByteBuffer &in)
+{
+ int64_t ret;
+ in.getLongNetwork(ret);
+ return ret;
+}
+
+document::DocumentId
+RoutableFactories52::decodeDocumentId(document::ByteBuffer &in)
+{
+ nbostream stream(in.getBufferAtPos(), in.getRemaining());
+ document::DocumentId ret(stream);
+ in.incPos(stream.rp());
+ return ret;
+}
+
+void
+RoutableFactories52::encodeDocumentId(const document::DocumentId &id, vespalib::GrowableByteBuffer &out)
+{
+ string str = id.toString();
+ out.putBytes(str.c_str(), str.size() + 1);
+}
+
void RoutableFactories52::decodeTasCondition(DocumentMessage & docMsg, document::ByteBuffer & buf) {
auto & msg = static_cast<TestAndSetMessage &>(docMsg);
msg.setCondition(TestAndSetCondition(decodeString(buf)));
@@ -73,4 +945,5 @@ void RoutableFactories52::encodeTasCondition(vespalib::GrowableByteBuffer & buf,
buf.putString(msg.getCondition().getSelection());
}
+
}
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories52.h b/documentapi/src/vespa/documentapi/messagebus/routablefactories52.h
index ac56dea8467..9c614bde487 100644
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories52.h
+++ b/documentapi/src/vespa/documentapi/messagebus/routablefactories52.h
@@ -2,57 +2,417 @@
// @author Vegard Sjonfjell
#pragma once
-#include "routablefactories51.h"
-#include <vespa/documentapi/messagebus/messages/testandsetmessage.h>
+#include <vespa/document/util/bytebuffer.h>
+#include <vespa/vespalib/util/growablebytebuffer.h>
+#include "iroutablefactory.h"
+#include <vespa/documentapi/messagebus/messages/putdocumentmessage.h>
+#include <vespa/documentapi/messagebus/messages/removedocumentmessage.h>
+#include <vespa/documentapi/messagebus/messages/updatedocumentmessage.h>
namespace document { class DocumentTypeRepo; }
+/**
+ * Utility class for invoking setApproxSize on a DocumentMessage with the delta
+ * between the read position of a ByteBuffer at construction and destruction
+ * time. The assumption being made is that the in-memory footprint of a message
+ * is reasonably close to its wire-serialized form.
+ */
+class ScopedApproxSizeSetter {
+public:
+ ScopedApproxSizeSetter(documentapi::DocumentMessage& msg,
+ const document::ByteBuffer& buf)
+ : _msg(msg),
+ _buf(buf),
+ _posBefore(_buf.getPos())
+ {
+ }
+
+ ~ScopedApproxSizeSetter() {
+ _msg.setApproxSize(static_cast<uint32_t>(_buf.getPos() - _posBefore));
+ }
+
+private:
+ documentapi::DocumentMessage& _msg;
+ const document::ByteBuffer& _buf;
+ const size_t _posBefore;
+};
+
namespace documentapi {
+
+template<typename MessageType, typename FactoryType>
+DocumentMessage::UP
+decodeMessage(const FactoryType * self, document::ByteBuffer & buf) {
+ auto msg = std::make_unique<MessageType>();
+ ScopedApproxSizeSetter sizeSetter(*msg, buf);
+ self->decodeInto(*msg, buf);
+ return msg;
+}
+
/**
* This class encapsulates all the {@link RoutableFactory} classes needed to implement factories for the document
* routable. When adding new factories to this class, please KEEP THE THEM ORDERED alphabetically like they are now.
*/
-class RoutableFactories52 : public RoutableFactories51 {
+class RoutableFactories52 {
public:
RoutableFactories52() = delete;
- class PutDocumentMessageFactory : public RoutableFactories50::PutDocumentMessageFactory {
- using super = RoutableFactories50::PutDocumentMessageFactory;
+ /**
+ * Implements the shared factory logic required for {@link DocumentMessage} objects, and it offers a more
+ * convenient interface for implementing {@link RoutableFactory}.
+ */
+ class DocumentMessageFactory : public IRoutableFactory {
+ protected:
+ /**
+ * This method encodes the given message into the given byte buffer. You are guaranteed to only receive messages of
+ * the type that this factory was registered for.
+ *
+ * This method is NOT exception safe. Return false to signal failure.
+ *
+ * @param msg The message to encode.
+ * @param buf The byte buffer to write to.
+ * @return True if the message was encoded.
+ */
+ virtual bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const = 0;
+
+ /**
+ * This method decodes a message from the given byte buffer. You are guaranteed to only receive byte buffers
+ * generated by a previous call to {@link #doEncode(DocumentMessage, GrowableByteBuffer)}.
+ *
+ * This method is NOT exception safe. Return null to signal failure.
+ *
+ * @param buf The byte buffer to read from.
+ * @return The decoded message.
+ */
+ virtual DocumentMessage::UP doDecode(document::ByteBuffer &buf) const = 0;
+
+ public:
+ bool encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const override;
+ mbus::Routable::UP decode(document::ByteBuffer &in, const LoadTypeSet& loadTypes) const override;
+ };
+
+ /**
+ * Implements the shared factory logic required for {@link DocumentReply} objects, and it offers a more
+ * convenient interface for implementing {@link RoutableFactory}.
+ */
+ class DocumentReplyFactory : public IRoutableFactory {
+ protected:
+ /**
+ * This method encodes the given reply into the given byte buffer. You are guaranteed to only receive
+ * replies of the type that this factory was registered for.
+ *
+ * This method is NOT exception safe. Return false to signal failure.
+ *
+ * @param reply The reply to encode.
+ * @param buf The byte buffer to write to.
+ * @return True if the message was encoded.
+ */
+ virtual bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const = 0;
+
+ /**
+ * This method decodes a reply from the given byte buffer. You are guaranteed to only receive byte buffers
+ * generated by a previous call to {@link #doEncode(DocumentReply, GrowableByteBuffer)}.
+ *
+ * This method is NOT exception safe. Return null to signal failure.
+ *
+ * @param buf The byte buffer to read from.
+ * @return The decoded reply.
+ */
+ virtual DocumentReply::UP doDecode(document::ByteBuffer &buf) const = 0;
+
+ public:
+ bool encode(const mbus::Routable &obj, vespalib::GrowableByteBuffer &out) const override;
+ mbus::Routable::UP decode(document::ByteBuffer &in, const LoadTypeSet& loadTypes) const override;
+ };
+
+ ////////////////////////////////////////////////////////////////////////////////
+ //
+ // Factories
+ //
+ ////////////////////////////////////////////////////////////////////////////////
+ class CreateVisitorMessageFactory : public DocumentMessageFactory {
+ const document::DocumentTypeRepo &_repo;
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+
+ virtual bool encodeBucketSpace(vespalib::stringref bucketSpace, vespalib::GrowableByteBuffer& buf) const;
+ virtual string decodeBucketSpace(document::ByteBuffer&) const;
+ public:
+ CreateVisitorMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
+ };
+ class CreateVisitorReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class DestroyVisitorMessageFactory : public DocumentMessageFactory {
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class DestroyVisitorReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class DocumentIgnoredReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class DocumentListMessageFactory : public DocumentMessageFactory {
+ const document::DocumentTypeRepo &_repo;
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ public:
+ DocumentListMessageFactory(const document::DocumentTypeRepo &r)
+ : _repo(r) {}
+ };
+ class DocumentListReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class DocumentSummaryMessageFactory : public DocumentMessageFactory {
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class DocumentSummaryReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class EmptyBucketsMessageFactory : public DocumentMessageFactory {
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class EmptyBucketsReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class GetBucketListMessageFactory : public DocumentMessageFactory {
+ virtual bool encodeBucketSpace(vespalib::stringref bucketSpace, vespalib::GrowableByteBuffer& buf) const;
+ virtual string decodeBucketSpace(document::ByteBuffer&) const;
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class GetBucketListReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class GetBucketStateMessageFactory : public DocumentMessageFactory {
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class GetBucketStateReplyFactory : public DocumentReplyFactory {
protected:
- DocumentMessage::UP doDecode(document::ByteBuffer & buf) const override {
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class GetDocumentMessageFactory : public DocumentMessageFactory {
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class GetDocumentReplyFactory : public DocumentReplyFactory {
+ const document::DocumentTypeRepo &_repo;
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &msg, vespalib::GrowableByteBuffer &buf) const override;
+ public:
+ GetDocumentReplyFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
+ };
+ class MapVisitorMessageFactory : public DocumentMessageFactory {
+ const document::DocumentTypeRepo &_repo;
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ public:
+ MapVisitorMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
+ };
+ class MapVisitorReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class PutDocumentMessageFactory : public DocumentMessageFactory {
+ protected:
+ const document::DocumentTypeRepo &_repo;
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override {
return decodeMessage<PutDocumentMessage>(this, buf);
}
- bool doEncode(const DocumentMessage & msg, vespalib::GrowableByteBuffer & buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
public:
void decodeInto(PutDocumentMessage & msg, document::ByteBuffer & buf) const;
- PutDocumentMessageFactory(const document::DocumentTypeRepo & r) : super::PutDocumentMessageFactory(r) {}
+ PutDocumentMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
};
-
- class RemoveDocumentMessageFactory : public RoutableFactories50::RemoveDocumentMessageFactory {
- using super = RoutableFactories50::RemoveDocumentMessageFactory;
+ class PutDocumentReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class RemoveDocumentMessageFactory : public DocumentMessageFactory {
protected:
- DocumentMessage::UP doDecode(document::ByteBuffer & buf) const override {
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override {
return decodeMessage<RemoveDocumentMessage>(this, buf);
}
- bool doEncode(const DocumentMessage & msg, vespalib::GrowableByteBuffer & buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
public:
void decodeInto(RemoveDocumentMessage & msg, document::ByteBuffer & buf) const;
};
-
- class UpdateDocumentMessageFactory : public RoutableFactories50::UpdateDocumentMessageFactory {
- using super = RoutableFactories50::UpdateDocumentMessageFactory;
+ class RemoveDocumentReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class RemoveLocationMessageFactory : public DocumentMessageFactory {
+ const document::DocumentTypeRepo &_repo;
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ public:
+ RemoveLocationMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
+ };
+ class RemoveLocationReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class SearchResultMessageFactory : public DocumentMessageFactory {
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class SearchResultReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class StatBucketMessageFactory : public DocumentMessageFactory {
+ virtual bool encodeBucketSpace(vespalib::stringref bucketSpace, vespalib::GrowableByteBuffer& buf) const;
+ virtual string decodeBucketSpace(document::ByteBuffer&) const;
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class StatBucketReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class StatDocumentMessageFactory : public DocumentMessageFactory {
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class StatDocumentReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class UpdateDocumentMessageFactory : public DocumentMessageFactory {
protected:
- DocumentMessage::UP doDecode(document::ByteBuffer & buf) const override {
+ const document::DocumentTypeRepo &_repo;
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override {
return decodeMessage<UpdateDocumentMessage>(this, buf);
}
- bool doEncode(const DocumentMessage & msg, vespalib::GrowableByteBuffer & buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
public:
void decodeInto(UpdateDocumentMessage & msg, document::ByteBuffer & buf) const;
- UpdateDocumentMessageFactory(const document::DocumentTypeRepo & r) : super::UpdateDocumentMessageFactory(r) {}
+ UpdateDocumentMessageFactory(const document::DocumentTypeRepo &r) : _repo(r) {}
+ };
+ class UpdateDocumentReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class VisitorInfoMessageFactory : public DocumentMessageFactory {
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class VisitorInfoReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
};
+ class WrongDistributionReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class QueryResultMessageFactory : public DocumentMessageFactory {
+ protected:
+ DocumentMessage::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentMessage &msg, vespalib::GrowableByteBuffer &buf) const override;
+ };
+ class QueryResultReplyFactory : public DocumentReplyFactory {
+ protected:
+ DocumentReply::UP doDecode(document::ByteBuffer &buf) const override;
+ bool doEncode(const DocumentReply &reply, vespalib::GrowableByteBuffer &buf) const override;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // Utilities
+ //
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * This is a complement for the vespalib::GrowableByteBuffer.putString() method.
+ *
+ * @param in The byte buffer to read from.
+ * @return The decoded string.
+ */
+ static string decodeString(document::ByteBuffer &in);
+
+ /**
+ * This is a complement for the vespalib::GrowableByteBuffer.putBoolean() method.
+ *
+ * @param in The byte buffer to read from.
+ * @return The decoded bool.
+ */
+ static bool decodeBoolean(document::ByteBuffer &in);
+
+ /**
+ * Convenience method to decode a 32-bit int from the given byte buffer.
+ *
+ * @param in The byte buffer to read from.
+ * @return The decoded int.
+ */
+ static int32_t decodeInt(document::ByteBuffer &in);
+
+ /**
+ * Convenience method to decode a 64-bit int from the given byte buffer.
+ *
+ * @param in The byte buffer to read from.
+ * @return The decoded int.
+ */
+ static int64_t decodeLong(document::ByteBuffer &in);
+
+ /**
+ * Convenience method to decode a document id from the given byte buffer.
+ *
+ * @param in The byte buffer to read from.
+ * @return The decoded document id.
+ */
+ static document::DocumentId decodeDocumentId(document::ByteBuffer &in);
+
+ /**
+ * Convenience method to encode a document id to the given byte buffer.
+ *
+ * @param id The document id to encode.
+ * @param out The byte buffer to write to.
+ */
+ static void encodeDocumentId(const document::DocumentId &id,
+ vespalib::GrowableByteBuffer &out);
static void decodeTasCondition(DocumentMessage & docMsg, document::ByteBuffer & buf);
static void encodeTasCondition(vespalib::GrowableByteBuffer & buf, const DocumentMessage & docMsg);
diff --git a/documentapi/src/vespa/documentapi/messagebus/routablefactories60.h b/documentapi/src/vespa/documentapi/messagebus/routablefactories60.h
index 26a8f0cb6d5..e91c9a773f2 100644
--- a/documentapi/src/vespa/documentapi/messagebus/routablefactories60.h
+++ b/documentapi/src/vespa/documentapi/messagebus/routablefactories60.h
@@ -22,14 +22,14 @@ public:
: RoutableFactories52::CreateVisitorMessageFactory(r) {}
};
- class StatBucketMessageFactory : public RoutableFactories50::StatBucketMessageFactory {
+ class StatBucketMessageFactory : public RoutableFactories52::StatBucketMessageFactory {
bool encodeBucketSpace(vespalib::stringref bucketSpace, vespalib::GrowableByteBuffer& buf) const override;
string decodeBucketSpace(document::ByteBuffer&) const override;
public:
StatBucketMessageFactory() = default;
};
- class GetBucketListMessageFactory : public RoutableFactories50::GetBucketListMessageFactory {
+ class GetBucketListMessageFactory : public RoutableFactories52::GetBucketListMessageFactory {
bool encodeBucketSpace(vespalib::stringref bucketSpace, vespalib::GrowableByteBuffer& buf) const override;
string decodeBucketSpace(document::ByteBuffer&) const override;
public:
@@ -40,4 +40,4 @@ public:
static string doDecodeBucketSpace(document::ByteBuffer&);
};
-} \ No newline at end of file
+}