From 3259d359e65f16c7e03036ae047737aacfdeb874 Mon Sep 17 00:00:00 2001 From: QuenKar <47681251+QuenKar@users.noreply.github.com> Date: Sun, 7 Jan 2024 13:01:11 +0800 Subject: [PATCH] refactor: unit test --- src/mito2/src/cache/write_cache.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/mito2/src/cache/write_cache.rs b/src/mito2/src/cache/write_cache.rs index 839f913c1b0e..ed57b7e2f659 100644 --- a/src/mito2/src/cache/write_cache.rs +++ b/src/mito2/src/cache/write_cache.rs @@ -167,8 +167,7 @@ mod tests { let cache = FileCache::new(local_store.clone(), ReadableSize::mb(10)); let file_id = FileId::random(); - // Create Env - let mut env = TestEnv::new(); + // Create Source let metadata = Arc::new(sst_region_metadata()); let region_id = metadata.region_id; let source = new_source(&[ @@ -177,13 +176,19 @@ mod tests { new_batch_by_range(&["b", "h"], 100, 200), ]); - // Another fs store to mock uploading + // Because we couldn't create a S3 object store in unit test, + // use another Fs store to mock uploading place. + let mut env = TestEnv::new(); let mock_store = env.init_object_store_manager(); let upload_path = sst_file_path("test", file_id); - // Create write cache + // Create WriteCache let object_store_manager = Arc::new(ObjectStoreManager::new("mock", mock_store.clone())); - let write_cache = WriteCache::new(local_store, object_store_manager, ReadableSize::mb(10)); + let write_cache = WriteCache::new( + local_store.clone(), + object_store_manager, + ReadableSize::mb(10), + ); let request = SstUploadRequest { file_id, @@ -210,11 +215,12 @@ mod tests { let key = (region_id, file_id); assert!(write_cache.file_cache.contains_key(&key)); - // Check the file size - let file_size = sst_info.file_size; + // Check file // Read from mock remote store - let n: usize = mock_store.read(&upload_path).await.unwrap().len(); - assert_eq!(file_size, n as u64); + let remote_data = mock_store.read(&upload_path).await.unwrap(); + // Read from local file cache + let cache_data = local_store.read(&cache.cache_file_path(key)).await.unwrap(); + assert_eq!(remote_data, cache_data); // Delete test files mock_store.delete(&upload_path).await;