Skip to content

Commit

Permalink
Change enum name and add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
RinChanNOWWW committed Jul 16, 2022
1 parent b875fca commit 9bfe7ba
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ metactl-test:
bash ./tests/metactl/test-metactl.sh
bash ./tests/metactl/test-metactl-restore-new-cluster.sh

meta-kvapi-test:
bash ./tests/meta-kvapi/test-meta-kvapi.sh

meta-bench: build-release
bash ./scripts/benchmark/run-meta-benchmark.sh 10 1000

Expand Down
2 changes: 1 addition & 1 deletion metasrv/src/bin/metasrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ async fn main(_global_tracker: Arc<RuntimeTracker>) -> common_exception::Result<
}

async fn run_kvapi_command(conf: &Config, op: &str) {
match cmd::KvApi::from_config(conf, op) {
match cmd::KvApiCommand::from_config(conf, op) {
Ok(kv_cmd) => {
let rpc_conf = RpcClientConf {
address: conf.grpc_api_address.clone(),
Expand Down
12 changes: 6 additions & 6 deletions metasrv/src/cmd/kvapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ use common_meta_types::UpsertKVReq;

use crate::configs::Config;

pub enum KvApi {
pub enum KvApiCommand {
Get(String),
Upsert(UpsertKVReq),
MGet(Vec<String>),
List(String),
}

impl KvApi {
impl KvApiCommand {
pub fn from_config(config: &Config, op: &str) -> std::result::Result<Self, String> {
let api = match op {
"upsert" => {
Expand Down Expand Up @@ -60,19 +60,19 @@ impl KvApi {

pub async fn execute(&self, client: Arc<dyn KVApi>) -> Result<String> {
let res_str = match self {
KvApi::Get(key) => {
KvApiCommand::Get(key) => {
let res = client.get_kv(key.as_str()).await?;
serde_json::to_string_pretty(&res)?
}
KvApi::Upsert(req) => {
KvApiCommand::Upsert(req) => {
let res = client.upsert_kv(req.clone()).await?;
serde_json::to_string_pretty(&res)?
}
KvApi::MGet(keys) => {
KvApiCommand::MGet(keys) => {
let res = client.mget_kv(keys.as_slice()).await?;
serde_json::to_string_pretty(&res)?
}
KvApi::List(prefix) => {
KvApiCommand::List(prefix) => {
let res = client.prefix_list_kv(prefix.as_str()).await?;
serde_json::to_string_pretty(&res)?
}
Expand Down
2 changes: 1 addition & 1 deletion metasrv/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

mod kvapi;

pub use kvapi::KvApi;
pub use kvapi::KvApiCommand;
8 changes: 8 additions & 0 deletions tests/meta-kvapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Data for testing databend-meta kvapi commands


In the databend root dir:

```
sh ./tests/meta-kvapi/test-meta-kvapi.sh
```
32 changes: 32 additions & 0 deletions tests/meta-kvapi/test-meta-kvapi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

set -o errexit

BUILD_PROFILE="${BUILD_PROFILE:-debug}"
DATABEND_META="./target/${BUILD_PROFILE}/databend-meta"

echo " === start a single node databend-meta"
chmod +x ${DATABEND_META}
${DATABEND_META} --single &
METASRV_PID=$!
echo $METASRV_PID

echo " === test kvapi::upsert"
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::upsert --key 1:key1 --value value1
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::upsert --key 1:key2 --value value2
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::upsert --key 1:key3 --value value3
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::upsert --key 2:key1 --value value1
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::upsert --key 2:key2 --value value2

echo " === test kvapi::get"
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::get --key 1:key1
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::get --key 2:key2

echo " === test kvapi::mget"
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::mget --key 1:key1 2:key2

echo " === test kvapi::list"
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::list --prefix 1:
${DATABEND_META} --grpc-api-address "127.0.0.1:9191" --cmd kvapi::list --prefix 2:

kill $METASRV_PID

0 comments on commit 9bfe7ba

Please sign in to comment.