Skip to content

Commit

Permalink
fix(initializer): WAL 디렉토리 추가 & 테스트 케이스 알맞게 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
wHoIsDReAmer committed Nov 22, 2024
1 parent 4aef420 commit 6674a34
Showing 1 changed file with 46 additions and 10 deletions.
56 changes: 46 additions & 10 deletions src/executor/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ impl Executor {
// 3. 데이터 디렉터리 생성 (없다면)
self.create_data_directory_if_not_exists().await?;

// 4. 데몬 설정파일 생성 (없다면)
// 4. WAL 디렉터리 생성 (없다면)
self.create_wal_directory_if_not_exists().await?;

// 5. 데몬 설정파일 생성 (없다면)
self.create_daemon_config_if_not_exists().await?;

// 5. 데몬 실행
// 6. 데몬 실행
self.start_daemon().await?;

Ok(())
Expand Down Expand Up @@ -96,6 +99,18 @@ impl Executor {
Ok(())
}

async fn create_wal_directory_if_not_exists(&self) -> Result<(), RRDBError> {
let wal_path = self.config.wal_directory.clone();

if let Err(error) = self.file_system.create_dir(&wal_path).await {
if error.kind() != std::io::ErrorKind::AlreadyExists {
return Err(ExecuteError::wrap(error.to_string()));
}
}

Ok(())
}

#[cfg(target_os = "linux")]
async fn create_daemon_config_if_not_exists(&self) -> Result<(), RRDBError> {
use crate::constants::SYSTEMD_DAEMON_SCRIPT;
Expand Down Expand Up @@ -188,16 +203,20 @@ mod tests {
async fn test_init_config() {
use mockall::predicate::eq;

use crate::executor::mocking::{
use crate::{constants::{DEFAULT_DATA_DIRNAME, DEFAULT_WAL_DIRNAME}, executor::mocking::{
CommandRunner, FileSystem, MockCommandRunner, MockFileSystem,
};
}};

use super::*;
use std::sync::Arc;

const CONFIG: &[u8] = br##"port = 22208
host = "0.0.0.0"
data_directory = "/var/lib/rrdb/data"
wal_enabled = true
wal_directory = "/var/lib/rrdb/wal"
wal_segment_size = 16777216
wal_extension = "log"
"##;

use crate::constants::SYSTEMD_DAEMON_SCRIPT;
Expand Down Expand Up @@ -240,10 +259,16 @@ data_directory = "/var/lib/rrdb/data"
// 3. 데이터 디렉터리 생성
mock.expect_create_dir()
.times(1)
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/data"))
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/" + DEFAULT_DATA_DIRNAME))
.returning(|_| Ok(()));

// 4. WAL 디렉터리 생성
mock.expect_create_dir()
.times(1)
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/" + DEFAULT_WAL_DIRNAME))
.returning(|_| Ok(()));

// 4. 데몬 설정파일 생성
// 5. 데몬 설정파일 생성
mock.expect_write_file()
.times(1)
.with(
Expand Down Expand Up @@ -294,10 +319,15 @@ data_directory = "/var/lib/rrdb/data"

// 3. 데이터 디렉터리 생성
mock.expect_create_dir()
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/data"))
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/" + DEFAULT_DATA_DIRNAME))
.returning(|_| Ok(()));

// 4. WAL 디렉터리 생성
mock.expect_create_dir()
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/" + DEFAULT_WAL_DIRNAME))
.returning(|_| Ok(()));

// 4. 데몬 설정파일 생성
// 5. 데몬 설정파일 생성
mock.expect_write_file()
.with(
eq("/etc/systemd/system/rrdb.service"),
Expand Down Expand Up @@ -348,7 +378,13 @@ data_directory = "/var/lib/rrdb/data"
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/data"))
.returning(|_| Ok(()));

// 4. 데몬 설정파일 생성
// 4. WAL 디렉터리 생성
mock.expect_create_dir()
.times(1)
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/" + DEFAULT_WAL_DIRNAME))
.returning(|_| Ok(()));

// 5. 데몬 설정파일 생성
mock.expect_write_file()
.times(1)
.with(
Expand Down Expand Up @@ -397,7 +433,7 @@ data_directory = "/var/lib/rrdb/data"
// 3. 데이터 디렉터리 생성
mock.expect_create_dir()
.times(1)
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/data"))
.with(eq(DEFAULT_CONFIG_BASEPATH.to_owned() + "/" + DEFAULT_DATA_DIRNAME))
.returning(|_| Err(Error::from_raw_os_error(1)));

Arc::new(mock)
Expand Down

0 comments on commit 6674a34

Please sign in to comment.