Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
Signed-off-by: Little-Wallace <[email protected]>
  • Loading branch information
Little-Wallace committed May 8, 2024
1 parent 8650192 commit 2535b6a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions src/meta/src/hummock/compaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,53 @@ impl Default for CompactionDeveloperConfig {
}
}
}

#[cfg(test)]
pub mod tests {
use super::*;
use crate::hummock::compaction::compaction_config::CompactionConfigBuilder;

#[test]
fn test_create_compaction_task() {
let config = CompactionConfigBuilder::new().build();
let mut input = CompactionInput {
input_levels: vec![],
target_level: 0,
select_input_size: 256 * 1024 * 1024,
target_input_size: 128 * 1024 * 1024,
total_file_count: 3,
target_sub_level_id: 0,
vnode_partition_count: 0,
};
let task =
create_compaction_task(&config, input.clone(), 3, compact_task::TaskType::Dynamic);
assert_eq!(task.target_file_size, config.target_file_size_base);
input.target_level = 3;
let task = create_compaction_task(&config, input, 3, compact_task::TaskType::Dynamic);
assert_eq!(task.target_file_size, config.target_file_size_base / 4);
let input = CompactionInput {
input_levels: vec![],
target_level: 3,
select_input_size: 512 * 1024 * 1024,
target_input_size: 512 * 1024 * 1024,
total_file_count: 3,
target_sub_level_id: 0,
vnode_partition_count: 0,
};

let task = create_compaction_task(&config, input, 3, compact_task::TaskType::Dynamic);
assert_eq!(task.target_file_size, config.target_file_size_base);

let input = CompactionInput {
input_levels: vec![],
target_level: 3,
select_input_size: 8 * 1024 * 1024 * 1024,
target_input_size: 8 * 1024 * 1024 * 1024,
total_file_count: 3,
target_sub_level_id: 0,
vnode_partition_count: 0,
};
let task = create_compaction_task(&config, input, 3, compact_task::TaskType::Dynamic);
assert_eq!(task.target_file_size, 64 * 1024 * 1024);
}
}
2 changes: 1 addition & 1 deletion src/meta/src/hummock/compaction/picker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct LocalPickerStatistic {
pub skip_by_overlapping: u64,
}

#[derive(Default, Debug)]
#[derive(Default, Debug, Clone)]
pub struct CompactionInput {
pub input_levels: Vec<InputLevel>,
pub target_level: usize,
Expand Down

0 comments on commit 2535b6a

Please sign in to comment.