hubcio commented on code in PR #2452: URL: https://github.com/apache/iggy/pull/2452#discussion_r2727825702
########## core/integration/tests/server/scenarios/log_rotation_scenario.rs: ########## @@ -0,0 +1,332 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +use crate::server::scenarios::{PARTITIONS_COUNT, STREAM_NAME, TOPIC_NAME}; +use iggy::prelude::*; +use iggy_common::{ + CompressionAlgorithm, Identifier, IggyByteSize, IggyDuration, IggyExpiry, MaxTopicSize, +}; +use integration::test_server::{ClientFactory, login_root}; +use once_cell::sync::Lazy; +use std::path::Path; +use std::time::Duration; +use tokio::fs; +use tokio::sync::Mutex; +use tokio::time::{sleep, timeout}; + +const RETENTION_SECS: u64 = 30; +const OPERATION_TIMEOUT_SECS: u64 = 10; +const OPERATION_LOOP_COUNT: usize = 300; +const FROM_BYTES_TO_KB: u64 = 1000; +const IGGY_LOG_BASE_NAME: &str = "iggy-server.log"; + +static PRINT_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(())); + +#[derive(Debug)] +pub struct LogRotationTestConfig { + pub name: String, + pub max_single_log_size: IggyByteSize, + pub max_total_log_size: IggyByteSize, + pub rotation_check_interval: IggyDuration, + pub retention: IggyDuration, +} + +pub async fn run( + client_factory: &dyn ClientFactory, + log_dir: &str, + present_log_config: LogRotationTestConfig, +) { + let done_status = false; + let present_log_test_title = present_log_config.name.clone(); + let log_path = Path::new(log_dir); + assert!( + log_path.exists() && log_path.is_dir(), + "failed::no_such_directory => {log_dir}", + ); + + let client = init_valid_client(client_factory).await; + assert!( + client.is_ok(), + "failed::client_initialize => {:?}", + client.as_ref().err(), + ); + + let generator_result = generate_enough_logs(client.as_ref().unwrap()).await; + assert!( + generator_result.is_ok(), + "failed::generate_logs => {:?}", + generator_result.as_ref().err(), + ); + + nocapture_observer(log_path, &present_log_test_title, done_status).await; + sleep(present_log_config.rotation_check_interval.get_duration()).await; + + let rotation_result = validate_log_rotation_rules(log_path, present_log_config).await; + assert!( + rotation_result.is_ok(), + "failed::rotation_check => {:?}", + rotation_result.as_ref().err(), + ); + + nocapture_observer(log_path, &present_log_test_title, !done_status).await; +} + +pub fn get_configurations() -> Vec<LogRotationTestConfig> { + vec![ + LogRotationTestConfig { + name: "log_regular_rotation".to_string(), + max_single_log_size: IggyByteSize::new(100_000), + max_total_log_size: IggyByteSize::new(400_000), + rotation_check_interval: IggyDuration::ONE_SECOND, + retention: IggyDuration::new_from_secs(RETENTION_SECS), + }, + LogRotationTestConfig { + name: "log_unlimited_size".to_string(), + max_single_log_size: IggyByteSize::new(0), + max_total_log_size: IggyByteSize::new(400_000), + rotation_check_interval: IggyDuration::ONE_SECOND, + retention: IggyDuration::new_from_secs(RETENTION_SECS), + }, + LogRotationTestConfig { + name: "log_unlimited_archives".to_string(), + max_single_log_size: IggyByteSize::new(100_000), + max_total_log_size: IggyByteSize::new(0), + rotation_check_interval: IggyDuration::ONE_SECOND, + retention: IggyDuration::new_from_secs(RETENTION_SECS), + }, + LogRotationTestConfig { + name: "log_special_scenario".to_string(), + max_single_log_size: IggyByteSize::new(0), + max_total_log_size: IggyByteSize::new(0), + rotation_check_interval: IggyDuration::ONE_SECOND, + retention: IggyDuration::new_from_secs(RETENTION_SECS), + }, + ] +} Review Comment: you can use test_matrix macro for this. see other tests in server on how to use it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
