From ea40691c71f1fa039a9ac167222c5e91d11f0ff5 Mon Sep 17 00:00:00 2001 From: discord9 Date: Fri, 26 Apr 2024 17:21:20 +0800 Subject: [PATCH] chore: some unfinished tests --- src/flow/Cargo.toml | 4 ++ src/flow/bin/mem_footprint.rs | 15 +++++++ src/flow/src/adapter.rs | 13 +++--- src/flow/src/adapter/tests.rs | 76 +++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 src/flow/bin/mem_footprint.rs create mode 100644 src/flow/src/adapter/tests.rs diff --git a/src/flow/Cargo.toml b/src/flow/Cargo.toml index 8c9bc9f179..8389dc11da 100644 --- a/src/flow/Cargo.toml +++ b/src/flow/Cargo.toml @@ -4,6 +4,10 @@ version.workspace = true edition.workspace = true license.workspace = true +[[bin]] +name = "mem-footprint" +path = "bin/mem_footprint.rs" + [lints] workspace = true diff --git a/src/flow/bin/mem_footprint.rs b/src/flow/bin/mem_footprint.rs new file mode 100644 index 0000000000..ca4081d307 --- /dev/null +++ b/src/flow/bin/mem_footprint.rs @@ -0,0 +1,15 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +fn main() {} diff --git a/src/flow/src/adapter.rs b/src/flow/src/adapter.rs index 8d85ca8320..482245f90e 100644 --- a/src/flow/src/adapter.rs +++ b/src/flow/src/adapter.rs @@ -59,7 +59,7 @@ pub struct FlowNodeManager<'subgraph> { pub task_states: BTreeMap>, /// The query engine that will be used to parse the query and convert it to a dataflow plan query_engine: Arc, - srv_map: TableIdNameMapper, + srv_map: TableInfoSource, /// contains mapping from table name to global id, and table schema worker_context: FlowWorkerContext, tick_manager: FlowTickManager, @@ -70,18 +70,21 @@ pub struct FlowNodeManager<'subgraph> { #[test] fn check_is_send() { fn is_send() {} - is_send::(); + is_send::(); is_send::(); is_send::(); } /// mapping of table name <-> table id should be query from tableinfo manager -pub struct TableIdNameMapper { +pub struct TableInfoSource { /// for query `TableId -> TableName` mapping table_info_manager: TableInfoManager, } -impl TableIdNameMapper { +impl TableInfoSource { + pub fn new(table_info_manager: TableInfoManager) -> Self { + TableInfoSource { table_info_manager } + } /// query metasrv about the table name and table id pub async fn get_table_name(&self, table_id: &TableId) -> Result { self.table_info_manager @@ -514,7 +517,7 @@ impl FlowWorkerContext { /// merely creating a mapping from table id to global id pub async fn assign_global_id_to_table( &mut self, - srv_map: &TableIdNameMapper, + srv_map: &TableInfoSource, table_id: TableId, ) -> GlobalId { if let Some((_name, gid)) = self.table_repr.get_by_table_id(&table_id) { diff --git a/src/flow/src/adapter/tests.rs b/src/flow/src/adapter/tests.rs new file mode 100644 index 0000000000..e2a948f6bf --- /dev/null +++ b/src/flow/src/adapter/tests.rs @@ -0,0 +1,76 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Somewhere integration-ish(more like mock) test for adapter module + +use common_meta::key::table_info::TableInfoKey; +use common_meta::kv_backend::memory::MemoryKvBackend; +use common_meta::kv_backend::{KvBackend, KvBackendRef}; +use datatypes::schema::{ColumnSchema, SchemaBuilder}; +use store_api::storage::ConcreteDataType; +use table::metadata::{RawTableInfo, TableInfo, TableInfoBuilder, TableMetaBuilder}; + +use super::*; + +pub fn new_test_table_info_with_name>( + table_id: TableId, + table_name: &str, + region_numbers: I, +) -> TableInfo { + let column_schemas = vec![ + ColumnSchema::new("number", ConcreteDataType::int32_datatype(), true), + ColumnSchema::new( + "ts", + ConcreteDataType::timestamp_millisecond_datatype(), + false, + ) + .with_time_index(true), + ]; + let schema = SchemaBuilder::try_from(column_schemas) + .unwrap() + .version(123) + .build() + .unwrap(); + + let meta = TableMetaBuilder::default() + .schema(Arc::new(schema)) + .primary_key_indices(vec![0]) + .engine("engine") + .next_column_id(3) + .region_numbers(region_numbers.into_iter().collect::>()) + .build() + .unwrap(); + TableInfoBuilder::default() + .table_id(table_id) + .table_version(5) + .name(table_name) + .meta(meta) + .build() + .unwrap() +} + +/// Create a mock harness for flow node manager +/// +/// containing several default table info and schema +fn mock_harness_flow_node_manager() { + let kvb = MemoryKvBackend::new(); + { + let table_id: TableId = 451; + let key = TableInfoKey::new(table_id); + let val = todo!(); + } + let kv = Arc::new(kvb) as KvBackendRef; + let info_manager = TableInfoManager::new(kv); + let meta_src = TableInfoSource::new(info_manager); +}