Skip to content

Commit

Permalink
MB-53100: Add new member KVBucketTest::store_item_replica()
Browse files Browse the repository at this point in the history
Add new member KVBucketTest::store_item_replica() to make it easier to
write to replica vbuckets in tests.
Change-Id: I4bebae283cdd4912e06fed14ee4e13ab88923d88

Change-Id: Ia5a2ca8dccdbfb7ff752b2f57e056df23b7c7b72
Reviewed-on: https://review.couchbase.org/c/kv_engine/+/178192
Reviewed-by: Dave Rigby <daver@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
  • Loading branch information
rdemellow committed Jul 29, 2022
1 parent f124229 commit 6c35d08
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
38 changes: 38 additions & 0 deletions engines/ep/tests/module_tests/kv_bucket_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,44 @@ ::testing::AssertionResult KVBucketTest::store_items(
return ::testing::AssertionSuccess();
}

::testing::AssertionResult KVBucketTest::store_item_replica(
Vbid vbid,
const DocKey& key,
const std::string& value,
uint64_t seqno,
uint32_t exptime,
const cb::engine_errc expected,
protocol_binary_datatype_t datatype,
std::optional<cb::durability::Requirements> reqs,
bool deleted) {
auto item = make_item(vbid, key, value, exptime, datatype);
if (reqs) {
item.setPendingSyncWrite(*reqs);
}
if (deleted) {
item.setDeleted(DeleteSource::Explicit);
}
item.setBySeqno(seqno);
item.setCas();

auto returnCode = store->setWithMeta(item,
0,
nullptr,
cookie,
{vbucket_state_replica},
CheckConflicts::No,
true,
GenerateBySeqno::Yes,
GenerateCas::No,
nullptr);
if (returnCode != expected) {
return ::testing::AssertionFailure()
<< "store_item_replica() unexpected error:"
<< cb::to_string(returnCode) << " for key:" << key.to_string();
}
return ::testing::AssertionSuccess();
}

void KVBucketTest::flush_vbucket_to_disk(Vbid vbid, size_t expected) {
size_t actualFlushed = flushVBucket(vbid);

Expand Down
15 changes: 15 additions & 0 deletions engines/ep/tests/module_tests/kv_bucket_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ class KVBucketTest : virtual public ::testing::Test {
protocol_binary_datatype_t datatype =
PROTOCOL_BINARY_DATATYPE_JSON);

/**
* Stores an item to a replica vbucket, returns an assert if the set succeed
* or not.
*/
[[nodiscard]] ::testing::AssertionResult store_item_replica(
Vbid vbid,
const DocKey& key,
const std::string& value,
uint64_t seqno,
uint32_t exptime = 0,
const cb::engine_errc expected = cb::engine_errc::success,
protocol_binary_datatype_t datatype = PROTOCOL_BINARY_DATATYPE_JSON,
std::optional<cb::durability::Requirements> reqs = {},
bool deleted = false);

/* Flush the given vbucket to disk, so any outstanding dirty items are
* written (and are clean).
*/
Expand Down

0 comments on commit 6c35d08

Please sign in to comment.