Skip to main content

log_store/test_util/
log_store_util.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::path::Path;
16
17use common_base::readable_size::ReadableSize;
18use common_wal::config::kafka::DatanodeKafkaConfig;
19use common_wal::config::kafka::common::KafkaConnectionConfig;
20use common_wal::config::raft_engine::RaftEngineConfig;
21
22use crate::kafka::log_store::KafkaLogStore;
23use crate::raft_engine::log_store::RaftEngineLogStore;
24
25/// Create a write log for the provided path, used for test.
26pub async fn create_tmp_local_file_log_store<P: AsRef<Path>>(path: P) -> RaftEngineLogStore {
27    let path = path.as_ref().display().to_string();
28    let cfg = RaftEngineConfig {
29        file_size: ReadableSize::kb(128),
30        ..Default::default()
31    };
32    RaftEngineLogStore::try_new(path, &cfg).await.unwrap()
33}
34
35/// Create a [KafkaLogStore].
36pub async fn create_kafka_log_store(broker_endpoints: Vec<String>) -> KafkaLogStore {
37    KafkaLogStore::try_new(&DatanodeKafkaConfig {
38        connection: KafkaConnectionConfig {
39            broker_endpoints,
40            ..Default::default()
41        },
42        ..Default::default()
43    })
44    .await
45    .unwrap()
46}