diff --git a/compactor/src/cold.rs b/compactor/src/cold.rs index ada321affb..5dcaa586f1 100644 --- a/compactor/src/cold.rs +++ b/compactor/src/cold.rs @@ -126,7 +126,7 @@ mod tests { use arrow_util::assert_batches_sorted_eq; use backoff::BackoffConfig; use data_types::{ColumnType, CompactionLevel, ParquetFileId}; - use iox_tests::util::{TestCatalog, TestParquetFileBuilder, TestTable}; + use iox_tests::{TestCatalog, TestParquetFileBuilder, TestTable}; use iox_time::{SystemProvider, TimeProvider}; use parquet_file::storage::StorageId; use std::collections::HashMap; diff --git a/compactor/src/compact.rs b/compactor/src/compact.rs index c7177da52b..c059985fde 100644 --- a/compactor/src/compact.rs +++ b/compactor/src/compact.rs @@ -602,7 +602,7 @@ pub mod tests { ColumnId, ColumnSet, CompactionLevel, ParquetFileParams, SequenceNumber, ShardIndex, Timestamp, }; - use iox_tests::util::{TestCatalog, TestPartition}; + use iox_tests::{TestCatalog, TestPartition}; use iox_time::SystemProvider; use parquet_file::storage::StorageId; use uuid::Uuid; diff --git a/compactor/src/garbage_collector.rs b/compactor/src/garbage_collector.rs index 3110c70550..8946d9e175 100644 --- a/compactor/src/garbage_collector.rs +++ b/compactor/src/garbage_collector.rs @@ -98,7 +98,7 @@ mod tests { ShardIndex, }; use futures::{StreamExt, TryStreamExt}; - use iox_tests::util::TestCatalog; + use iox_tests::TestCatalog; use std::time::Duration; use uuid::Uuid; diff --git a/compactor/src/hot.rs b/compactor/src/hot.rs index 15e0f6de14..59f0bf7b65 100644 --- a/compactor/src/hot.rs +++ b/compactor/src/hot.rs @@ -80,7 +80,7 @@ mod tests { }; use backoff::BackoffConfig; use data_types::CompactionLevel; - use iox_tests::util::{TestCatalog, TestParquetFileBuilder, TestShard, TestTable}; + use iox_tests::{TestCatalog, TestParquetFileBuilder, TestShard, TestTable}; use iox_time::TimeProvider; use parquet_file::storage::{ParquetStorage, StorageId}; use std::sync::Arc; diff --git a/compactor/src/lib.rs b/compactor/src/lib.rs index ff4417dab5..d09acb1327 100644 --- a/compactor/src/lib.rs +++ b/compactor/src/lib.rs @@ -545,9 +545,7 @@ pub mod tests { use arrow_util::assert_batches_sorted_eq; use backoff::BackoffConfig; use data_types::{ColumnType, CompactionLevel, ParquetFileId}; - use iox_tests::util::{ - TestCatalog, TestParquetFileBuilder, TestPartition, TestShard, TestTable, - }; + use iox_tests::{TestCatalog, TestParquetFileBuilder, TestPartition, TestShard, TestTable}; use iox_time::{SystemProvider, TimeProvider}; use std::{ collections::{HashMap, VecDeque}, diff --git a/compactor/src/parquet_file.rs b/compactor/src/parquet_file.rs index cf6f1c2897..2b8cce5a95 100644 --- a/compactor/src/parquet_file.rs +++ b/compactor/src/parquet_file.rs @@ -126,7 +126,7 @@ impl From for ParquetFile { #[cfg(test)] pub mod tests { use super::*; - use iox_tests::util::TestParquetFile; + use iox_tests::TestParquetFile; impl From for CompactorParquetFile { fn from(tpf: TestParquetFile) -> Self { diff --git a/compactor/src/parquet_file_combining.rs b/compactor/src/parquet_file_combining.rs index 70ce4d3e61..b713b98e68 100644 --- a/compactor/src/parquet_file_combining.rs +++ b/compactor/src/parquet_file_combining.rs @@ -884,7 +884,7 @@ mod tests { use arrow::record_batch::RecordBatch; use arrow_util::{assert_batches_eq, assert_batches_sorted_eq}; use data_types::{ColumnType, PartitionParam}; - use iox_tests::util::{TestCatalog, TestParquetFileBuilder, TestTable}; + use iox_tests::{TestCatalog, TestParquetFileBuilder, TestTable}; use iox_time::SystemProvider; use itertools::Itertools; use metric::U64HistogramOptions; diff --git a/compactor/src/parquet_file_lookup.rs b/compactor/src/parquet_file_lookup.rs index 14551fb674..76add8b27a 100644 --- a/compactor/src/parquet_file_lookup.rs +++ b/compactor/src/parquet_file_lookup.rs @@ -211,7 +211,7 @@ mod tests { use super::*; use backoff::BackoffConfig; use data_types::ColumnType; - use iox_tests::util::{TestCatalog, TestParquetFileBuilder, TestPartition}; + use iox_tests::{TestCatalog, TestParquetFileBuilder, TestPartition}; use iox_time::{SystemProvider, TimeProvider}; use parquet_file::storage::{ParquetStorage, StorageId}; diff --git a/compactor/src/query.rs b/compactor/src/query.rs index df4e299663..27759d9815 100644 --- a/compactor/src/query.rs +++ b/compactor/src/query.rs @@ -233,7 +233,7 @@ impl QueryChunk for QueryableParquetChunk { mod tests { use super::*; use data_types::ColumnType; - use iox_tests::util::{TestCatalog, TestParquetFileBuilder}; + use iox_tests::{TestCatalog, TestParquetFileBuilder}; use iox_time::{SystemProvider, TimeProvider}; use parquet_file::storage::{ParquetStorage, StorageId}; diff --git a/compactor/src/warm.rs b/compactor/src/warm.rs index 24084133c6..bbbf3db5ca 100644 --- a/compactor/src/warm.rs +++ b/compactor/src/warm.rs @@ -77,7 +77,7 @@ mod tests { use backoff::BackoffConfig; use data_types::{ColumnType, CompactionLevel, TablePartition, Timestamp}; use futures::{stream::FuturesUnordered, StreamExt}; - use iox_tests::util::{TestCatalog, TestParquetFileBuilder}; + use iox_tests::{TestCatalog, TestParquetFileBuilder}; use iox_time::{SystemProvider, Time, TimeProvider}; use parquet_file::storage::{ParquetStorage, StorageId}; use std::sync::Arc; diff --git a/compactor2/src/components/commit/logging.rs b/compactor2/src/components/commit/logging.rs index 4750d4dc4e..0bd1789372 100644 --- a/compactor2/src/components/commit/logging.rs +++ b/compactor2/src/components/commit/logging.rs @@ -82,12 +82,9 @@ mod tests { use test_helpers::tracing::TracingCapture; - use crate::{ - components::commit::mock::{CommitHistoryEntry, MockCommit}, - test_util::ParquetFileBuilder, - }; - use super::*; + use crate::components::commit::mock::{CommitHistoryEntry, MockCommit}; + use iox_tests::ParquetFileBuilder; #[test] fn test_display() { diff --git a/compactor2/src/components/commit/metrics.rs b/compactor2/src/components/commit/metrics.rs index 88c8cd1a30..5adfdd8389 100644 --- a/compactor2/src/components/commit/metrics.rs +++ b/compactor2/src/components/commit/metrics.rs @@ -208,10 +208,8 @@ mod tests { use metric::{Attributes, HistogramObservation, Metric}; - use crate::{ - components::commit::mock::{CommitHistoryEntry, MockCommit}, - test_util::ParquetFileBuilder, - }; + use crate::components::commit::mock::{CommitHistoryEntry, MockCommit}; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/commit/mock.rs b/compactor2/src/components/commit/mock.rs index 71295af25a..17a68c33b8 100644 --- a/compactor2/src/components/commit/mock.rs +++ b/compactor2/src/components/commit/mock.rs @@ -83,7 +83,7 @@ impl Commit for MockCommit { #[cfg(test)] mod tests { - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/divide_initial/single_branch.rs b/compactor2/src/components/divide_initial/single_branch.rs index 8de9527fdc..1a420ffd40 100644 --- a/compactor2/src/components/divide_initial/single_branch.rs +++ b/compactor2/src/components/divide_initial/single_branch.rs @@ -31,7 +31,7 @@ impl DivideInitial for SingleBranchDivideInitial { #[cfg(test)] mod tests { - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/file_filter/level_range.rs b/compactor2/src/components/file_filter/level_range.rs index 71cd83b93e..2441dede93 100644 --- a/compactor2/src/components/file_filter/level_range.rs +++ b/compactor2/src/components/file_filter/level_range.rs @@ -34,7 +34,7 @@ impl FileFilter for LevelRangeFileFilter { #[cfg(test)] mod tests { - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/level_exist/one_level.rs b/compactor2/src/components/level_exist/one_level.rs index e4c6087513..21042fdfa7 100644 --- a/compactor2/src/components/level_exist/one_level.rs +++ b/compactor2/src/components/level_exist/one_level.rs @@ -27,7 +27,7 @@ impl LevelExist for OneLevelExist { #[cfg(test)] mod tests { - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_files_source/mock.rs b/compactor2/src/components/partition_files_source/mock.rs index f04e7c62a6..ee82915bcf 100644 --- a/compactor2/src/components/partition_files_source/mock.rs +++ b/compactor2/src/components/partition_files_source/mock.rs @@ -32,7 +32,7 @@ impl PartitionFilesSource for MockPartitionFilesSource { #[cfg(test)] mod tests { - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_filter/greater_matching_files.rs b/compactor2/src/components/partition_filter/greater_matching_files.rs index e4e4627eb2..0fac590488 100644 --- a/compactor2/src/components/partition_filter/greater_matching_files.rs +++ b/compactor2/src/components/partition_filter/greater_matching_files.rs @@ -61,9 +61,8 @@ where mod tests { use data_types::CompactionLevel; - use crate::{ - components::file_filter::level_range::LevelRangeFileFilter, test_util::ParquetFileBuilder, - }; + use crate::components::file_filter::level_range::LevelRangeFileFilter; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_filter/greater_size_matching_files.rs b/compactor2/src/components/partition_filter/greater_size_matching_files.rs index ff483cdeab..056efb10df 100644 --- a/compactor2/src/components/partition_filter/greater_size_matching_files.rs +++ b/compactor2/src/components/partition_filter/greater_size_matching_files.rs @@ -74,9 +74,8 @@ where mod tests { use data_types::CompactionLevel; - use crate::{ - components::file_filter::level_range::LevelRangeFileFilter, test_util::ParquetFileBuilder, - }; + use crate::components::file_filter::level_range::LevelRangeFileFilter; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_filter/has_files.rs b/compactor2/src/components/partition_filter/has_files.rs index 3b91df564e..ac412eb4d6 100644 --- a/compactor2/src/components/partition_filter/has_files.rs +++ b/compactor2/src/components/partition_filter/has_files.rs @@ -35,7 +35,7 @@ impl PartitionFilter for HasFilesPartitionFilter { #[cfg(test)] mod tests { - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_filter/has_matching_file.rs b/compactor2/src/components/partition_filter/has_matching_file.rs index 62c7105cf1..a8f0bf7284 100644 --- a/compactor2/src/components/partition_filter/has_matching_file.rs +++ b/compactor2/src/components/partition_filter/has_matching_file.rs @@ -51,9 +51,8 @@ where mod tests { use data_types::CompactionLevel; - use crate::{ - components::file_filter::level_range::LevelRangeFileFilter, test_util::ParquetFileBuilder, - }; + use crate::components::file_filter::level_range::LevelRangeFileFilter; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_filter/logging.rs b/compactor2/src/components/partition_filter/logging.rs index 2b3c8c2b3d..f5afd8d581 100644 --- a/compactor2/src/components/partition_filter/logging.rs +++ b/compactor2/src/components/partition_filter/logging.rs @@ -73,10 +73,8 @@ where mod tests { use test_helpers::tracing::TracingCapture; - use crate::{ - components::partition_filter::has_files::HasFilesPartitionFilter, - test_util::ParquetFileBuilder, - }; + use crate::components::partition_filter::has_files::HasFilesPartitionFilter; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_filter/max_files.rs b/compactor2/src/components/partition_filter/max_files.rs index 8a0061783d..2e25359bb2 100644 --- a/compactor2/src/components/partition_filter/max_files.rs +++ b/compactor2/src/components/partition_filter/max_files.rs @@ -50,7 +50,8 @@ impl PartitionFilter for MaxFilesPartitionFilter { #[cfg(test)] mod tests { - use crate::{error::ErrorKindExt, test_util::ParquetFileBuilder}; + use crate::error::ErrorKindExt; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_filter/max_parquet_bytes.rs b/compactor2/src/components/partition_filter/max_parquet_bytes.rs index 061c751a10..ed285a05e4 100644 --- a/compactor2/src/components/partition_filter/max_parquet_bytes.rs +++ b/compactor2/src/components/partition_filter/max_parquet_bytes.rs @@ -53,7 +53,8 @@ impl PartitionFilter for MaxParquetBytesPartitionFilter { #[cfg(test)] mod tests { - use crate::{error::ErrorKindExt, test_util::ParquetFileBuilder}; + use crate::error::ErrorKindExt; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_filter/metrics.rs b/compactor2/src/components/partition_filter/metrics.rs index 1f2b1cf660..f9a938c2b6 100644 --- a/compactor2/src/components/partition_filter/metrics.rs +++ b/compactor2/src/components/partition_filter/metrics.rs @@ -83,10 +83,8 @@ where mod tests { use metric::{Attributes, Metric}; - use crate::{ - components::partition_filter::has_files::HasFilesPartitionFilter, - test_util::ParquetFileBuilder, - }; + use crate::components::partition_filter::has_files::HasFilesPartitionFilter; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/partition_source/logging.rs b/compactor2/src/components/partition_source/logging.rs index 5f679f0780..544f3e8a8d 100644 --- a/compactor2/src/components/partition_source/logging.rs +++ b/compactor2/src/components/partition_source/logging.rs @@ -55,9 +55,8 @@ where mod tests { use test_helpers::tracing::TracingCapture; - use crate::{ - components::partition_source::mock::MockPartitionSource, test_util::PartitionBuilder, - }; + use crate::components::partition_source::mock::MockPartitionSource; + use iox_tests::PartitionBuilder; use super::*; diff --git a/compactor2/src/components/partition_source/metrics.rs b/compactor2/src/components/partition_source/metrics.rs index c9ce473013..9f16e810fb 100644 --- a/compactor2/src/components/partition_source/metrics.rs +++ b/compactor2/src/components/partition_source/metrics.rs @@ -64,9 +64,8 @@ where mod tests { use metric::{Attributes, Metric}; - use crate::{ - components::partition_source::mock::MockPartitionSource, test_util::PartitionBuilder, - }; + use crate::components::partition_source::mock::MockPartitionSource; + use iox_tests::PartitionBuilder; use super::*; diff --git a/compactor2/src/components/partition_source/mock.rs b/compactor2/src/components/partition_source/mock.rs index 40d7c35bf2..d1aa3d5272 100644 --- a/compactor2/src/components/partition_source/mock.rs +++ b/compactor2/src/components/partition_source/mock.rs @@ -35,7 +35,7 @@ impl PartitionSource for MockPartitionSource { #[cfg(test)] mod tests { - use crate::test_util::PartitionBuilder; + use iox_tests::PartitionBuilder; use super::*; diff --git a/compactor2/src/components/round_split/all_now.rs b/compactor2/src/components/round_split/all_now.rs index 4287d8cedb..bf1d401a3a 100644 --- a/compactor2/src/components/round_split/all_now.rs +++ b/compactor2/src/components/round_split/all_now.rs @@ -27,7 +27,7 @@ impl RoundSplit for AllNowRoundSplit { #[cfg(test)] mod tests { - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/skipped_compactions_source/mock.rs b/compactor2/src/components/skipped_compactions_source/mock.rs index de1947321d..83961d222a 100644 --- a/compactor2/src/components/skipped_compactions_source/mock.rs +++ b/compactor2/src/components/skipped_compactions_source/mock.rs @@ -34,7 +34,7 @@ impl SkippedCompactionsSource for MockSkippedCompactionsSource { #[cfg(test)] mod tests { - use crate::test_util::SkippedCompactionBuilder; + use iox_tests::SkippedCompactionBuilder; use super::*; diff --git a/compactor2/src/components/tables_source/mock.rs b/compactor2/src/components/tables_source/mock.rs index c8484ca5b0..777a77d085 100644 --- a/compactor2/src/components/tables_source/mock.rs +++ b/compactor2/src/components/tables_source/mock.rs @@ -32,7 +32,7 @@ impl TablesSource for MockTablesSource { #[cfg(test)] mod tests { - use crate::test_util::TableBuilder; + use iox_tests::TableBuilder; use super::*; diff --git a/compactor2/src/components/target_level_chooser/all_at_once.rs b/compactor2/src/components/target_level_chooser/all_at_once.rs index 2c6ab08363..0d97b2e6e6 100644 --- a/compactor2/src/components/target_level_chooser/all_at_once.rs +++ b/compactor2/src/components/target_level_chooser/all_at_once.rs @@ -37,7 +37,7 @@ impl TargetLevelChooser for AllAtOnceTargetLevelChooser { #[cfg(test)] mod tests { - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/components/target_level_chooser/target_level.rs b/compactor2/src/components/target_level_chooser/target_level.rs index 67a3f288e1..e0d2340d28 100644 --- a/compactor2/src/components/target_level_chooser/target_level.rs +++ b/compactor2/src/components/target_level_chooser/target_level.rs @@ -58,7 +58,8 @@ where #[cfg(test)] mod tests { - use crate::{components::level_exist::one_level::OneLevelExist, test_util::ParquetFileBuilder}; + use crate::components::level_exist::one_level::OneLevelExist; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/file_group.rs b/compactor2/src/file_group.rs index 8418035df0..14bfd6e938 100644 --- a/compactor2/src/file_group.rs +++ b/compactor2/src/file_group.rs @@ -71,7 +71,7 @@ pub fn split_by_level( #[cfg(test)] mod test { use super::*; - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; #[test] fn files_time_range_empty() { diff --git a/compactor2/src/test_util.rs b/compactor2/src/test_util.rs index d133307e01..64e701b2f3 100644 --- a/compactor2/src/test_util.rs +++ b/compactor2/src/test_util.rs @@ -14,21 +14,20 @@ use std::{ use async_trait::async_trait; use backoff::BackoffConfig; use data_types::{ - ColumnId, ColumnSchema, ColumnSet, ColumnType, CompactionLevel, Namespace, NamespaceId, - NamespaceSchema, ParquetFile, ParquetFileId, Partition, PartitionId, PartitionKey, QueryPoolId, - SequenceNumber, ShardId, SkippedCompaction, Table, TableId, TableSchema, Timestamp, TopicId, + ColumnId, ColumnSchema, ColumnType, CompactionLevel, Namespace, NamespaceId, NamespaceSchema, + ParquetFile, PartitionId, PartitionKey, QueryPoolId, Table, TableId, TableSchema, TopicId, TRANSITION_SHARD_NUMBER, }; use datafusion::arrow::record_batch::RecordBatch; use futures::TryStreamExt; -use iox_tests::util::{ - TestCatalog, TestNamespace, TestParquetFileBuilder, TestPartition, TestShard, TestTable, +use iox_tests::{ + ParquetFileBuilder, TestCatalog, TestNamespace, TestParquetFileBuilder, TestPartition, + TestShard, TestTable, }; use iox_time::TimeProvider; use object_store::{path::Path, DynObjectStore}; use parquet_file::storage::{ParquetStorage, StorageId}; use schema::sort::SortKey; -use uuid::Uuid; use crate::{ components::{ @@ -42,116 +41,7 @@ use crate::{ }; #[derive(Debug)] -pub struct ParquetFileBuilder { - file: ParquetFile, -} - -impl ParquetFileBuilder { - pub fn new(id: i64) -> Self { - Self { - file: ParquetFile { - id: ParquetFileId::new(id), - shard_id: ShardId::new(0), - namespace_id: NamespaceId::new(0), - table_id: TableId::new(0), - partition_id: PartitionId::new(0), - object_store_id: Uuid::from_u128(id.try_into().expect("invalid id")), - max_sequence_number: SequenceNumber::new(0), - min_time: Timestamp::new(0), - max_time: Timestamp::new(0), - to_delete: None, - file_size_bytes: 1, - row_count: 1, - compaction_level: CompactionLevel::FileNonOverlapped, - created_at: Timestamp::new(0), - column_set: ColumnSet::new(vec![]), - max_l0_created_at: Timestamp::new(0), - }, - } - } - - pub fn with_partition(self, id: i64) -> Self { - Self { - file: ParquetFile { - partition_id: PartitionId::new(id), - ..self.file - }, - } - } - - pub fn with_compaction_level(self, level: CompactionLevel) -> Self { - Self { - file: ParquetFile { - compaction_level: level, - ..self.file - }, - } - } - - pub fn with_file_size_bytes(self, file_size_bytes: i64) -> Self { - Self { - file: ParquetFile { - file_size_bytes, - ..self.file - }, - } - } - - pub fn with_time_range(self, min_time: i64, max_time: i64) -> Self { - Self { - file: ParquetFile { - min_time: Timestamp::new(min_time), - max_time: Timestamp::new(max_time), - ..self.file - }, - } - } - - pub fn with_row_count(self, row_count: i64) -> Self { - Self { - file: ParquetFile { - row_count, - ..self.file - }, - } - } - - pub fn build(self) -> ParquetFile { - self.file - } -} - -#[derive(Debug)] -pub struct TableBuilder { - table: Table, -} - -impl TableBuilder { - pub fn new(id: i64) -> Self { - Self { - table: Table { - id: TableId::new(id), - namespace_id: NamespaceId::new(0), - name: "table".to_string(), - }, - } - } - - pub fn with_name(self, name: &str) -> Self { - Self { - table: Table { - name: name.to_string(), - ..self.table - }, - } - } - - pub fn build(self) -> Table { - self.table - } -} - -#[derive(Debug)] +/// Build [`NamespaceWrapper`] for testing pub struct NamespaceBuilder { namespace: NamespaceWrapper, } @@ -245,66 +135,6 @@ impl NamespaceBuilder { } } -#[derive(Debug)] -pub struct PartitionBuilder { - partition: Partition, -} - -impl PartitionBuilder { - pub fn new(id: i64) -> Self { - Self { - partition: Partition { - id: PartitionId::new(id), - shard_id: ShardId::new(0), - table_id: TableId::new(0), - partition_key: PartitionKey::from("key"), - sort_key: vec![], - persisted_sequence_number: None, - new_file_at: None, - }, - } - } - - pub fn build(self) -> Partition { - self.partition - } -} - -#[derive(Debug)] -pub struct SkippedCompactionBuilder { - skipped_compaction: SkippedCompaction, -} - -impl SkippedCompactionBuilder { - pub fn new(id: i64) -> Self { - Self { - skipped_compaction: SkippedCompaction { - partition_id: PartitionId::new(id), - reason: "test skipped compaction".to_string(), - skipped_at: Timestamp::new(0), - num_files: 0, - limit_num_files: 0, - estimated_bytes: 0, - limit_bytes: 0, - limit_num_files_first_in_partition: 0, - }, - } - } - - pub fn with_reason(self, reason: &str) -> Self { - Self { - skipped_compaction: SkippedCompaction { - reason: reason.to_string(), - ..self.skipped_compaction - }, - } - } - - pub fn build(self) -> SkippedCompaction { - self.skipped_compaction - } -} - // Default values for the test setup builder const SHARD_INDEX: i32 = TRANSITION_SHARD_NUMBER; const PARTITION_THRESHOLD: Duration = Duration::from_secs(10 * 60); // 10min diff --git a/compactor2/src/test_util/display.rs b/compactor2/src/test_util/display.rs index f45504bcfc..46aaf8bceb 100644 --- a/compactor2/src/test_util/display.rs +++ b/compactor2/src/test_util/display.rs @@ -297,7 +297,7 @@ fn display_format(file: &ParquetFile, show_size: bool) -> String { #[cfg(test)] mod test { - use crate::test_util::ParquetFileBuilder; + use iox_tests::ParquetFileBuilder; use super::*; diff --git a/compactor2/src/tests.rs b/compactor2/src/tests.rs index f9a05800d9..d563f07097 100644 --- a/compactor2/src/tests.rs +++ b/compactor2/src/tests.rs @@ -2,7 +2,7 @@ use std::time::Duration; use arrow_util::assert_batches_sorted_eq; use data_types::{CompactionLevel, ParquetFile, PartitionId}; -use iox_tests::util::TestParquetFileBuilder; +use iox_tests::TestParquetFileBuilder; use crate::{ config::AlgoVersion, diff --git a/iox_tests/src/builders.rs b/iox_tests/src/builders.rs new file mode 100644 index 0000000000..785be2ad5b --- /dev/null +++ b/iox_tests/src/builders.rs @@ -0,0 +1,195 @@ +use data_types::{ + ColumnSet, CompactionLevel, NamespaceId, ParquetFile, ParquetFileId, Partition, PartitionId, + PartitionKey, SequenceNumber, ShardId, SkippedCompaction, Table, TableId, Timestamp, +}; +use uuid::Uuid; + +#[derive(Debug)] +/// Build up [`ParquetFile`]s for testing +pub struct ParquetFileBuilder { + file: ParquetFile, +} + +impl ParquetFileBuilder { + /// Create a builder that will create a parquet file with + /// `parquet_id` of `id` + pub fn new(id: i64) -> Self { + Self { + file: ParquetFile { + id: ParquetFileId::new(id), + shard_id: ShardId::new(0), + namespace_id: NamespaceId::new(0), + table_id: TableId::new(0), + partition_id: PartitionId::new(0), + object_store_id: Uuid::from_u128(id.try_into().expect("invalid id")), + max_sequence_number: SequenceNumber::new(0), + min_time: Timestamp::new(0), + max_time: Timestamp::new(0), + to_delete: None, + file_size_bytes: 1, + row_count: 1, + compaction_level: CompactionLevel::FileNonOverlapped, + created_at: Timestamp::new(0), + column_set: ColumnSet::new(vec![]), + max_l0_created_at: Timestamp::new(0), + }, + } + } + + /// Set the partition id + pub fn with_partition(self, id: i64) -> Self { + Self { + file: ParquetFile { + partition_id: PartitionId::new(id), + ..self.file + }, + } + } + + /// Set the compaction level + pub fn with_compaction_level(self, level: CompactionLevel) -> Self { + Self { + file: ParquetFile { + compaction_level: level, + ..self.file + }, + } + } + + /// Set the file size + pub fn with_file_size_bytes(self, file_size_bytes: i64) -> Self { + Self { + file: ParquetFile { + file_size_bytes, + ..self.file + }, + } + } + + /// Set the min/max time range + pub fn with_time_range(self, min_time: i64, max_time: i64) -> Self { + Self { + file: ParquetFile { + min_time: Timestamp::new(min_time), + max_time: Timestamp::new(max_time), + ..self.file + }, + } + } + + /// Set the row_count + pub fn with_row_count(self, row_count: i64) -> Self { + Self { + file: ParquetFile { + row_count, + ..self.file + }, + } + } + + /// Create the [`ParquetFile`] + pub fn build(self) -> ParquetFile { + self.file + } +} + +#[derive(Debug)] +/// Build [`Table`]s for testing +pub struct TableBuilder { + table: Table, +} + +impl TableBuilder { + /// Create a builder to create a table with `table_id` `id` + pub fn new(id: i64) -> Self { + Self { + table: Table { + id: TableId::new(id), + namespace_id: NamespaceId::new(0), + name: "table".to_string(), + }, + } + } + + /// Set the table name + pub fn with_name(self, name: &str) -> Self { + Self { + table: Table { + name: name.to_string(), + ..self.table + }, + } + } + + /// Create the table + pub fn build(self) -> Table { + self.table + } +} + +#[derive(Debug)] +/// Builds [`Partition`]s for testing +pub struct PartitionBuilder { + partition: Partition, +} + +impl PartitionBuilder { + /// Create a builder to create a partition with `partition_id` `id` + pub fn new(id: i64) -> Self { + Self { + partition: Partition { + id: PartitionId::new(id), + shard_id: ShardId::new(0), + table_id: TableId::new(0), + partition_key: PartitionKey::from("key"), + sort_key: vec![], + persisted_sequence_number: None, + new_file_at: None, + }, + } + } + + /// Create the partition + pub fn build(self) -> Partition { + self.partition + } +} + +#[derive(Debug)] +/// A builder to create a skipped compaction record +pub struct SkippedCompactionBuilder { + skipped_compaction: SkippedCompaction, +} + +impl SkippedCompactionBuilder { + /// Create the builder for skipped_compaction_id = id + pub fn new(id: i64) -> Self { + Self { + skipped_compaction: SkippedCompaction { + partition_id: PartitionId::new(id), + reason: "test skipped compaction".to_string(), + skipped_at: Timestamp::new(0), + num_files: 0, + limit_num_files: 0, + estimated_bytes: 0, + limit_bytes: 0, + limit_num_files_first_in_partition: 0, + }, + } + } + + /// Add a reason for the skipped compaction + pub fn with_reason(self, reason: &str) -> Self { + Self { + skipped_compaction: SkippedCompaction { + reason: reason.to_string(), + ..self.skipped_compaction + }, + } + } + + /// Build the skipped compaction + pub fn build(self) -> SkippedCompaction { + self.skipped_compaction + } +} diff --git a/iox_tests/src/util.rs b/iox_tests/src/catalog.rs similarity index 100% rename from iox_tests/src/util.rs rename to iox_tests/src/catalog.rs diff --git a/iox_tests/src/lib.rs b/iox_tests/src/lib.rs index 3589e1242e..b3d1ade6b8 100644 --- a/iox_tests/src/lib.rs +++ b/iox_tests/src/lib.rs @@ -12,4 +12,11 @@ clippy::dbg_macro )] -pub mod util; +mod catalog; +pub use catalog::{ + TestCatalog, TestNamespace, TestParquetFile, TestParquetFileBuilder, TestPartition, TestShard, + TestTable, +}; + +mod builders; +pub use builders::{ParquetFileBuilder, PartitionBuilder, SkippedCompactionBuilder, TableBuilder}; diff --git a/ioxd_querier/src/rpc/namespace.rs b/ioxd_querier/src/rpc/namespace.rs index 052b6cc03d..bfd6ce1048 100644 --- a/ioxd_querier/src/rpc/namespace.rs +++ b/ioxd_querier/src/rpc/namespace.rs @@ -88,7 +88,7 @@ impl proto::namespace_service_server::NamespaceService for NamespaceServiceImpl mod tests { use super::*; use generated_types::influxdata::iox::namespace::v1::namespace_service_server::NamespaceService; - use iox_tests::util::TestCatalog; + use iox_tests::TestCatalog; use querier::{create_ingester_connection_for_testing, QuerierCatalogCache}; use tokio::runtime::Handle; diff --git a/querier/src/cache/namespace.rs b/querier/src/cache/namespace.rs index 7d862c97ed..c193db3c4d 100644 --- a/querier/src/cache/namespace.rs +++ b/querier/src/cache/namespace.rs @@ -318,7 +318,7 @@ mod tests { use crate::cache::{ram::test_util::test_ram_pool, test_util::assert_histogram_metric_count}; use arrow::datatypes::DataType; use data_types::ColumnType; - use iox_tests::util::TestCatalog; + use iox_tests::TestCatalog; use schema::SchemaBuilder; use super::*; diff --git a/querier/src/cache/parquet_file.rs b/querier/src/cache/parquet_file.rs index 79d31b4995..0bc9f46307 100644 --- a/querier/src/cache/parquet_file.rs +++ b/querier/src/cache/parquet_file.rs @@ -314,7 +314,7 @@ mod tests { use super::*; use data_types::{ColumnType, ParquetFileId}; - use iox_tests::util::{ + use iox_tests::{ TestCatalog, TestNamespace, TestParquetFile, TestParquetFileBuilder, TestPartition, TestTable, }; diff --git a/querier/src/cache/partition.rs b/querier/src/cache/partition.rs index 53fa8ae145..1a7b1ece77 100644 --- a/querier/src/cache/partition.rs +++ b/querier/src/cache/partition.rs @@ -224,7 +224,7 @@ mod tests { use super::*; use crate::cache::{ram::test_util::test_ram_pool, test_util::assert_histogram_metric_count}; use data_types::ColumnType; - use iox_tests::util::TestCatalog; + use iox_tests::TestCatalog; use schema::{Schema, SchemaBuilder}; #[tokio::test] diff --git a/querier/src/cache/processed_tombstones.rs b/querier/src/cache/processed_tombstones.rs index 15455c4e7d..7ab1657c58 100644 --- a/querier/src/cache/processed_tombstones.rs +++ b/querier/src/cache/processed_tombstones.rs @@ -139,7 +139,7 @@ mod tests { use super::*; use crate::cache::{ram::test_util::test_ram_pool, test_util::assert_histogram_metric_count}; use data_types::ColumnType; - use iox_tests::util::{TestCatalog, TestParquetFileBuilder}; + use iox_tests::{TestCatalog, TestParquetFileBuilder}; const TABLE_LINE_PROTOCOL: &str = "table foo=1 11"; diff --git a/querier/src/cache/tombstones.rs b/querier/src/cache/tombstones.rs index d92cd50a67..a819585dcc 100644 --- a/querier/src/cache/tombstones.rs +++ b/querier/src/cache/tombstones.rs @@ -215,7 +215,7 @@ mod tests { use super::*; use data_types::TombstoneId; - use iox_tests::util::TestCatalog; + use iox_tests::TestCatalog; use crate::cache::{ram::test_util::test_ram_pool, test_util::assert_histogram_metric_count}; diff --git a/querier/src/database.rs b/querier/src/database.rs index fa8480bd51..a8c2aa080d 100644 --- a/querier/src/database.rs +++ b/querier/src/database.rs @@ -239,7 +239,7 @@ pub async fn create_sharder( mod tests { use super::*; use crate::create_ingester_connection_for_testing; - use iox_tests::util::TestCatalog; + use iox_tests::TestCatalog; use test_helpers::assert_error; use tokio::runtime::Handle; diff --git a/querier/src/ingester/mod.rs b/querier/src/ingester/mod.rs index 816ea96327..9ca1b03e42 100644 --- a/querier/src/ingester/mod.rs +++ b/querier/src/ingester/mod.rs @@ -1393,7 +1393,7 @@ mod tests { use data_types::TableId; use generated_types::influxdata::iox::ingester::v1::PartitionStatus; use influxdb_iox_client::flight::generated_types::IngesterQueryResponseMetadata; - use iox_tests::util::TestCatalog; + use iox_tests::TestCatalog; use metric::Attributes; use mutable_batch_lp::test_helpers::lp_to_mutable_batch; use schema::{builder::SchemaBuilder, InfluxFieldType}; diff --git a/querier/src/namespace/mod.rs b/querier/src/namespace/mod.rs index c984527c15..5be1b5dee5 100644 --- a/querier/src/namespace/mod.rs +++ b/querier/src/namespace/mod.rs @@ -141,7 +141,7 @@ mod tests { use super::*; use crate::namespace::test_util::querier_namespace; use data_types::ColumnType; - use iox_tests::util::TestCatalog; + use iox_tests::TestCatalog; use schema::{ builder::SchemaBuilder, InfluxColumnType, InfluxFieldType, Schema, TIME_COLUMN_NAME, }; diff --git a/querier/src/namespace/query_access.rs b/querier/src/namespace/query_access.rs index 56a8e2508c..9cad152509 100644 --- a/querier/src/namespace/query_access.rs +++ b/querier/src/namespace/query_access.rs @@ -203,7 +203,7 @@ mod tests { use data_types::ColumnType; use datafusion::common::DataFusionError; use iox_query::frontend::sql::SqlQueryPlanner; - use iox_tests::util::{TestCatalog, TestParquetFileBuilder}; + use iox_tests::{TestCatalog, TestParquetFileBuilder}; use metric::{Observation, RawReporter}; use regex::Regex; use snafu::{ResultExt, Snafu}; diff --git a/querier/src/namespace/test_util.rs b/querier/src/namespace/test_util.rs index c4ab169663..174bf85c6a 100644 --- a/querier/src/namespace/test_util.rs +++ b/querier/src/namespace/test_util.rs @@ -5,7 +5,7 @@ use crate::{ use data_types::{ShardIndex, TableId}; use iox_catalog::interface::get_schema_by_name; use iox_query::exec::ExecutorType; -use iox_tests::util::TestNamespace; +use iox_tests::TestNamespace; use sharder::JumpHash; use std::sync::Arc; use tokio::runtime::Handle; diff --git a/querier/src/parquet/mod.rs b/querier/src/parquet/mod.rs index 6778d599cd..465d9c2a54 100644 --- a/querier/src/parquet/mod.rs +++ b/querier/src/parquet/mod.rs @@ -172,7 +172,7 @@ pub mod tests { exec::{ExecutorType, IOxSessionContext}, QueryChunk, QueryChunkMeta, }; - use iox_tests::util::{TestCatalog, TestNamespace, TestParquetFileBuilder}; + use iox_tests::{TestCatalog, TestNamespace, TestParquetFileBuilder}; use metric::{Attributes, Observation, RawReporter}; use predicate::Predicate; use schema::{builder::SchemaBuilder, sort::SortKeyBuilder}; diff --git a/querier/src/table/mod.rs b/querier/src/table/mod.rs index 9d03e6cd11..6440c10bcf 100644 --- a/querier/src/table/mod.rs +++ b/querier/src/table/mod.rs @@ -556,7 +556,7 @@ mod tests { use assert_matches::assert_matches; use data_types::{ChunkId, ColumnType, CompactionLevel, SequenceNumber}; use iox_query::exec::IOxSessionContext; - use iox_tests::util::{TestCatalog, TestParquetFileBuilder, TestTable}; + use iox_tests::{TestCatalog, TestParquetFileBuilder, TestTable}; use iox_time::TimeProvider; use predicate::Predicate; use schema::{builder::SchemaBuilder, InfluxFieldType}; diff --git a/querier/src/table/test_util.rs b/querier/src/table/test_util.rs index f1920504b2..fdded1cc14 100644 --- a/querier/src/table/test_util.rs +++ b/querier/src/table/test_util.rs @@ -6,7 +6,7 @@ use crate::{ use arrow::record_batch::RecordBatch; use data_types::{ChunkId, SequenceNumber, ShardIndex}; use iox_catalog::interface::get_schema_by_name; -use iox_tests::util::{TestCatalog, TestPartition, TestShard, TestTable}; +use iox_tests::{TestCatalog, TestPartition, TestShard, TestTable}; use mutable_batch_lp::test_helpers::lp_to_mutable_batch; use schema::{sort::SortKey, Projection, Schema}; use sharder::JumpHash; diff --git a/router/src/dml_handlers/retention_validator.rs b/router/src/dml_handlers/retention_validator.rs index 2452ad2b2c..63becbef38 100644 --- a/router/src/dml_handlers/retention_validator.rs +++ b/router/src/dml_handlers/retention_validator.rs @@ -127,7 +127,7 @@ where #[cfg(test)] mod tests { - use iox_tests::util::{TestCatalog, TestNamespace}; + use iox_tests::{TestCatalog, TestNamespace}; use once_cell::sync::Lazy; use std::sync::Arc; diff --git a/router/src/dml_handlers/schema_validation.rs b/router/src/dml_handlers/schema_validation.rs index 2345e6e732..11689a8b86 100644 --- a/router/src/dml_handlers/schema_validation.rs +++ b/router/src/dml_handlers/schema_validation.rs @@ -487,7 +487,7 @@ mod tests { use assert_matches::assert_matches; use data_types::{ColumnType, TimestampRange}; - use iox_tests::util::{TestCatalog, TestNamespace}; + use iox_tests::{TestCatalog, TestNamespace}; use once_cell::sync::Lazy; use super::*;