Skip to content

Commit

Permalink
[serverless] Add separate unit test for Locking functions
Browse files Browse the repository at this point in the history
Change-Id: I335093679d4a37de52b354875250aab87e31ad9f
Reviewed-on: https://review.couchbase.org/c/kv_engine/+/176796
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Paolo Cocchi <paolo.cocchi@couchbase.com>
  • Loading branch information
trondn committed Jun 30, 2022
1 parent 6c136df commit 81ced25
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions tests/testapp_serverless/serverless_test.cc
Expand Up @@ -967,33 +967,10 @@ TEST_F(ServerlessTest, OpsMetered) {
break;

case ClientOpcode::GetLocked:
rsp = conn.execute(
BinprotGetAndLockCommand{"ClientOpcode::GetLocked"});
EXPECT_EQ(Status::KeyEnoent, rsp.getStatus());
EXPECT_FALSE(rsp.getReadUnits());
EXPECT_FALSE(rsp.getWriteUnits());
createDocument("ClientOpcode::GetLocked", "value");
rsp = conn.execute(
BinprotGetAndLockCommand{"ClientOpcode::GetLocked"});
EXPECT_TRUE(rsp.isSuccess());
ASSERT_TRUE(rsp.getReadUnits());
EXPECT_EQ(1, *rsp.getReadUnits());
EXPECT_FALSE(rsp.getWriteUnits());
break;
case ClientOpcode::UnlockKey:
do {
createDocument("ClientOpcode::UnlockKey", "value");
auto doc = conn.get_and_lock(
"ClientOpcode::UnlockKey", Vbid{0}, 15);
executeWithExpectedCU(
[&conn, cas = doc.info.cas]() {
conn.unlock(
"ClientOpcode::UnlockKey", Vbid{0}, cas);
},
0,
0);
} while (false);
// Tested in MeterDocumentLocking
break;

case ClientOpcode::ObserveSeqno:
do {
uint64_t uuid = 0;
Expand Down Expand Up @@ -1737,4 +1714,38 @@ TEST_F(ServerlessTest, MeterDocumentGet) {
EXPECT_FALSE(rsp.getWriteUnits());
}

TEST_F(ServerlessTest, MeterDocumentLocking) {
auto& sconfig = cb::serverless::Config::instance();
auto conn = cluster->getConnection(0);
conn->authenticate("@admin", "password");
conn->selectBucket("bucket-0");
conn->dropPrivilege(cb::rbac::Privilege::Unmetered);
conn->setFeature(cb::mcbp::Feature::ReportUnitUsage, true);

const std::string id = "MeterDocumentLocking";
const auto getl = BinprotGetAndLockCommand{id};
auto rsp = conn->execute(getl);
EXPECT_EQ(cb::mcbp::Status::KeyEnoent, rsp.getStatus());
EXPECT_FALSE(rsp.getReadUnits());
EXPECT_FALSE(rsp.getWriteUnits());

std::string document_value;
document_value.resize(sconfig.readUnitSize - 5);
std::fill(document_value.begin(), document_value.end(), 'a');

writeDocument(*conn, id, document_value);
rsp = conn->execute(getl);
EXPECT_TRUE(rsp.isSuccess()) << rsp.getStatus();
ASSERT_TRUE(rsp.getReadUnits());
EXPECT_EQ(sconfig.to_ru(document_value.size() + id.size()),
*rsp.getReadUnits());
EXPECT_FALSE(rsp.getWriteUnits());

auto unl = BinprotUnlockCommand{id, Vbid{0}, rsp.getCas()};
rsp = conn->execute(unl);
EXPECT_TRUE(rsp.isSuccess()) << rsp.getStatus();
EXPECT_FALSE(rsp.getReadUnits());
EXPECT_FALSE(rsp.getWriteUnits());
}

} // namespace cb::test

0 comments on commit 81ced25

Please sign in to comment.