From 521839f37b45de0d385eef992c192d8c0a0d3785 Mon Sep 17 00:00:00 2001 From: Liang Zhao Date: Sat, 11 Mar 2023 17:41:29 +0800 Subject: [PATCH] unit test --- src/storage/src/hummock/compactor/iterator.rs | 13 +++++----- src/storage/src/hummock/test_utils.rs | 24 +++++++++++++++++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/storage/src/hummock/compactor/iterator.rs b/src/storage/src/hummock/compactor/iterator.rs index d621a72f0613b..aa540959a5488 100644 --- a/src/storage/src/hummock/compactor/iterator.rs +++ b/src/storage/src/hummock/compactor/iterator.rs @@ -401,7 +401,8 @@ mod tests { use crate::hummock::iterator::test_utils::mock_sstable_store; use crate::hummock::iterator::HummockIterator; use crate::hummock::test_utils::{ - default_builder_opt_for_test, gen_test_sstable, test_key_of, test_value_of, TEST_KEYS_COUNT, + default_builder_opt_for_test, gen_test_sstable_and_info, test_key_of, test_value_of, + TEST_KEYS_COUNT, }; use crate::hummock::value::HummockValue; @@ -412,7 +413,7 @@ mod tests { for sst_id in 0..3 { let start_index = sst_id * TEST_KEYS_COUNT; let end_index = (sst_id + 1) * TEST_KEYS_COUNT; - let table = gen_test_sstable( + let (_table, table_info) = gen_test_sstable_and_info( default_builder_opt_for_test(), sst_id as u64, (start_index..end_index) @@ -420,7 +421,7 @@ mod tests { sstable_store.clone(), ) .await; - table_infos.push(table.get_sstable_info()); + table_infos.push(table_info); } let start_index = 5000; let end_index = 25000; @@ -512,7 +513,7 @@ mod tests { for sst_id in 0..3 { let start_index = sst_id * TEST_KEYS_COUNT + TEST_KEYS_COUNT / 2; let end_index = (sst_id + 1) * TEST_KEYS_COUNT; - let table = gen_test_sstable( + let (_table, table_info) = gen_test_sstable_and_info( default_builder_opt_for_test(), sst_id as u64, (start_index..end_index) @@ -520,7 +521,7 @@ mod tests { sstable_store.clone(), ) .await; - table_infos.push(table.get_sstable_info()); + table_infos.push(table_info); } // Test seek_idx. Result is dominated by given seek key rather than key range. @@ -550,7 +551,7 @@ mod tests { let block_1_second_key = iter.key().to_vec(); // Use a big enough seek key and result in invalid iterator. let seek_key = test_key_of(30001); - iter.seek_idx(0, Some(seek_key.encode().as_slice())) + iter.seek_idx(table_infos.len() - 1, Some(seek_key.encode().as_slice())) .await .unwrap(); assert!(!iter.is_valid()); diff --git a/src/storage/src/hummock/test_utils.rs b/src/storage/src/hummock/test_utils.rs index 816efd07611c6..60aec0b8c0975 100644 --- a/src/storage/src/hummock/test_utils.rs +++ b/src/storage/src/hummock/test_utils.rs @@ -202,7 +202,7 @@ pub async fn gen_test_sstable_inner>( range_tombstones: Vec, sstable_store: SstableStoreRef, policy: CachePolicy, -) -> Sstable { +) -> (Sstable, SstableInfo) { let writer_opts = SstableWriterOptions { capacity_hint: None, tracker: None, @@ -223,7 +223,7 @@ pub async fn gen_test_sstable_inner>( ) .await .unwrap(); - table.value().as_ref().clone() + (table.value().as_ref().clone(), output.sst_info.sst_info) } /// Generate a test table from the given `kv_iter` and put the kv value to `sstable_store` @@ -242,6 +242,25 @@ pub async fn gen_test_sstable>( CachePolicy::NotFill, ) .await + .0 +} + +/// Generate a test table from the given `kv_iter` and put the kv value to `sstable_store` +pub async fn gen_test_sstable_and_info>( + opts: SstableBuilderOptions, + sst_id: HummockSstableId, + kv_iter: impl Iterator, HummockValue)>, + sstable_store: SstableStoreRef, +) -> (Sstable, SstableInfo) { + gen_test_sstable_inner( + opts, + sst_id, + kv_iter, + vec![], + sstable_store, + CachePolicy::NotFill, + ) + .await } /// Generate a test table from the given `kv_iter` and put the kv value to `sstable_store` @@ -261,6 +280,7 @@ pub async fn gen_test_sstable_with_range_tombstone( CachePolicy::NotFill, ) .await + .0 } /// Generates a user key with table id 0 and the given `table_key`