diff --git a/crates/lox-distributor/Cargo.toml b/crates/lox-distributor/Cargo.toml index af9c2f356cd069d2e81e7254a3cb20d40950bc0e..3ec4db2c0bdb056b4256a52b280f3c3772a48299 100644 --- a/crates/lox-distributor/Cargo.toml +++ b/crates/lox-distributor/Cargo.toml @@ -45,3 +45,6 @@ sha1 = "0.10" [dependencies.chrono] version = "0.4.38" features = ["serde"] + +[features] +simulation = [] diff --git a/crates/lox-distributor/src/db_handler.rs b/crates/lox-distributor/src/db_handler.rs index 72a26dca2a18867304788bede8f2bcf4bc267502..b3137660b29e5dbc47d69aef90f30363a079411e 100644 --- a/crates/lox-distributor/src/db_handler.rs +++ b/crates/lox-distributor/src/db_handler.rs @@ -29,28 +29,31 @@ impl DB { // Writes the Lox context to the lox database with "context_%Y-%m-%d_%H:%M:%S" as the // database key pub fn write_context(&mut self, context: lox_context::LoxServerContext) { - let date = Local::now().format("context_%Y-%m-%d_%H:%M:%S").to_string(); - /* Uncomment to generate test file for this function after making changes to lox library - let file = OpenOptions::new() - .create(true) - .write(true) - .truncate(true) - .open("db_test_file.json").unwrap(); - serde_json::to_writer(&file, &context).unwrap(); - */ - let json_result = serde_json::to_vec(&context).unwrap(); - println!("Writing context to the db with key: {:?}", date); - let _new_ivec = self.db.insert( - IVec::from(date.as_bytes().to_vec()), - IVec::from(json_result.clone()), - ); - assert_eq!( - self.db - .get(IVec::from(date.as_bytes().to_vec())) - .unwrap() - .unwrap(), - IVec::from(json_result) - ); + #[cfg(not(feature = "simulation"))] + { + let date = Local::now().format("context_%Y-%m-%d_%H:%M:%S").to_string(); + /* Uncomment to generate test file for this function after making changes to lox library + let file = OpenOptions::new() + .create(true) + .write(true) + .truncate(true) + .open("db_test_file.json").unwrap(); + serde_json::to_writer(&file, &context).unwrap(); + */ + let json_result = serde_json::to_vec(&context).unwrap(); + println!("Writing context to the db with key: {:?}", date); + let _new_ivec = self.db.insert( + IVec::from(date.as_bytes().to_vec()), + IVec::from(json_result.clone()), + ); + assert_eq!( + self.db + .get(IVec::from(date.as_bytes().to_vec())) + .unwrap() + .unwrap(), + IVec::from(json_result) + ); + } } // If roll_back_date is empty, opens the most recent entry in the lox database or if none exists, creates a