diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-01-06 12:44:51 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-01-06 13:51:43 +0000 |
commit | 20abbaa6eb1b411bbc43b98c3bb5bc8e79a86153 (patch) | |
tree | d0eb22f90787408b402848f06b8b5f578542c3d4 | |
parent | 3110d9380650e0f68fad2a621ea71d083519446a (diff) |
Use enum class for the flags.
11 files changed, 90 insertions, 92 deletions
diff --git a/persistence/src/tests/dummyimpl/dummypersistence_test.cpp b/persistence/src/tests/dummyimpl/dummypersistence_test.cpp index 3b30f5e29ca..2c245f377e1 100644 --- a/persistence/src/tests/dummyimpl/dummypersistence_test.cpp +++ b/persistence/src/tests/dummyimpl/dummypersistence_test.cpp @@ -19,14 +19,14 @@ namespace { struct Fixture { BucketContent content; - void insert(DocumentId id, Timestamp timestamp, int meta_flags) { + void insert(DocumentId id, Timestamp timestamp, DocumentMetaFlags meta_flags) { content.insert(DocEntry::create(timestamp, meta_flags, id)); } Fixture() { - insert(DocumentId("id:ns:type::test:3"), Timestamp(3), NONE); - insert(DocumentId("id:ns:type::test:1"), Timestamp(1), NONE); - insert(DocumentId("id:ns:type::test:2"), Timestamp(2), NONE); + insert(DocumentId("id:ns:type::test:3"), Timestamp(3), DocumentMetaFlags::NONE); + insert(DocumentId("id:ns:type::test:1"), Timestamp(1), DocumentMetaFlags::NONE); + insert(DocumentId("id:ns:type::test:2"), Timestamp(2), DocumentMetaFlags::NONE); } }; @@ -63,13 +63,13 @@ TEST_F("require that BucketContent can provide bucket info", Fixture) { uint32_t lastChecksum = 0; EXPECT_NOT_EQUAL(lastChecksum, f.content.getBucketInfo().getChecksum()); lastChecksum = f.content.getBucketInfo().getChecksum(); - f.insert(DocumentId("id:ns:type::test:3"), Timestamp(4), NONE); + f.insert(DocumentId("id:ns:type::test:3"), Timestamp(4), DocumentMetaFlags::NONE); EXPECT_NOT_EQUAL(lastChecksum, f.content.getBucketInfo().getChecksum()); lastChecksum = f.content.getBucketInfo().getChecksum(); - f.insert(DocumentId("id:ns:type::test:2"), Timestamp(5), REMOVE_ENTRY); + f.insert(DocumentId("id:ns:type::test:2"), Timestamp(5), DocumentMetaFlags::REMOVE_ENTRY); EXPECT_NOT_EQUAL(lastChecksum, f.content.getBucketInfo().getChecksum()); - f.insert(DocumentId("id:ns:type::test:1"), Timestamp(6), REMOVE_ENTRY); - f.insert(DocumentId("id:ns:type::test:3"), Timestamp(7), REMOVE_ENTRY); + f.insert(DocumentId("id:ns:type::test:1"), Timestamp(6), DocumentMetaFlags::REMOVE_ENTRY); + f.insert(DocumentId("id:ns:type::test:3"), Timestamp(7), DocumentMetaFlags::REMOVE_ENTRY); EXPECT_EQUAL(0u, f.content.getBucketInfo().getChecksum()); } diff --git a/persistence/src/tests/spi/clusterstatetest.cpp b/persistence/src/tests/spi/clusterstatetest.cpp index 205661ba930..b044552d672 100644 --- a/persistence/src/tests/spi/clusterstatetest.cpp +++ b/persistence/src/tests/spi/clusterstatetest.cpp @@ -266,7 +266,7 @@ TEST(DocEntryTest, test_basics) { } TEST(DocEntryTest, test_meta_only) { - DocEntry::UP e = DocEntry::create(Timestamp(9), 0); + DocEntry::UP e = DocEntry::create(Timestamp(9), DocumentMetaFlags::NONE); EXPECT_EQ(9, e->getTimestamp()); EXPECT_FALSE(e->isRemove()); EXPECT_EQ(24, e->getSize()); @@ -274,13 +274,13 @@ TEST(DocEntryTest, test_meta_only) { EXPECT_EQ(nullptr, e->getDocument()); EXPECT_EQ(nullptr, e->getDocumentId()); - DocEntry::UP r = DocEntry::create(Timestamp(666), 1); + DocEntry::UP r = DocEntry::create(Timestamp(666), DocumentMetaFlags::REMOVE_ENTRY); EXPECT_EQ(666, r->getTimestamp()); EXPECT_TRUE(r->isRemove()); } TEST(DocEntryTest, test_docid_only) { - DocEntry::UP e = DocEntry::create(Timestamp(9), 0, DocumentId("id:test:test::1")); + DocEntry::UP e = DocEntry::create(Timestamp(9), DocumentMetaFlags::NONE, DocumentId("id:test:test::1")); EXPECT_EQ(9, e->getTimestamp()); EXPECT_FALSE(e->isRemove()); EXPECT_EQ(48, e->getSize()); @@ -291,7 +291,7 @@ TEST(DocEntryTest, test_docid_only) { TEST(DocEntryTest, test_document_only) { document::TestDocMan testDocMan; - DocEntry::UP e = DocEntry::create(Timestamp(9), 0, testDocMan.createRandomDocument(0, 1000)); + DocEntry::UP e = DocEntry::create(Timestamp(9), testDocMan.createRandomDocument(0, 1000)); EXPECT_EQ(9, e->getTimestamp()); EXPECT_FALSE(e->isRemove()); EXPECT_EQ(664, e->getSize()); diff --git a/persistence/src/vespa/persistence/dummyimpl/dummypersistence.cpp b/persistence/src/vespa/persistence/dummyimpl/dummypersistence.cpp index 19c03a97f05..a85c1c49752 100644 --- a/persistence/src/vespa/persistence/dummyimpl/dummypersistence.cpp +++ b/persistence/src/vespa/persistence/dummyimpl/dummypersistence.cpp @@ -435,7 +435,7 @@ DummyPersistence::putAsync(const Bucket& b, Timestamp t, Document::SP doc, Conte } } else { LOG(spam, "Inserting document %s", doc->toString(true).c_str()); - auto entry = DocEntry::create(t, NONE, Document::UP(doc->clone())); + auto entry = DocEntry::create(t, Document::UP(doc->clone())); (*bc)->insert(std::move(entry)); bc.reset(); onComplete->onComplete(std::make_unique<Result>()); @@ -493,7 +493,7 @@ DummyPersistence::removeAsync(const Bucket& b, std::vector<TimeStampAndDocumentI } DocEntry::SP entry((*bc)->getEntry(id)); numRemoves += (entry.get() && !entry->isRemove()) ? 1 : 0; - auto remEntry = DocEntry::create(t, REMOVE_ENTRY, id); + auto remEntry = DocEntry::create(t, DocumentMetaFlags::REMOVE_ENTRY, id); if ((*bc)->hasTimestamp(t)) { (*bc)->eraseEntry(t); @@ -658,8 +658,7 @@ DummyPersistence::iterate(IteratorId id, uint64_t maxByteSize, Context& ctx) con assert(entry->getDocument()); // Create new document with only wanted fields. Document::UP filtered(FieldSet::createDocumentSubsetCopy(*entry->getDocument(), *it->_fieldSet)); - auto ret = DocEntry::create(entry->getTimestamp(), entry->getFlags(), - std::move(filtered), entry->getDocumentSize()); + auto ret = DocEntry::create(entry->getTimestamp(), std::move(filtered), entry->getDocumentSize()); entries.push_back(std::move(ret)); } else { // Use entry as-is. diff --git a/persistence/src/vespa/persistence/spi/docentry.cpp b/persistence/src/vespa/persistence/spi/docentry.cpp index e586b4e414f..3235de25d46 100644 --- a/persistence/src/vespa/persistence/spi/docentry.cpp +++ b/persistence/src/vespa/persistence/spi/docentry.cpp @@ -11,7 +11,7 @@ namespace { class DocEntryWithId final : public DocEntry { public: - DocEntryWithId(Timestamp t, int metaFlags, const DocumentId &docId); + DocEntryWithId(Timestamp t, DocumentMetaFlags metaFlags, const DocumentId &docId); ~DocEntryWithId(); vespalib::string toString() const override; const DocumentId* getDocumentId() const override { return _documentId.get(); } @@ -22,7 +22,7 @@ private: class DocEntryWithDoc final : public DocEntry { public: - DocEntryWithDoc(Timestamp t, int metaFlags, DocumentUP doc); + DocEntryWithDoc(Timestamp t, DocumentUP doc); /** * Constructor that can be used by providers that already know @@ -30,7 +30,7 @@ public: * call to getSerializedSize can be avoided. This value shall be the size of the document _before_ * any field filtering is performed. */ - DocEntryWithDoc(Timestamp t, int metaFlags, DocumentUP doc, size_t serializedDocumentSize); + DocEntryWithDoc(Timestamp t, DocumentUP doc, size_t serializedDocumentSize); ~DocEntryWithDoc(); vespalib::string toString() const override; const Document* getDocument() const override { return _document.get(); } @@ -41,17 +41,17 @@ private: DocumentUP _document; }; -DocEntryWithDoc::DocEntryWithDoc(Timestamp t, int metaFlags, DocumentUP doc) - : DocEntry(t, metaFlags, doc->serialize().size()), +DocEntryWithDoc::DocEntryWithDoc(Timestamp t, DocumentUP doc) + : DocEntry(t, DocumentMetaFlags::NONE, doc->serialize().size()), _document(std::move(doc)) { } -DocEntryWithDoc::DocEntryWithDoc(Timestamp t, int metaFlags, DocumentUP doc, size_t serializedDocumentSize) - : DocEntry(t, metaFlags, serializedDocumentSize), +DocEntryWithDoc::DocEntryWithDoc(Timestamp t, DocumentUP doc, size_t serializedDocumentSize) + : DocEntry(t, DocumentMetaFlags::NONE, serializedDocumentSize), _document(std::move(doc)) { } -DocEntryWithId::DocEntryWithId(Timestamp t, int metaFlags, const DocumentId& docId) +DocEntryWithId::DocEntryWithId(Timestamp t, DocumentMetaFlags metaFlags, const DocumentId& docId) : DocEntry(t, metaFlags, docId.getSerializedSize()), _documentId(std::make_unique<DocumentId>(docId)) { } @@ -63,7 +63,7 @@ vespalib::string DocEntryWithId::toString() const { std::ostringstream out; - out << "DocEntry(" << getTimestamp() << ", " << getFlags() << ", " << *_documentId << ")"; + out << "DocEntry(" << getTimestamp() << ", " << int(getFlags()) << ", " << *_documentId << ")"; return out.str(); } @@ -71,7 +71,7 @@ vespalib::string DocEntryWithDoc::toString() const { std::ostringstream out; - out << "DocEntry(" << getTimestamp() << ", " << getFlags() << ", "; + out << "DocEntry(" << getTimestamp() << ", " << int(getFlags()) << ", "; if (_document.get()) { out << "Doc(" << _document->getId() << ")"; } else { @@ -84,20 +84,20 @@ DocEntryWithDoc::toString() const } DocEntry::UP -DocEntry::create(Timestamp t, int metaFlags) { - return std::make_unique<DocEntry>(t, metaFlags); +DocEntry::create(Timestamp t, DocumentMetaFlags metaFlags) { + return UP(new DocEntry(t, metaFlags)); } DocEntry::UP -DocEntry::create(Timestamp t, int metaFlags, const DocumentId &docId) { +DocEntry::create(Timestamp t, DocumentMetaFlags metaFlags, const DocumentId &docId) { return std::make_unique<DocEntryWithId>(t, metaFlags, docId); } DocEntry::UP -DocEntry::create(Timestamp t, int metaFlags, DocumentUP doc) { - return std::make_unique<DocEntryWithDoc>(t, metaFlags, std::move(doc)); +DocEntry::create(Timestamp t, DocumentUP doc) { + return std::make_unique<DocEntryWithDoc>(t, std::move(doc)); } DocEntry::UP -DocEntry::create(Timestamp t, int metaFlags, DocumentUP doc, SizeType serializedDocumentSize) { - return std::make_unique<DocEntryWithDoc>(t, metaFlags, std::move(doc), serializedDocumentSize); +DocEntry::create(Timestamp t, DocumentUP doc, SizeType serializedDocumentSize) { + return std::make_unique<DocEntryWithDoc>(t, std::move(doc), serializedDocumentSize); } DocEntry::~DocEntry() = default; @@ -111,7 +111,7 @@ vespalib::string DocEntry::toString() const { std::ostringstream out; - out << "DocEntry(" << _timestamp << ", " << _metaFlags << ", metadata only)"; + out << "DocEntry(" << _timestamp << ", " << int(_metaFlags) << ", metadata only)"; return out.str(); } diff --git a/persistence/src/vespa/persistence/spi/docentry.h b/persistence/src/vespa/persistence/spi/docentry.h index 90be8eedc0c..d2da3f03881 100644 --- a/persistence/src/vespa/persistence/spi/docentry.h +++ b/persistence/src/vespa/persistence/spi/docentry.h @@ -17,7 +17,7 @@ namespace storage::spi { -enum DocumentMetaFlags { +enum class DocumentMetaFlags { NONE = 0x0, REMOVE_ENTRY = 0x1 }; @@ -28,15 +28,14 @@ public: using UP = std::unique_ptr<DocEntry>; using SP = std::shared_ptr<DocEntry>; - DocEntry(Timestamp t, int metaFlags) : DocEntry(t, metaFlags, 0) { } DocEntry(const DocEntry &) = delete; DocEntry & operator=(const DocEntry &) = delete; DocEntry(DocEntry &&) = delete; DocEntry & operator=(DocEntry &&) = delete; virtual ~DocEntry(); - bool isRemove() const { return (_metaFlags & REMOVE_ENTRY); } + bool isRemove() const { return (_metaFlags == DocumentMetaFlags::REMOVE_ENTRY); } Timestamp getTimestamp() const { return _timestamp; } - int getFlags() const { return _metaFlags; } + DocumentMetaFlags getFlags() const { return _metaFlags; } /** * @return In-memory size of this doc entry, including document instance. * In essence: serialized size of document + sizeof(DocEntry). @@ -55,19 +54,20 @@ public: virtual const Document* getDocument() const { return nullptr; } virtual const DocumentId* getDocumentId() const { return nullptr; } virtual DocumentUP releaseDocument(); - static UP create(Timestamp t, int metaFlags); - static UP create(Timestamp t, int metaFlags, const DocumentId &docId); - static UP create(Timestamp t, int metaFlags, DocumentUP doc); - static UP create(Timestamp t, int metaFlags, DocumentUP doc, SizeType serializedDocumentSize); + static UP create(Timestamp t, DocumentMetaFlags metaFlags); + static UP create(Timestamp t, DocumentMetaFlags metaFlags, const DocumentId &docId); + static UP create(Timestamp t, DocumentUP doc); + static UP create(Timestamp t, DocumentUP doc, SizeType serializedDocumentSize); protected: - DocEntry(Timestamp t, int metaFlags, SizeType size) + DocEntry(Timestamp t, DocumentMetaFlags metaFlags, SizeType size) : _timestamp(t), _metaFlags(metaFlags), _size(size) {} private: + DocEntry(Timestamp t, DocumentMetaFlags metaFlags) : DocEntry(t, metaFlags, 0) { } Timestamp _timestamp; - int _metaFlags; + DocumentMetaFlags _metaFlags; SizeType _size; }; diff --git a/persistence/src/vespa/persistence/spi/test.cpp b/persistence/src/vespa/persistence/spi/test.cpp index 0f10b839f98..9aaa26adb59 100644 --- a/persistence/src/vespa/persistence/spi/test.cpp +++ b/persistence/src/vespa/persistence/spi/test.cpp @@ -21,9 +21,7 @@ std::unique_ptr<DocEntry> cloneDocEntry(const DocEntry & e) { std::unique_ptr<DocEntry> ret; if (e.getDocument()) { - ret = DocEntry::create(e.getTimestamp(), e.getFlags(), - std::make_unique<Document>(*e.getDocument()), - e.getDocumentSize()); + ret = DocEntry::create(e.getTimestamp(), std::make_unique<Document>(*e.getDocument()), e.getDocumentSize()); } else if (e.getDocumentId()) { ret = DocEntry::create(e.getTimestamp(), e.getFlags(), *e.getDocumentId()); } else { diff --git a/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp b/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp index 209523cd0aa..9df5de567f5 100644 --- a/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp +++ b/searchcore/src/tests/proton/document_iterator/document_iterator_test.cpp @@ -48,6 +48,7 @@ using storage::spi::IncludedVersions; using storage::spi::IterateResult; using storage::spi::Selection; using storage::spi::Timestamp; +using storage::spi::DocumentMetaFlags; using storage::spi::test::makeSpiBucket; using storage::spi::test::equal; @@ -383,7 +384,7 @@ void checkDoc(const IDocumentRetriever &dr, const std::string &id, EXPECT_TRUE(DocumentId(id) == doc->getId()); } -void checkEntry(const IterateResult &res, size_t idx, const Timestamp ×tamp, int flags) +void checkEntry(const IterateResult &res, size_t idx, const Timestamp ×tamp, DocumentMetaFlags flags) { ASSERT_LESS(idx, res.getEntries().size()); auto expect = DocEntry::create(timestamp, flags); @@ -394,7 +395,7 @@ void checkEntry(const IterateResult &res, size_t idx, const Timestamp ×tamp void checkEntry(const IterateResult &res, size_t idx, const DocumentId &id, const Timestamp ×tamp) { ASSERT_LESS(idx, res.getEntries().size()); - auto expect = DocEntry::create(timestamp, storage::spi::REMOVE_ENTRY, id); + auto expect = DocEntry::create(timestamp, DocumentMetaFlags::REMOVE_ENTRY, id); EXPECT_TRUE(equal(*expect, *res.getEntries()[idx])); EXPECT_EQUAL(getSize(id), res.getEntries()[idx]->getDocumentSize()); EXPECT_GREATER(getSize(id), 0u); @@ -403,7 +404,7 @@ void checkEntry(const IterateResult &res, size_t idx, const DocumentId &id, cons void checkEntry(const IterateResult &res, size_t idx, const Document &doc, const Timestamp ×tamp) { ASSERT_LESS(idx, res.getEntries().size()); - auto expect = DocEntry::create(timestamp, storage::spi::NONE, Document::UP(doc.clone())); + auto expect = DocEntry::create(timestamp, Document::UP(doc.clone())); EXPECT_TRUE(equal(*expect, *res.getEntries()[idx])); EXPECT_EQUAL(getSize(doc), res.getEntries()[idx]->getDocumentSize()); EXPECT_GREATER(getSize(doc), 0u); @@ -605,9 +606,9 @@ TEST("require that using an empty field set returns meta-data only") { IterateResult res = itr.iterate(largeNum); EXPECT_TRUE(res.isCompleted()); EXPECT_EQUAL(3u, res.getEntries().size()); - TEST_DO(checkEntry(res, 0, Timestamp(2), storage::spi::NONE)); - TEST_DO(checkEntry(res, 1, Timestamp(3), storage::spi::NONE)); - TEST_DO(checkEntry(res, 2, Timestamp(4), storage::spi::REMOVE_ENTRY)); + TEST_DO(checkEntry(res, 0, Timestamp(2), DocumentMetaFlags::NONE)); + TEST_DO(checkEntry(res, 1, Timestamp(3), DocumentMetaFlags::NONE)); + TEST_DO(checkEntry(res, 2, Timestamp(4), DocumentMetaFlags::REMOVE_ENTRY)); } TEST("require that entries in other buckets are skipped") { @@ -650,12 +651,12 @@ TEST("require that maxBytes splits iteration results for meta-data only iteratio IterateResult res1 = itr.iterate(2 * sizeof(DocEntry)); EXPECT_TRUE(!res1.isCompleted()); EXPECT_EQUAL(2u, res1.getEntries().size()); - TEST_DO(checkEntry(res1, 0, Timestamp(2), storage::spi::NONE)); - TEST_DO(checkEntry(res1, 1, Timestamp(3), storage::spi::REMOVE_ENTRY)); + TEST_DO(checkEntry(res1, 0, Timestamp(2), DocumentMetaFlags::NONE)); + TEST_DO(checkEntry(res1, 1, Timestamp(3), DocumentMetaFlags::REMOVE_ENTRY)); IterateResult res2 = itr.iterate(largeNum); EXPECT_TRUE(res2.isCompleted()); - TEST_DO(checkEntry(res2, 0, Timestamp(4), storage::spi::NONE)); + TEST_DO(checkEntry(res2, 0, Timestamp(4), DocumentMetaFlags::NONE)); IterateResult res3 = itr.iterate(largeNum); EXPECT_TRUE(res3.isCompleted()); diff --git a/searchcore/src/vespa/searchcore/proton/persistenceengine/document_iterator.cpp b/searchcore/src/vespa/searchcore/proton/persistenceengine/document_iterator.cpp index 39c93a0dd1a..a798b2c2f93 100644 --- a/searchcore/src/vespa/searchcore/proton/persistenceengine/document_iterator.cpp +++ b/searchcore/src/vespa/searchcore/proton/persistenceengine/document_iterator.cpp @@ -18,6 +18,7 @@ using storage::spi::DocEntry; using storage::spi::Timestamp; using document::Document; using document::DocumentId; +using storage::spi::DocumentMetaFlags; namespace proton { @@ -25,18 +26,17 @@ namespace { std::unique_ptr<DocEntry> createDocEntry(Timestamp timestamp, bool removed) { - int flags = removed ? storage::spi::REMOVE_ENTRY : storage::spi::NONE; - return std::make_unique<DocEntry>(timestamp, flags); + return DocEntry::create(timestamp, removed ? DocumentMetaFlags::REMOVE_ENTRY : DocumentMetaFlags::NONE); } std::unique_ptr<DocEntry> createDocEntry(Timestamp timestamp, bool removed, Document::UP doc, ssize_t defaultSerializedSize) { if (doc) { if (removed) { - return DocEntry::create(timestamp, storage::spi::REMOVE_ENTRY, doc->getId()); + return DocEntry::create(timestamp, DocumentMetaFlags::REMOVE_ENTRY, doc->getId()); } else { ssize_t serializedSize = defaultSerializedSize >= 0 ? defaultSerializedSize : doc->serialize().size(); - return DocEntry::create(timestamp, storage::spi::NONE, std::move(doc), serializedSize); + return DocEntry::create(timestamp, std::move(doc), serializedSize); } } else { return createDocEntry(timestamp, removed); diff --git a/storage/src/tests/persistence/testandsettest.cpp b/storage/src/tests/persistence/testandsettest.cpp index 56e20309c17..f6e48d6c325 100644 --- a/storage/src/tests/persistence/testandsettest.cpp +++ b/storage/src/tests/persistence/testandsettest.cpp @@ -74,7 +74,7 @@ struct TestAndSetTest : PersistenceTestUtils { static std::string expectedDocEntryString( api::Timestamp timestamp, const document::DocumentId & testDocId, - spi::DocumentMetaFlags removeFlag = spi::NONE); + spi::DocumentMetaFlags removeFlag = spi::DocumentMetaFlags::NONE); }; TEST_F(TestAndSetTest, conditional_put_not_executed_on_condition_mismatch) { @@ -151,7 +151,7 @@ TEST_F(TestAndSetTest, conditional_remove_executed_on_condition_match) { ASSERT_EQ(fetchResult(asyncHandler->handleRemove(*remove, createTracker(remove, BUCKET))).getResult(), api::ReturnCode::Result::OK); EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId) + - expectedDocEntryString(timestampTwo, testDocId, spi::REMOVE_ENTRY), + expectedDocEntryString(timestampTwo, testDocId, spi::DocumentMetaFlags::REMOVE_ENTRY), dumpBucket(BUCKET_ID)); } @@ -296,8 +296,8 @@ std::string TestAndSetTest::expectedDocEntryString( { std::stringstream ss; - ss << "DocEntry(" << timestamp << ", " << removeFlag << ", "; - if (removeFlag == spi::REMOVE_ENTRY) { + ss << "DocEntry(" << timestamp << ", " << int(removeFlag) << ", "; + if (removeFlag == spi::DocumentMetaFlags::REMOVE_ENTRY) { ss << docId << ")\n"; } else { ss << "Doc(" << docId << "))\n"; diff --git a/storage/src/tests/visiting/visitortest.cpp b/storage/src/tests/visiting/visitortest.cpp index 82ccdb60736..945a08d910e 100644 --- a/storage/src/tests/visiting/visitortest.cpp +++ b/storage/src/tests/visiting/visitortest.cpp @@ -24,6 +24,8 @@ using namespace std::chrono_literals; using document::test::makeBucketSpace; +using document::Document; +using document::DocumentId; using namespace ::testing; namespace storage { @@ -55,7 +57,7 @@ struct TestParams { struct VisitorTest : Test { static uint32_t docCount; - std::vector<document::Document::SP > _documents; + std::vector<Document::SP> _documents; std::unique_ptr<TestVisitorMessageSessionFactory> _messageSessionFactory; std::unique_ptr<TestServiceLayerApp> _node; std::unique_ptr<DummyStorageLink> _top; @@ -93,11 +95,11 @@ struct VisitorTest : Test { void getMessagesAndReply( int expectedCount, TestVisitorMessageSession& session, - std::vector<document::Document::SP >& docs, - std::vector<document::DocumentId>& docIds, + std::vector<Document::SP> & docs, + std::vector<DocumentId>& docIds, std::vector<std::string>& infoMessages, api::ReturnCode::Result returnCode = api::ReturnCode::OK); - uint32_t getMatchingDocuments(std::vector<document::Document::SP >& docs); + uint32_t getMatchingDocuments(std::vector<Document::SP>& docs); protected: void doTestVisitorInstanceHasConsistencyLevel( @@ -213,7 +215,7 @@ VisitorTest::initializeTest(const TestParams& params) uri << "id:test:testdoctype1:n=" << i % 10 << ":http://www.ntnu.no/" << i << ".html"; - _documents.push_back(document::Document::SP( + _documents.push_back(Document::SP( _node->getTestDocMan().createDocument(content, uri.str()))); const document::DocumentType& type(_documents.back()->getType()); _documents.back()->setValue(type.getField("headerval"), @@ -276,8 +278,8 @@ void VisitorTest::getMessagesAndReply( int expectedCount, TestVisitorMessageSession& session, - std::vector<document::Document::SP >& docs, - std::vector<document::DocumentId>& docIds, + std::vector<Document::SP >& docs, + std::vector<DocumentId>& docIds, std::vector<std::string>& infoMessages, api::ReturnCode::Result result) { @@ -352,7 +354,7 @@ VisitorTest::verifyCreateVisitorReply( } uint32_t -VisitorTest::getMatchingDocuments(std::vector<document::Document::SP >& docs) { +VisitorTest::getMatchingDocuments(std::vector<Document::SP >& docs) { uint32_t equalCount = 0; for (uint32_t i=0; i<docs.size(); ++i) { for (uint32_t j=0; j<_documents.size(); ++j) { @@ -382,8 +384,7 @@ VisitorTest::sendGetIterReply(GetIterCommand& cmd, assert(maxDocuments < _documents.size()); size_t documentCount = maxDocuments != 0 ? maxDocuments : _documents.size(); for (size_t i = 0; i < documentCount; ++i) { - reply->getEntries().push_back(spi::DocEntry::create(spi::Timestamp(1000 + i), spi::NONE, - document::Document::UP(_documents[i]->clone()))); + reply->getEntries().push_back(spi::DocEntry::create(spi::Timestamp(1000 + i), Document::UP(_documents[i]->clone()))); } if (documentCount == _documents.size() || overrideCompleted) { reply->setCompleted(); @@ -479,8 +480,8 @@ TEST_F(VisitorTest, normal_usage) { sendGetIterReply(*getIterCmd); - std::vector<document::Document::SP> docs; - std::vector<document::DocumentId> docIds; + std::vector<Document::SP> docs; + std::vector<DocumentId> docIds; std::vector<std::string> infoMessages; getMessagesAndReply(_documents.size(), getSession(0), docs, docIds, infoMessages); ASSERT_EQ(0, infoMessages.size()); @@ -545,8 +546,8 @@ TEST_F(VisitorTest, document_api_client_error) { sendGetIterReply(*getIterCmd, api::ReturnCode(api::ReturnCode::OK), 1); } - std::vector<document::Document::SP> docs; - std::vector<document::DocumentId> docIds; + std::vector<Document::SP> docs; + std::vector<DocumentId> docIds; std::vector<std::string> infoMessages; getMessagesAndReply(1, getSession(0), docs, docIds, infoMessages, api::ReturnCode::INTERNAL_FAILURE); @@ -585,8 +586,8 @@ TEST_F(VisitorTest, no_document_api_resending_for_failed_visitor) { sendGetIterReply(*getIterCmd, api::ReturnCode(api::ReturnCode::OK), 2, true); } - std::vector<document::Document::SP> docs; - std::vector<document::DocumentId> docIds; + std::vector<Document::SP> docs; + std::vector<DocumentId> docIds; std::vector<std::string> infoMessages; // Use non-critical result. Visitor info message should be received // after we send a NOT_CONNECTED reply. Failing this message as well @@ -688,8 +689,8 @@ TEST_F(VisitorTest, no_visitor_notification_for_transient_failures) { ASSERT_NO_FATAL_FAILURE(initializeTest()); ASSERT_NO_FATAL_FAILURE(sendInitialCreateVisitorAndGetIterRound()); - std::vector<document::Document::SP> docs; - std::vector<document::DocumentId> docIds; + std::vector<Document::SP> docs; + std::vector<DocumentId> docIds; std::vector<std::string> infoMessages; // Have to make sure time increases in visitor thread so that resend // times are reached. @@ -732,8 +733,8 @@ TEST_F(VisitorTest, notification_sent_if_transient_error_retried_many_times) { ASSERT_NO_FATAL_FAILURE(initializeTest()); sendInitialCreateVisitorAndGetIterRound(); - std::vector<document::Document::SP> docs; - std::vector<document::DocumentId> docIds; + std::vector<Document::SP> docs; + std::vector<DocumentId> docIds; std::vector<std::string> infoMessages; // Have to make sure time increases in visitor thread so that resend // times are reached. @@ -772,8 +773,8 @@ VisitorTest::doCompleteVisitingSession( 1, true); - std::vector<document::Document::SP> docs; - std::vector<document::DocumentId> docIds; + std::vector<Document::SP> docs; + std::vector<DocumentId> docIds; std::vector<std::string> infoMessages; getMessagesAndReply(1, getSession(0), docs, docIds, infoMessages); @@ -833,8 +834,8 @@ TEST_F(VisitorTest, no_more_iterators_sent_while_memory_used_above_limit) { std::this_thread::sleep_for(100ms); ASSERT_EQ(0, _bottom->getNumCommands()); - std::vector<document::Document::SP> docs; - std::vector<document::DocumentId> docIds; + std::vector<Document::SP> docs; + std::vector<DocumentId> docIds; std::vector<std::string> infoMessages; getMessagesAndReply(1, getSession(0), docs, docIds, infoMessages); @@ -896,8 +897,8 @@ struct ReindexingVisitorTest : VisitorTest { void respond_to_client_put(api::ReturnCode::Result result) { // Reply to the Put from "client" back to the visitor - std::vector<document::Document::SP> docs; - std::vector<document::DocumentId> doc_ids; + std::vector<Document::SP> docs; + std::vector<DocumentId> doc_ids; std::vector<std::string> info_messages; getMessagesAndReply(1, getSession(0), docs, doc_ids, info_messages, result); } diff --git a/streamingvisitors/src/tests/searchvisitor/searchvisitor_test.cpp b/streamingvisitors/src/tests/searchvisitor/searchvisitor_test.cpp index fcbff9a0dbb..d36819f1536 100644 --- a/streamingvisitors/src/tests/searchvisitor/searchvisitor_test.cpp +++ b/streamingvisitors/src/tests/searchvisitor/searchvisitor_test.cpp @@ -61,8 +61,7 @@ createDocuments(const vespalib::string & dir) (void) dir; std::vector<spi::DocEntry::UP> documents; spi::Timestamp ts; - document::Document::UP doc(new document::Document()); - auto e = spi::DocEntry::create(ts, 0, std::move(doc)); + auto e = spi::DocEntry::create(ts, std::make_unique<Document>()); documents.push_back(std::move(e)); return documents; } |