From 3a69780635fc280b587963a0bcc7ce7116273ce3 Mon Sep 17 00:00:00 2001 From: Li0k Date: Mon, 24 Jun 2024 18:40:44 +0800 Subject: [PATCH] chore(compactor): add more test --- src/storage/src/hummock/compactor/iterator.rs | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/storage/src/hummock/compactor/iterator.rs b/src/storage/src/hummock/compactor/iterator.rs index d2c87739b76d8..cb245b5d36fab 100644 --- a/src/storage/src/hummock/compactor/iterator.rs +++ b/src/storage/src/hummock/compactor/iterator.rs @@ -988,5 +988,97 @@ mod tests { assert_eq!(1, start_index); assert_eq!(1, end_index); } + + { + let block_metas = vec![ + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(1), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(1), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(1), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(2), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(3), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + ]; + let seek_key = None; + + let (start_index, end_index) = ConcatSstableIterator::filter_block_metas( + &block_metas, + seek_key, + &HashSet::from_iter(vec![2_u32].into_iter()), + &KeyRange::default(), + ); + + assert_eq!(3, start_index); + assert_eq!(4, end_index); + } + + { + let block_metas = vec![ + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(1), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(2), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(3), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(3), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + BlockMeta { + smallest_key: FullKey::for_test(TableId::new(3), Vec::default(), 0) + .encode() + .into(), + ..Default::default() + }, + ]; + let seek_key = None; + + let (start_index, end_index) = ConcatSstableIterator::filter_block_metas( + &block_metas, + seek_key, + &HashSet::from_iter(vec![2_u32].into_iter()), + &KeyRange::default(), + ); + + assert_eq!(1, start_index); + assert_eq!(1, end_index); + } } }