Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add tests for KvBackend trait implement #3700

Merged
merged 6 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/catalog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ workspace = true

[dependencies]
api.workspace = true
arrow.workspace = true
arrow-schema.workspace = true
arrow.workspace = true
poltao marked this conversation as resolved.
Show resolved Hide resolved
async-stream.workspace = true
async-trait = "0.1"
common-catalog.workspace = true
Expand Down
113 changes: 113 additions & 0 deletions src/common/meta/src/kv_backend/etcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,117 @@ mod tests {
assert_eq!(b"test_key".to_vec(), delete.key);
let _ = delete.options.unwrap();
}

use crate::kv_backend::test::{
prepare_kv_with_prefix, test_kv_batch_delete_with_prefix, test_kv_batch_get_with_prefix,
test_kv_compare_and_put_with_prefix, test_kv_delete_range_with_prefix,
test_kv_put_with_prefix, test_kv_range_2_with_prefix, test_kv_range_with_prefix,
unprepare_kv,
};

async fn build_kv_backend() -> Option<EtcdStore> {
let endpoints = std::env::var("GT_ETCD_ENDPOINTS").unwrap_or_default();
if endpoints.is_empty() {
return None;
}
let endpoints = endpoints
.split(',')
.map(|s| s.to_string())
.collect::<Vec<String>>();

std::panic::set_hook(Box::new(|_| {
println!("panic: malformed endpoints");
}));
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
let client = Client::connect(endpoints, None)
.await
.expect("malformed endpoints");
Some(EtcdStore {
client,
max_txn_ops: 128,
})
}

#[tokio::test]
async fn test_put() {
match build_kv_backend().await {
Some(kv_backend) => {
let prefix = b"put/";
prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
test_kv_put_with_prefix(&kv_backend, prefix.to_vec()).await;
unprepare_kv(&kv_backend, prefix).await;
}
None => {}
}
}

#[tokio::test]
async fn test_range() {
match build_kv_backend().await {
Some(kv_backend) => {
let prefix = b"range/";
prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
test_kv_range_with_prefix(&kv_backend, prefix.to_vec()).await;
unprepare_kv(&kv_backend, prefix).await;
}
None => {}
}
}

#[tokio::test]
async fn test_range_2() {
match build_kv_backend().await {
Some(kv_backend) => {
test_kv_range_2_with_prefix(kv_backend, b"range2/".to_vec()).await;
}
None => {}
}
}

#[tokio::test]
async fn test_batch_get() {
match build_kv_backend().await {
Some(kv_backend) => {
let prefix = b"batchGet/";
prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
test_kv_batch_get_with_prefix(&kv_backend, prefix.to_vec()).await;
unprepare_kv(&kv_backend, prefix).await;
}
None => {}
}
}

#[tokio::test(flavor = "multi_thread")]
async fn test_compare_and_put() {
match build_kv_backend().await {
Some(kv_backend) => {
let kv_backend = Arc::new(kv_backend);
test_kv_compare_and_put_with_prefix(kv_backend, b"compareAndPut/".to_vec()).await;
}
None => {}
}
}

#[tokio::test]
async fn test_delete_range() {
match build_kv_backend().await {
Some(kv_backend) => {
let prefix = b"deleteRange/";
prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
test_kv_delete_range_with_prefix(kv_backend, prefix.to_vec()).await;
}
None => {}
}
}

#[tokio::test]
async fn test_batch_delete() {
match build_kv_backend().await {
Some(kv_backend) => {
let prefix = b"batchDelete/";
prepare_kv_with_prefix(&kv_backend, prefix.to_vec()).await;
test_kv_batch_delete_with_prefix(kv_backend, prefix.to_vec()).await;
}
None => {}
}
}
}
6 changes: 3 additions & 3 deletions src/common/meta/src/kv_backend/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,14 @@ mod tests {
async fn test_put() {
let kv_backend = mock_mem_store_with_data().await;

test_kv_put(kv_backend).await;
test_kv_put(&kv_backend).await;
}

#[tokio::test]
async fn test_range() {
let kv_backend = mock_mem_store_with_data().await;

test_kv_range(kv_backend).await;
test_kv_range(&kv_backend).await;
}

#[tokio::test]
Expand All @@ -378,7 +378,7 @@ mod tests {
async fn test_batch_get() {
let kv_backend = mock_mem_store_with_data().await;

test_kv_batch_get(kv_backend).await;
test_kv_batch_get(&kv_backend).await;
}

#[tokio::test(flavor = "multi_thread")]
Expand Down
Loading
Loading