chore: some unfinished tests

This commit is contained in:
discord9
2024-04-26 17:21:20 +08:00
parent 640674b9bc
commit ea40691c71
4 changed files with 103 additions and 5 deletions

View File

@@ -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

View File

@@ -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() {}

View File

@@ -59,7 +59,7 @@ pub struct FlowNodeManager<'subgraph> {
pub task_states: BTreeMap<TaskId, ActiveDataflowState<'subgraph>>,
/// The query engine that will be used to parse the query and convert it to a dataflow plan
query_engine: Arc<dyn QueryEngine>,
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<T: Send>() {}
is_send::<TableIdNameMapper>();
is_send::<TableInfoSource>();
is_send::<FlowWorkerContext>();
is_send::<FlowTickManager>();
}
/// 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<TableName, Error> {
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) {

View File

@@ -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<I: IntoIterator<Item = u32>>(
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::<Vec<_>>())
.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);
}