aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/persistence
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@oath.com>2018-11-26 13:51:12 +0000
committerTor Brede Vekterli <vekterli@oath.com>2018-11-26 14:12:23 +0000
commitb71cc013e878e4a12ee3ce6c7434424fcb7f204b (patch)
tree7986f84c321d3607b9f9389213fb9bd2c7a94dd5 /storage/src/tests/persistence
parent9871bb9e867198d767386d35a3842a2da8fc7dfb (diff)
Support test-and-set for auto-create document updates
Has the obvious consistency caveats that if all your existing replicas are down, the update will go through since the document from an weak consistency perspective does not exist anywhere. But can be a useful feature if this is an acceptable tradeoff.
Diffstat (limited to 'storage/src/tests/persistence')
-rw-r--r--storage/src/tests/persistence/testandsettest.cpp50
1 files changed, 35 insertions, 15 deletions
diff --git a/storage/src/tests/persistence/testandsettest.cpp b/storage/src/tests/persistence/testandsettest.cpp
index 686e10ba5ef..197aa95fc22 100644
--- a/storage/src/tests/persistence/testandsettest.cpp
+++ b/storage/src/tests/persistence/testandsettest.cpp
@@ -66,8 +66,10 @@ public:
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 non_existing_document_should_fail();
+ void conditional_put_to_non_existing_document_should_fail();
void document_with_no_type_should_fail();
CPPUNIT_TEST_SUITE(TestAndSetTest);
@@ -77,16 +79,17 @@ public:
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(non_existing_document_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 matchingHeader,
- api::Timestamp timestampOne,
- api::Timestamp timestampTwo);
+ bool createIfMissing,
+ api::Timestamp updateTimestamp);
document::Document::SP createTestDocument();
document::Document::SP retrieveTestDocument();
@@ -183,18 +186,16 @@ void TestAndSetTest::conditional_remove_executed_on_condition_match()
}
std::unique_ptr<api::UpdateCommand> TestAndSetTest::conditional_update_test(
- bool matchingHeader,
- api::Timestamp timestampOne,
- api::Timestamp timestampTwo)
+ bool createIfMissing,
+ api::Timestamp updateTimestamp)
{
- putTestDocument(matchingHeader, timestampOne);
-
auto docUpdate = std::make_shared<document::DocumentUpdate>(_env->_testDocMan.getTypeRepo(), testDoc->getType(), testDocId);
auto fieldUpdate = document::FieldUpdate(testDoc->getField("content"));
fieldUpdate.addUpdate(document::AssignValueUpdate(NEW_CONTENT));
docUpdate->addUpdate(fieldUpdate);
+ docUpdate->setCreateIfNonExistent(createIfMissing);
- auto updateUp = std::make_unique<api::UpdateCommand>(makeDocumentBucket(BUCKET_ID), docUpdate, timestampTwo);
+ auto updateUp = std::make_unique<api::UpdateCommand>(makeDocumentBucket(BUCKET_ID), docUpdate, updateTimestamp);
setTestCondition(*updateUp);
return updateUp;
}
@@ -203,11 +204,12 @@ void TestAndSetTest::conditional_update_not_executed_on_condition_mismatch()
{
api::Timestamp timestampOne = 0;
api::Timestamp timestampTwo = 1;
- auto updateUp = conditional_update_test(false, timestampOne, timestampTwo);
+ 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));
+ dumpBucket(BUCKET_ID));
assertTestDocumentFoundAndMatchesContent(OLD_CONTENT);
}
@@ -216,7 +218,8 @@ void TestAndSetTest::conditional_update_executed_on_condition_match()
{
api::Timestamp timestampOne = 0;
api::Timestamp timestampTwo = 1;
- auto updateUp = conditional_update_test(true, timestampOne, timestampTwo);
+ 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) +
@@ -226,6 +229,23 @@ void TestAndSetTest::conditional_update_executed_on_condition_match()
assertTestDocumentFoundAndMatchesContent(NEW_CONTENT);
}
+void 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));
+}
+
+void 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));
+ assertTestDocumentFoundAndMatchesContent(NEW_CONTENT);
+}
+
void TestAndSetTest::invalid_document_selection_should_fail()
{
// Conditionally replace nonexisting document
@@ -238,7 +258,7 @@ void TestAndSetTest::invalid_document_selection_should_fail()
CPPUNIT_ASSERT_EQUAL(""s, dumpBucket(BUCKET_ID));
}
-void TestAndSetTest::non_existing_document_should_fail()
+void TestAndSetTest::conditional_put_to_non_existing_document_should_fail()
{
// Conditionally replace nonexisting document
// Fail since no document exists to match with test and set