diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-14 13:50:54 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-06-14 13:50:54 +0200 |
commit | 799acc9335f0dc3eebc747db8397aef0b4d930a9 (patch) | |
tree | 051baee0f938c2b088daa4a0fcb9120993abd95c /storage/src/tests/persistence/testandsettest.cpp | |
parent | 7e2d577daf548e171a7d7bf16a6996f9b894c330 (diff) | |
parent | 1b2c6aa193483f9a7eaaf17a5a82037b93bd1749 (diff) |
Merge with master
Diffstat (limited to 'storage/src/tests/persistence/testandsettest.cpp')
-rw-r--r-- | storage/src/tests/persistence/testandsettest.cpp | 153 |
1 files changed, 58 insertions, 95 deletions
diff --git a/storage/src/tests/persistence/testandsettest.cpp b/storage/src/tests/persistence/testandsettest.cpp index 197aa95fc22..4c4a7c9a0be 100644 --- a/storage/src/tests/persistence/testandsettest.cpp +++ b/storage/src/tests/persistence/testandsettest.cpp @@ -1,6 +1,5 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. // @author Vegard Sjonfjell -#include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/storage/persistence/persistencethread.h> #include <tests/persistence/persistencetestutils.h> #include <vespa/document/test/make_document_bucket.h> @@ -14,14 +13,13 @@ using std::unique_ptr; using std::shared_ptr; -using namespace std::string_literals; using storage::spi::test::makeSpiBucket; using document::test::makeDocumentBucket; +using namespace ::testing; namespace storage { -class TestAndSetTest : public SingleDiskPersistenceTestUtils -{ +struct TestAndSetTest : SingleDiskPersistenceTestUtils { static constexpr int MIN_DOCUMENT_SIZE = 0; static constexpr int MAX_DOCUMENT_SIZE = 128; static constexpr int RANDOM_SEED = 1234; @@ -36,9 +34,8 @@ class TestAndSetTest : public SingleDiskPersistenceTestUtils shared_ptr<document::Document> testDoc; document::DocumentId testDocId; -public: - void setUp() override { - SingleDiskPersistenceTestUtils::setUp(); + void SetUp() override { + SingleDiskPersistenceTestUtils::SetUp(); spi::Context context( spi::LoadType(0, "default"), @@ -55,38 +52,11 @@ public: testDocId = testDoc->getId(); } - void tearDown() override { + void TearDown() override { thread.reset(nullptr); - SingleDiskPersistenceTestUtils::tearDown(); + SingleDiskPersistenceTestUtils::TearDown(); } - void conditional_put_not_executed_on_condition_mismatch(); - void conditional_put_executed_on_condition_match(); - void conditional_remove_not_executed_on_condition_mismatch(); - void conditional_remove_executed_on_condition_match(); - void conditional_update_not_executed_on_condition_mismatch(); - void conditional_update_executed_on_condition_match(); - void conditional_update_not_executed_when_no_document_and_no_auto_create(); - void conditional_update_executed_when_no_document_but_auto_create_is_enabled(); - void invalid_document_selection_should_fail(); - void conditional_put_to_non_existing_document_should_fail(); - void document_with_no_type_should_fail(); - - CPPUNIT_TEST_SUITE(TestAndSetTest); - CPPUNIT_TEST(conditional_put_not_executed_on_condition_mismatch); - CPPUNIT_TEST(conditional_put_executed_on_condition_match); - CPPUNIT_TEST(conditional_remove_not_executed_on_condition_mismatch); - CPPUNIT_TEST(conditional_remove_executed_on_condition_match); - CPPUNIT_TEST(conditional_update_not_executed_on_condition_mismatch); - CPPUNIT_TEST(conditional_update_executed_on_condition_match); - CPPUNIT_TEST(conditional_update_not_executed_when_no_document_and_no_auto_create); - CPPUNIT_TEST(conditional_update_executed_when_no_document_but_auto_create_is_enabled); - CPPUNIT_TEST(invalid_document_selection_should_fail); - CPPUNIT_TEST(conditional_put_to_non_existing_document_should_fail); - CPPUNIT_TEST(document_with_no_type_should_fail); - CPPUNIT_TEST_SUITE_END(); - -protected: std::unique_ptr<api::UpdateCommand> conditional_update_test( bool createIfMissing, api::Timestamp updateTimestamp); @@ -103,32 +73,29 @@ protected: spi::DocumentMetaFlags removeFlag = spi::NONE); }; -CPPUNIT_TEST_SUITE_REGISTRATION(TestAndSetTest); - -void TestAndSetTest::conditional_put_not_executed_on_condition_mismatch() -{ +TEST_F(TestAndSetTest, conditional_put_not_executed_on_condition_mismatch) { // Put document with mismatching header api::Timestamp timestampOne = 0; putTestDocument(false, timestampOne); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); // Conditionally replace document, but fail due to lack of woofy dog api::Timestamp timestampTwo = 1; api::PutCommand putTwo(makeDocumentBucket(BUCKET_ID), testDoc, timestampTwo); setTestCondition(putTwo); - CPPUNIT_ASSERT(thread->handlePut(putTwo)->getResult() == api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handlePut(putTwo)->getResult().getResult(), + api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); } -void TestAndSetTest::conditional_put_executed_on_condition_match() -{ +TEST_F(TestAndSetTest, conditional_put_executed_on_condition_match) { // Put document with matching header api::Timestamp timestampOne = 0; putTestDocument(true, timestampOne); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); // Update content of document testDoc->setValue(testDoc->getField("content"), NEW_CONTENT); @@ -138,51 +105,50 @@ void TestAndSetTest::conditional_put_executed_on_condition_match() api::PutCommand putTwo(makeDocumentBucket(BUCKET_ID), testDoc, timestampTwo); setTestCondition(putTwo); - CPPUNIT_ASSERT(thread->handlePut(putTwo)->getResult() == api::ReturnCode::Result::OK); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId) + - expectedDocEntryString(timestampTwo, testDocId), - dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handlePut(putTwo)->getResult().getResult(), api::ReturnCode::Result::OK); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId) + + expectedDocEntryString(timestampTwo, testDocId), + dumpBucket(BUCKET_ID)); assertTestDocumentFoundAndMatchesContent(NEW_CONTENT); } -void TestAndSetTest::conditional_remove_not_executed_on_condition_mismatch() -{ +TEST_F(TestAndSetTest, conditional_remove_not_executed_on_condition_mismatch) { // Put document with mismatching header api::Timestamp timestampOne = 0; putTestDocument(false, timestampOne); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); // Conditionally remove document, fail in doing so api::Timestamp timestampTwo = 1; api::RemoveCommand remove(makeDocumentBucket(BUCKET_ID), testDocId, timestampTwo); setTestCondition(remove); - CPPUNIT_ASSERT(thread->handleRemove(remove)->getResult() == api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handleRemove(remove)->getResult().getResult(), + api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); // Assert that the document is still there retrieveTestDocument(); } -void TestAndSetTest::conditional_remove_executed_on_condition_match() -{ +TEST_F(TestAndSetTest, conditional_remove_executed_on_condition_match) { // Put document with matching header api::Timestamp timestampOne = 0; putTestDocument(true, timestampOne); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); // Conditionally remove document, succeed in doing so api::Timestamp timestampTwo = 1; api::RemoveCommand remove(makeDocumentBucket(BUCKET_ID), testDocId, timestampTwo); setTestCondition(remove); - CPPUNIT_ASSERT(thread->handleRemove(remove)->getResult() == api::ReturnCode::Result::OK); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId) + - expectedDocEntryString(timestampTwo, testDocId, spi::REMOVE_ENTRY), - dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handleRemove(remove)->getResult().getResult(), api::ReturnCode::Result::OK); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId) + + expectedDocEntryString(timestampTwo, testDocId, spi::REMOVE_ENTRY), + dumpBucket(BUCKET_ID)); } std::unique_ptr<api::UpdateCommand> TestAndSetTest::conditional_update_test( @@ -200,66 +166,63 @@ std::unique_ptr<api::UpdateCommand> TestAndSetTest::conditional_update_test( return updateUp; } -void TestAndSetTest::conditional_update_not_executed_on_condition_mismatch() -{ +TEST_F(TestAndSetTest, conditional_update_not_executed_on_condition_mismatch) { api::Timestamp timestampOne = 0; api::Timestamp timestampTwo = 1; putTestDocument(false, timestampOne); auto updateUp = conditional_update_test(false, timestampTwo); - CPPUNIT_ASSERT(thread->handleUpdate(*updateUp)->getResult() == api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId), - dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handleUpdate(*updateUp)->getResult().getResult(), + api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId), dumpBucket(BUCKET_ID)); assertTestDocumentFoundAndMatchesContent(OLD_CONTENT); } -void TestAndSetTest::conditional_update_executed_on_condition_match() -{ +TEST_F(TestAndSetTest, conditional_update_executed_on_condition_match) { api::Timestamp timestampOne = 0; api::Timestamp timestampTwo = 1; putTestDocument(true, timestampOne); auto updateUp = conditional_update_test(false, timestampTwo); - CPPUNIT_ASSERT(thread->handleUpdate(*updateUp)->getResult() == api::ReturnCode::Result::OK); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(timestampOne, testDocId) + - expectedDocEntryString(timestampTwo, testDocId), - dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handleUpdate(*updateUp)->getResult().getResult(), api::ReturnCode::Result::OK); + EXPECT_EQ(expectedDocEntryString(timestampOne, testDocId) + + expectedDocEntryString(timestampTwo, testDocId), + dumpBucket(BUCKET_ID)); assertTestDocumentFoundAndMatchesContent(NEW_CONTENT); } -void TestAndSetTest::conditional_update_not_executed_when_no_document_and_no_auto_create() { +TEST_F(TestAndSetTest, conditional_update_not_executed_when_no_document_and_no_auto_create) { api::Timestamp updateTimestamp = 200; auto updateUp = conditional_update_test(false, updateTimestamp); - CPPUNIT_ASSERT(thread->handleUpdate(*updateUp)->getResult() == api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); - CPPUNIT_ASSERT_EQUAL(""s, dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handleUpdate(*updateUp)->getResult().getResult(), + api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); + EXPECT_EQ("", dumpBucket(BUCKET_ID)); } -void TestAndSetTest::conditional_update_executed_when_no_document_but_auto_create_is_enabled() { +TEST_F(TestAndSetTest, conditional_update_executed_when_no_document_but_auto_create_is_enabled) { api::Timestamp updateTimestamp = 200; auto updateUp = conditional_update_test(true, updateTimestamp); - CPPUNIT_ASSERT(thread->handleUpdate(*updateUp)->getResult() == api::ReturnCode::Result::OK); - CPPUNIT_ASSERT_EQUAL(expectedDocEntryString(updateTimestamp, testDocId), dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handleUpdate(*updateUp)->getResult().getResult(), api::ReturnCode::Result::OK); + EXPECT_EQ(expectedDocEntryString(updateTimestamp, testDocId), dumpBucket(BUCKET_ID)); assertTestDocumentFoundAndMatchesContent(NEW_CONTENT); } -void TestAndSetTest::invalid_document_selection_should_fail() -{ +TEST_F(TestAndSetTest, invalid_document_selection_should_fail) { // Conditionally replace nonexisting document // Fail early since document selection is invalid api::Timestamp timestamp = 0; api::PutCommand put(makeDocumentBucket(BUCKET_ID), testDoc, timestamp); put.setCondition(documentapi::TestAndSetCondition("bjarne")); - CPPUNIT_ASSERT(thread->handlePut(put)->getResult() == api::ReturnCode::Result::ILLEGAL_PARAMETERS); - CPPUNIT_ASSERT_EQUAL(""s, dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handlePut(put)->getResult().getResult(), api::ReturnCode::Result::ILLEGAL_PARAMETERS); + EXPECT_EQ("", dumpBucket(BUCKET_ID)); } -void TestAndSetTest::conditional_put_to_non_existing_document_should_fail() -{ +TEST_F(TestAndSetTest, conditional_put_to_non_existing_document_should_fail) { // Conditionally replace nonexisting document // Fail since no document exists to match with test and set api::Timestamp timestamp = 0; @@ -267,12 +230,12 @@ void TestAndSetTest::conditional_put_to_non_existing_document_should_fail() setTestCondition(put); thread->handlePut(put); - CPPUNIT_ASSERT(thread->handlePut(put)->getResult() == api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); - CPPUNIT_ASSERT_EQUAL(""s, dumpBucket(BUCKET_ID)); + ASSERT_EQ(thread->handlePut(put)->getResult().getResult(), + api::ReturnCode::Result::TEST_AND_SET_CONDITION_FAILED); + EXPECT_EQ("", dumpBucket(BUCKET_ID)); } -void TestAndSetTest::document_with_no_type_should_fail() -{ +TEST_F(TestAndSetTest, document_with_no_type_should_fail) { // Conditionally replace nonexisting document // Fail since no document exists to match with test and set api::Timestamp timestamp = 0; @@ -281,9 +244,9 @@ void TestAndSetTest::document_with_no_type_should_fail() setTestCondition(remove); auto code = thread->handleRemove(remove)->getResult(); - CPPUNIT_ASSERT(code == api::ReturnCode::Result::ILLEGAL_PARAMETERS); - CPPUNIT_ASSERT(code.getMessage() == "Document id has no doctype"); - CPPUNIT_ASSERT_EQUAL(""s, dumpBucket(BUCKET_ID)); + EXPECT_EQ(code.getResult(), api::ReturnCode::Result::ILLEGAL_PARAMETERS); + EXPECT_EQ(code.getMessage(), "Document id has no doctype"); + EXPECT_EQ("", dumpBucket(BUCKET_ID)); } document::Document::SP @@ -306,10 +269,10 @@ document::Document::SP TestAndSetTest::retrieveTestDocument() { api::GetCommand get(makeDocumentBucket(BUCKET_ID), testDocId, "[all]"); auto tracker = thread->handleGet(get); - CPPUNIT_ASSERT(tracker->getResult() == api::ReturnCode::Result::OK); + assert(tracker->getResult() == api::ReturnCode::Result::OK); auto & reply = static_cast<api::GetReply &>(*tracker->getReply()); - CPPUNIT_ASSERT(reply.wasFound()); + assert(reply.wasFound()); return reply.getDocument(); } @@ -333,7 +296,7 @@ void TestAndSetTest::assertTestDocumentFoundAndMatchesContent(const document::Fi auto doc = retrieveTestDocument(); auto & field = doc->getField("content"); - CPPUNIT_ASSERT_EQUAL(*doc->getValue(field), value); + EXPECT_EQ(*doc->getValue(field), value); } std::string TestAndSetTest::expectedDocEntryString( |