From 4bab4d615143915b843ddc46dbe3e7c0825ba6fb Mon Sep 17 00:00:00 2001 From: fys <1113014250@qq.com> Date: Fri, 2 Feb 2024 17:02:34 +0800 Subject: [PATCH] unit test --- src/catalog/src/kvbackend/client.rs | 60 +++++------------------------ 1 file changed, 9 insertions(+), 51 deletions(-) diff --git a/src/catalog/src/kvbackend/client.rs b/src/catalog/src/kvbackend/client.rs index d5673c51f6a2..e3351c6d270f 100644 --- a/src/catalog/src/kvbackend/client.rs +++ b/src/catalog/src/kvbackend/client.rs @@ -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; @@ -465,19 +465,13 @@ 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()], @@ -485,39 +479,12 @@ mod tests { 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); } } @@ -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(); } }