diff options
Diffstat (limited to 'storage/src/tests/distributor/updateoperationtest.cpp')
-rw-r--r-- | storage/src/tests/distributor/updateoperationtest.cpp | 140 |
1 files changed, 52 insertions, 88 deletions
diff --git a/storage/src/tests/distributor/updateoperationtest.cpp b/storage/src/tests/distributor/updateoperationtest.cpp index 67cd4f5f233..7cf3ea0ad18 100644 --- a/storage/src/tests/distributor/updateoperationtest.cpp +++ b/storage/src/tests/distributor/updateoperationtest.cpp @@ -1,7 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <cppunit/extensions/HelperMacros.h> -#include <iomanip> #include <tests/common/dummystoragelink.h> #include <vespa/storageapi/message/persistence.h> #include <vespa/storageapi/message/state.h> @@ -11,56 +9,39 @@ #include <vespa/document/update/documentupdate.h> #include <vespa/document/test/make_document_bucket.h> #include <vespa/storage/distributor/operations/external/updateoperation.h> -#include <vespa/vespalib/testkit/test_kit.h> #include <vespa/storage/distributor/distributor.h> #include <vespa/config/helper/configgetter.hpp> +#include <vespa/vespalib/gtest/gtest.h> -using std::shared_ptr; using namespace document; using namespace storage; using namespace storage::distributor; using namespace storage::api; using namespace std; using namespace storage::lib; +using namespace ::testing; using config::ConfigGetter; using config::FileSpec; using vespalib::string; using document::test::makeDocumentBucket; -class UpdateOperation_Test : public CppUnit::TestFixture, - public DistributorTestUtil -{ - CPPUNIT_TEST_SUITE(UpdateOperation_Test); - CPPUNIT_TEST(testSimple); - CPPUNIT_TEST(testNotFound); - CPPUNIT_TEST(testMultiNode); - CPPUNIT_TEST(testMultiNodeInconsistentTimestamp); - CPPUNIT_TEST_SUITE_END(); - +struct UpdateOperationTest : Test, DistributorTestUtil { std::shared_ptr<const DocumentTypeRepo> _repo; - const DocumentType *_html_type; - -protected: - void testSimple(); - void testNotFound(); - void testMultiNode(); - void testMultiNodeInconsistentTimestamp(); + const DocumentType* _html_type; -public: - void setUp() override { + void SetUp() override { _repo.reset( new DocumentTypeRepo(*ConfigGetter<DocumenttypesConfig>:: - getConfig("config-doctypes", - FileSpec(TEST_PATH("config-doctypes.cfg"))))); + getConfig("config-doctypes", FileSpec("../config-doctypes.cfg")))); _html_type = _repo->getDocumentType("text/html"); createLinks(); } - void tearDown() override { + void TearDown() override { close(); } - void replyToMessage(UpdateOperation& callback, MessageSenderStub& sender, uint32_t index, + void replyToMessage(UpdateOperation& callback, DistributorMessageSenderStub& sender, uint32_t index, uint64_t oldTimestamp, const api::BucketInfo& info = api::BucketInfo(2,4,6)); std::shared_ptr<UpdateOperation> @@ -69,133 +50,116 @@ public: document::BucketId _bId; }; -CPPUNIT_TEST_SUITE_REGISTRATION(UpdateOperation_Test); - std::shared_ptr<UpdateOperation> -UpdateOperation_Test::sendUpdate(const std::string& bucketState) +UpdateOperationTest::sendUpdate(const std::string& bucketState) { - document::DocumentUpdate::SP update( - new document::DocumentUpdate(*_repo, *_html_type, - document::DocumentId(document::DocIdString("test", "test")))); + auto update = std::make_shared<document::DocumentUpdate>( + *_repo, *_html_type, + document::DocumentId(document::DocIdString("test", "test"))); _bId = getExternalOperationHandler().getBucketId(update->getId()); addNodesToBucketDB(_bId, bucketState); - std::shared_ptr<api::UpdateCommand> msg( - new api::UpdateCommand(makeDocumentBucket(document::BucketId(0)), update, 100)); + auto msg = std::make_shared<api::UpdateCommand>(makeDocumentBucket(document::BucketId(0)), update, 100); ExternalOperationHandler& handler = getExternalOperationHandler(); - return std::shared_ptr<UpdateOperation>( - new UpdateOperation(handler, getDistributorBucketSpace(), msg, - getDistributor().getMetrics().updates[msg->getLoadType()])); + return std::make_shared<UpdateOperation>( + handler, getDistributorBucketSpace(), msg, + getDistributor().getMetrics().updates[msg->getLoadType()]); } void -UpdateOperation_Test::replyToMessage(UpdateOperation& callback, MessageSenderStub& sender, uint32_t index, +UpdateOperationTest::replyToMessage(UpdateOperation& callback, DistributorMessageSenderStub& sender, uint32_t index, uint64_t oldTimestamp, const api::BucketInfo& info) { - std::shared_ptr<api::StorageMessage> msg2 = sender.commands[index]; - UpdateCommand* updatec = dynamic_cast<UpdateCommand*>(msg2.get()); + std::shared_ptr<api::StorageMessage> msg2 = sender.command(index); + auto* updatec = dynamic_cast<UpdateCommand*>(msg2.get()); std::unique_ptr<api::StorageReply> reply(updatec->makeReply()); - UpdateReply* updateR = static_cast<api::UpdateReply*>(reply.get()); + auto* updateR = static_cast<api::UpdateReply*>(reply.get()); updateR->setOldTimestamp(oldTimestamp); updateR->setBucketInfo(info); callback.onReceive(sender, std::shared_ptr<StorageReply>(reply.release())); } -void -UpdateOperation_Test::testSimple() -{ +TEST_F(UpdateOperationTest, simple) { setupDistributor(1, 1, "storage:1 distributor:1"); std::shared_ptr<UpdateOperation> cb(sendUpdate("0=1/2/3")); - MessageSenderStub sender; + DistributorMessageSenderStub sender; cb->start(sender, framework::MilliSecTime(0)); - CPPUNIT_ASSERT_EQUAL(std::string("Update => 0"), sender.getCommands(true)); + ASSERT_EQ("Update => 0", sender.getCommands(true)); replyToMessage(*cb, sender, 0, 90); - CPPUNIT_ASSERT_EQUAL( - std::string("UpdateReply(doc:test:test, BucketId(0x0000000000000000), " - "timestamp 100, timestamp of updated doc: 90) ReturnCode(NONE)"), - sender.getLastReply(true)); + ASSERT_EQ("UpdateReply(doc:test:test, BucketId(0x0000000000000000), " + "timestamp 100, timestamp of updated doc: 90) ReturnCode(NONE)", + sender.getLastReply(true)); auto& metrics = getDistributor().getMetrics().updates[documentapi::LoadType::DEFAULT]; - CPPUNIT_ASSERT_EQUAL(UINT64_C(0), metrics.diverging_timestamp_updates.getValue()); + EXPECT_EQ(0, metrics.diverging_timestamp_updates.getValue()); } -void -UpdateOperation_Test::testNotFound() -{ +TEST_F(UpdateOperationTest, not_found) { setupDistributor(1, 1, "storage:1 distributor:1"); std::shared_ptr<UpdateOperation> cb(sendUpdate("0=1/2/3")); - MessageSenderStub sender; + DistributorMessageSenderStub sender; cb->start(sender, framework::MilliSecTime(0)); - CPPUNIT_ASSERT_EQUAL(std::string("Update => 0"), sender.getCommands(true)); + ASSERT_EQ("Update => 0", sender.getCommands(true)); replyToMessage(*cb, sender, 0, 0); - CPPUNIT_ASSERT_EQUAL( - std::string("UpdateReply(doc:test:test, BucketId(0x0000000000000000), " - "timestamp 100, timestamp of updated doc: 0) ReturnCode(NONE)"), - sender.getLastReply(true)); + EXPECT_EQ("UpdateReply(doc:test:test, BucketId(0x0000000000000000), " + "timestamp 100, timestamp of updated doc: 0) ReturnCode(NONE)", + sender.getLastReply(true)); } -void -UpdateOperation_Test::testMultiNode() -{ +TEST_F(UpdateOperationTest, multi_node) { setupDistributor(2, 2, "distributor:1 storage:2"); std::shared_ptr<UpdateOperation> cb(sendUpdate("0=1/2/3,1=1/2/3")); - MessageSenderStub sender; + DistributorMessageSenderStub sender; cb->start(sender, framework::MilliSecTime(0)); - CPPUNIT_ASSERT_EQUAL(std::string("Update => 0,Update => 1"), sender.getCommands(true)); + ASSERT_EQ("Update => 0,Update => 1", sender.getCommands(true)); replyToMessage(*cb, sender, 0, 120); replyToMessage(*cb, sender, 1, 120); - CPPUNIT_ASSERT_EQUAL( - std::string("UpdateReply(doc:test:test, BucketId(0x0000000000000000), " - "timestamp 100, timestamp of updated doc: 120) ReturnCode(NONE)"), - sender.getLastReply(true)); + ASSERT_EQ("UpdateReply(doc:test:test, BucketId(0x0000000000000000), " + "timestamp 100, timestamp of updated doc: 120) ReturnCode(NONE)", + sender.getLastReply(true)); - CPPUNIT_ASSERT_EQUAL( - std::string( - _bId.toString() + " : " - "node(idx=1,crc=0x2,docs=4/4,bytes=6/6,trusted=true,active=false,ready=false), " - "node(idx=0,crc=0x2,docs=4/4,bytes=6/6,trusted=true,active=false,ready=false)"), - dumpBucket(_bId)); + ASSERT_EQ(_bId.toString() + " : " + "node(idx=1,crc=0x2,docs=4/4,bytes=6/6,trusted=true,active=false,ready=false), " + "node(idx=0,crc=0x2,docs=4/4,bytes=6/6,trusted=true,active=false,ready=false)", + dumpBucket(_bId)); auto& metrics = getDistributor().getMetrics().updates[documentapi::LoadType::DEFAULT]; - CPPUNIT_ASSERT_EQUAL(UINT64_C(0), metrics.diverging_timestamp_updates.getValue()); + EXPECT_EQ(0, metrics.diverging_timestamp_updates.getValue()); } -void -UpdateOperation_Test::testMultiNodeInconsistentTimestamp() -{ +TEST_F(UpdateOperationTest, multi_node_inconsistent_timestamp) { setupDistributor(2, 2, "distributor:1 storage:2"); std::shared_ptr<UpdateOperation> cb(sendUpdate("0=1/2/3,1=1/2/3")); - MessageSenderStub sender; + DistributorMessageSenderStub sender; cb->start(sender, framework::MilliSecTime(0)); - CPPUNIT_ASSERT_EQUAL(std::string("Update => 0,Update => 1"), sender.getCommands(true)); + ASSERT_EQ("Update => 0,Update => 1", sender.getCommands(true)); replyToMessage(*cb, sender, 0, 119); replyToMessage(*cb, sender, 1, 120); - CPPUNIT_ASSERT_EQUAL( - std::string("UpdateReply(doc:test:test, BucketId(0x0000000000000000), " - "timestamp 100, timestamp of updated doc: 120 Was inconsistent " - "(best node 1)) ReturnCode(NONE)"), - sender.getLastReply(true)); + ASSERT_EQ("UpdateReply(doc:test:test, BucketId(0x0000000000000000), " + "timestamp 100, timestamp of updated doc: 120 Was inconsistent " + "(best node 1)) ReturnCode(NONE)", + sender.getLastReply(true)); auto& metrics = getDistributor().getMetrics().updates[documentapi::LoadType::DEFAULT]; - CPPUNIT_ASSERT_EQUAL(UINT64_C(1), metrics.diverging_timestamp_updates.getValue()); + EXPECT_EQ(1, metrics.diverging_timestamp_updates.getValue()); } |