Skip to content

Commit

Permalink
refactor(test): refactor some ut for hummock (#18534)
Browse files Browse the repository at this point in the history
  • Loading branch information
Li0k authored Sep 14, 2024
1 parent c80351b commit ac966f1
Show file tree
Hide file tree
Showing 20 changed files with 1,116 additions and 692 deletions.
10 changes: 8 additions & 2 deletions src/meta/src/hummock/compactor_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,31 +476,37 @@ impl CompactorManager {

#[cfg(test)]
mod tests {
use std::sync::Arc;
use std::time::Duration;

use risingwave_hummock_sdk::compaction_group::StaticCompactionGroupId;
use risingwave_pb::hummock::CompactTaskProgress;
use risingwave_rpc_client::HummockMetaClient;

use crate::hummock::compaction::selector::default_compaction_selector;
use crate::hummock::test_utils::{
add_ssts, register_table_ids_to_compaction_group, setup_compute_env,
};
use crate::hummock::CompactorManager;
use crate::hummock::{CompactorManager, MockHummockMetaClient};

#[tokio::test]
async fn test_compactor_manager() {
// Initialize metastore with task assignment.
let (env, context_id) = {
let (env, hummock_manager, _cluster_manager, worker_node) = setup_compute_env(80).await;
let context_id = worker_node.id;
let hummock_meta_client: Arc<dyn HummockMetaClient> = Arc::new(
MockHummockMetaClient::new(hummock_manager.clone(), worker_node.id),
);
let compactor_manager = hummock_manager.compactor_manager_ref_for_test();
register_table_ids_to_compaction_group(
hummock_manager.as_ref(),
&[1],
StaticCompactionGroupId::StateDefault.into(),
)
.await;
let _sst_infos = add_ssts(1, hummock_manager.as_ref(), context_id).await;
let _sst_infos =
add_ssts(1, hummock_manager.as_ref(), hummock_meta_client.clone()).await;
let _receiver = compactor_manager.add_compactor(context_id);
hummock_manager
.get_compact_task(
Expand Down
31 changes: 0 additions & 31 deletions src/meta/src/hummock/manager/commit_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,6 @@ pub struct CommitEpochInfo {
}

impl HummockManager {
#[cfg(any(test, feature = "test"))]
pub async fn commit_epoch_for_test(
&self,
epoch: u64,
sstables: Vec<impl Into<LocalSstableInfo>>,
sst_to_context: HashMap<HummockSstableObjectId, HummockContextId>,
) -> Result<()> {
let tables = self
.versioning
.read()
.await
.current_version
.state_table_info
.info()
.keys()
.cloned()
.collect();
let info = CommitEpochInfo {
sstables: sstables.into_iter().map(Into::into).collect(),
new_table_watermarks: HashMap::new(),
sst_to_context,
new_table_fragment_info: NewTableFragmentInfo::None,
change_log_delta: HashMap::new(),
committed_epoch: epoch,
tables_to_commit: tables,
is_visible_table_committed_epoch: true,
};
self.commit_epoch(info).await?;
Ok(())
}

/// Caller should ensure `epoch` > `max_committed_epoch`
pub async fn commit_epoch(
&self,
Expand Down
15 changes: 14 additions & 1 deletion src/meta/src/hummock/manager/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,24 @@ mod tests {
use std::time::Duration;

use itertools::Itertools;
use risingwave_hummock_sdk::compaction_group::StaticCompactionGroupId;
use risingwave_hummock_sdk::HummockSstableObjectId;
use risingwave_rpc_client::HummockMetaClient;

use super::ResponseEvent;
use crate::hummock::test_utils::{add_test_tables, setup_compute_env};
use crate::hummock::MockHummockMetaClient;
use crate::MetaOpts;

#[tokio::test]
async fn test_full_gc() {
let (mut env, hummock_manager, cluster_manager, worker_node) = setup_compute_env(80).await;
let context_id = worker_node.id;
let hummock_meta_client: Arc<dyn HummockMetaClient> = Arc::new(MockHummockMetaClient::new(
hummock_manager.clone(),
worker_node.id,
));
let compaction_group_id = StaticCompactionGroupId::StateDefault.into();
let compactor_manager = hummock_manager.compactor_manager_ref_for_test();
// Use smaller spin interval to accelerate test.
env.opts = Arc::new(MetaOpts {
Expand Down Expand Up @@ -426,7 +434,12 @@ mod tests {
);

// All committed SST ids should be excluded from GC.
let sst_infos = add_test_tables(hummock_manager.as_ref(), context_id).await;
let sst_infos = add_test_tables(
hummock_manager.as_ref(),
hummock_meta_client.clone(),
compaction_group_id,
)
.await;
let committed_object_ids = sst_infos
.into_iter()
.flatten()
Expand Down
Loading

0 comments on commit ac966f1

Please sign in to comment.