Skip to content

Commit dde138c

Browse files
committed
MB-31869: Remove duplicate code in TestBucketImpl::set<param> functions
And introduce the new ::setParam() API that can be used to set any dynamic configuration param. Change-Id: I5e2402f10368f623e9ea5d39db5d6862e722a54e Reviewed-on: https://review.couchbase.org/c/kv_engine/+/203486 Reviewed-by: Jim Walker <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent 4e8acd0 commit dde138c

File tree

2 files changed

+46
-31
lines changed

2 files changed

+46
-31
lines changed

tests/testapp/testapp_environment.cc

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,51 +63,49 @@ void TestBucketImpl::createEwbBucket(const std::string& name,
6363
conn.createBucket(name, cfg, BucketType::EWouldBlock);
6464
}
6565

66-
// Both memcache and ep-engine buckets support set_param for xattr on/off
66+
// Both memcached and ep-engine buckets support set_param for xattr on/off
6767
void TestBucketImpl::setXattrEnabled(MemcachedConnection& conn,
6868
const std::string& bucketName,
6969
bool value) {
70-
conn.executeInBucket(bucketName, [&](auto& connection) {
71-
// Encode a set_flush_param (like cbepctl)
72-
BinprotGenericCommand cmd{cb::mcbp::ClientOpcode::SetParam,
73-
"xattr_enabled",
74-
value ? "true" : "false"};
75-
cmd.setExtrasValue<uint32_t>(htonl(static_cast<uint32_t>(
76-
cb::mcbp::request::SetParamPayload::Type::Flush)));
77-
78-
const auto resp = connection.execute(cmd);
79-
ASSERT_EQ(cb::mcbp::Status::Success, resp.getStatus());
80-
});
70+
setParam(conn,
71+
bucketName,
72+
"xattr_enabled",
73+
value ? "true" : "false",
74+
cb::mcbp::request::SetParamPayload::Type::Flush);
8175
}
8276

8377
void TestBucketImpl::setCompressionMode(MemcachedConnection& conn,
8478
const std::string& bucketName,
8579
const std::string& value) {
86-
conn.executeInBucket(bucketName, [&](auto& connection) {
87-
// Encode a set_flush_param (like cbepctl)
88-
BinprotGenericCommand cmd{
89-
cb::mcbp::ClientOpcode::SetParam, "compression_mode", value};
90-
cmd.setExtrasValue<uint32_t>(htonl(static_cast<uint32_t>(
91-
cb::mcbp::request::SetParamPayload::Type::Flush)));
92-
93-
const auto resp = connection.execute(cmd);
94-
ASSERT_EQ(cb::mcbp::Status::Success, resp.getStatus());
95-
});
80+
setParam(conn,
81+
bucketName,
82+
"compression_mode",
83+
value,
84+
cb::mcbp::request::SetParamPayload::Type::Flush);
9685
}
9786

9887
void TestBucketImpl::setMinCompressionRatio(MemcachedConnection& conn,
9988
const std::string& bucketName,
10089
const std::string& value) {
90+
setParam(conn,
91+
bucketName,
92+
"min_compression_ratio",
93+
value,
94+
cb::mcbp::request::SetParamPayload::Type::Flush);
95+
}
96+
97+
void TestBucketImpl::setParam(
98+
MemcachedConnection& conn,
99+
const std::string& bucketName,
100+
const std::string& paramName,
101+
const std::string& paramValue,
102+
cb::mcbp::request::SetParamPayload::Type paramType) {
101103
conn.executeInBucket(bucketName, [&](auto& connection) {
102-
// Encode a set_flush_param (like cbepctl)
103-
BinprotGenericCommand cmd{cb::mcbp::ClientOpcode::SetParam,
104-
"min_compression_ratio",
105-
value};
106-
cmd.setExtrasValue<uint32_t>(htonl(static_cast<uint32_t>(
107-
cb::mcbp::request::SetParamPayload::Type::Flush)));
108-
109-
const auto resp = connection.execute(cmd);
110-
ASSERT_EQ(cb::mcbp::Status::Success, resp.getStatus());
104+
BinprotGenericCommand cmd{
105+
cb::mcbp::ClientOpcode::SetParam, paramName, paramValue};
106+
cmd.setExtrasValue<uint32_t>(htonl(static_cast<uint32_t>(paramType)));
107+
ASSERT_EQ(cb::mcbp::Status::Success,
108+
connection.execute(cmd).getStatus());
111109
});
112110
}
113111

tests/testapp/testapp_environment.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
#pragma once
1212

13+
#include <memcached/protocol_binary.h>
1314
#include <nlohmann/json_fwd.hpp>
1415
#include <functional>
1516
#include <string>
@@ -98,6 +99,22 @@ class TestBucketImpl {
9899
const std::string& bucketName,
99100
const std::string& value);
100101

102+
/**
103+
* Set a configuration param for the named bucket.
104+
*
105+
* @param conn The connection to use (must have admin privileges)
106+
* @param bucketName The name of the bucket to modify
107+
* @param paramName
108+
* @param paramValue
109+
* @param paramType See cb::mcbp::request::SetParamPayload::Type for
110+
* details.
111+
*/
112+
void setParam(MemcachedConnection& conn,
113+
const std::string& bucketName,
114+
const std::string& paramName,
115+
const std::string& paramValue,
116+
cb::mcbp::request::SetParamPayload::Type paramType);
117+
101118
protected:
102119
static void createEwbBucket(const std::string& name,
103120
const std::string& plugin,

0 commit comments

Comments
 (0)