Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
fengys1996 committed Feb 2, 2024
1 parent 7ba48ac commit 4bab4d6
Showing 1 changed file with 9 additions and 51 deletions.
60 changes: 9 additions & 51 deletions src/catalog/src/kvbackend/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl KvBackend for MetaKvBackend {
#[cfg(test)]
mod tests {
use std::any::Any;
use std::sync::atomic::AtomicU32;
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc;

use async_trait::async_trait;
Expand Down Expand Up @@ -465,59 +465,26 @@ mod tests {
keys: vec![b"k1".to_vec(), b"k2".to_vec()],
};

let _batch_get_resp = cached_kv.batch_get(batch_get_req.clone()).await.unwrap();

assert_eq!(
get_execute_times.load(std::sync::atomic::Ordering::SeqCst),
2
);
assert_eq!(get_execute_times.load(Ordering::SeqCst), 0);

let _batch_get_resp = cached_kv.batch_get(batch_get_req).await.unwrap();
for _ in 0..10 {
let _batch_get_resp = cached_kv.batch_get(batch_get_req.clone()).await.unwrap();

assert_eq!(
get_execute_times.load(std::sync::atomic::Ordering::SeqCst),
2
);
assert_eq!(get_execute_times.load(Ordering::SeqCst), 2);
}

let batch_get_req = BatchGetRequest {
keys: vec![b"k1".to_vec(), b"k2".to_vec(), b"k3".to_vec()],
};

let _batch_get_resp = cached_kv.batch_get(batch_get_req.clone()).await.unwrap();

assert_eq!(
get_execute_times.load(std::sync::atomic::Ordering::SeqCst),
3
);
assert_eq!(get_execute_times.load(Ordering::SeqCst), 3);

for _ in 0..100 {
for _ in 0..10 {
let _batch_get_resp = cached_kv.batch_get(batch_get_req.clone()).await.unwrap();

assert_eq!(
get_execute_times.load(std::sync::atomic::Ordering::SeqCst),
3
);
}

for _ in 0..50 {
let _get_resp = cached_kv.get(b"k3").await.unwrap();
assert_eq!(
get_execute_times.load(std::sync::atomic::Ordering::SeqCst),
3
);
}
let _get_resp = cached_kv.get(b"k4").await.unwrap();
assert_eq!(
get_execute_times.load(std::sync::atomic::Ordering::SeqCst),
4
);

for _ in 0..50 {
let _get_resp = cached_kv.get(b"k4").await.unwrap();
assert_eq!(
get_execute_times.load(std::sync::atomic::Ordering::SeqCst),
4
);
assert_eq!(get_execute_times.load(Ordering::SeqCst), 3);
}
}

Expand Down Expand Up @@ -548,14 +515,5 @@ mod tests {
})
.await
.unwrap();

kv_backend
.put(PutRequest {
key: b"k4".to_vec(),
value: b"v4".to_vec(),
prev_kv: false,
})
.await
.unwrap();
}
}

0 comments on commit 4bab4d6

Please sign in to comment.