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 all 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
91 changes: 91 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,95 @@ 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>>();

let client = Client::connect(endpoints, None)
.await
.expect("malformed endpoints");

Some(EtcdStore {
client,
max_txn_ops: 128,
})
}

#[tokio::test]
async fn test_put() {
if let Some(kv_backend) = build_kv_backend().await {
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;
}
}

#[tokio::test]
async fn test_range() {
if let Some(kv_backend) = build_kv_backend().await {
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;
}
}

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

#[tokio::test]
async fn test_batch_get() {
if let Some(kv_backend) = build_kv_backend().await {
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;
}
}

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

#[tokio::test]
async fn test_delete_range() {
if let Some(kv_backend) = build_kv_backend().await {
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;
}
}

#[tokio::test]
async fn test_batch_delete() {
if let Some(kv_backend) = build_kv_backend().await {
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;
}
}
}
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