Skip to content

Commit

Permalink
refactor: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
QuenKar committed Jan 7, 2024
1 parent 476a12e commit 3259d35
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/mito2/src/cache/write_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&[
Expand All @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit 3259d35

Please sign in to comment.