Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jopemachine committed Jan 8, 2024
1 parent 7ae8a16 commit 661654f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
9 changes: 2 additions & 7 deletions harness/src/raft_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub type Raft = Raft_<LogEntry, HashStore>;

pub static RAFTS: Lazy<Mutex<HashMap<u64, Raft>>> = Lazy::new(|| Mutex::new(HashMap::new()));

fn build_logger(node_id: u64) -> slog::Logger {
fn build_logger(_node_id: u64) -> slog::Logger {
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::CompactFormat::new(decorator).build();
let drain = std::sync::Mutex::new(drain).fuse();
Expand All @@ -30,8 +30,7 @@ fn build_logger(node_id: u64) -> slog::Logger {
}
let drain = builder.build();

let pid = std::process::id();
slog::Logger::root(drain, o!("Node ID" => node_id, "PID" => pid))
slog::Logger::root(drain, o!())
}

fn run_raft(node_id: &u64, peers: Peers) -> Result<JoinHandle<Result<()>>> {
Expand All @@ -57,10 +56,6 @@ fn run_raft(node_id: &u64, peers: Peers) -> Result<JoinHandle<Result<()>>> {
Ok(raft_handle)
}

pub fn setup_test() {
set_custom_deserializer(CustomDeserializer::<LogEntry, HashStore>::new());
}

pub async fn run_rafts(peers: Peers) -> Result<()> {
let mut raft_handles = vec![];

Expand Down
8 changes: 7 additions & 1 deletion harness/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use raftify::Peers;
use raftify::{Peers, CustomDeserializer};
use raftify::raft::derializer::set_custom_deserializer;
use serde::Deserialize;
use std::net::SocketAddr;
use std::path::Path;
Expand All @@ -7,6 +8,7 @@ use tokio::time::sleep;
use toml;

use crate::raft_server::Raft;
use crate::state_machine::{LogEntry, HashStore};

#[derive(Deserialize, Debug)]
pub struct TomlRaftPeer {
Expand Down Expand Up @@ -70,3 +72,7 @@ pub async fn wait_for_until_cluster_size_decrease(raft: Raft, target: usize) {
// Wait for the conf_change reflected to the cluster
sleep(Duration::from_secs_f32(1.0)).await;
}

pub fn setup_test() {
set_custom_deserializer(CustomDeserializer::<LogEntry, HashStore>::new());
}
4 changes: 2 additions & 2 deletions harness/tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use tokio::time::sleep;

use harness::{
constant::{ONE_NODE_EXAMPLE, RAFT_ADDRS, THREE_NODE_EXAMPLE},
raft_server::{handle_bootstrap, run_rafts, setup_test, spawn_extra_node, RAFTS},
utils::{load_peers, wait_for_until_cluster_size_increase},
raft_server::{handle_bootstrap, run_rafts, spawn_extra_node, RAFTS},
utils::{load_peers, wait_for_until_cluster_size_increase, setup_test},
};

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions harness/tests/data_replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use tokio::time::sleep;

use harness::{
constant::{RAFT_ADDRS, THREE_NODE_EXAMPLE},
raft_server::{handle_bootstrap, run_rafts, setup_test, spawn_extra_node, RAFTS},
raft_server::{handle_bootstrap, run_rafts, spawn_extra_node, RAFTS},
state_machine::LogEntry,
utils::{load_peers, wait_for_until_cluster_size_increase},
utils::{load_peers, wait_for_until_cluster_size_increase, setup_test},
};

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions harness/tests/leader_election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use tokio::time::sleep;

use harness::{
constant::{FIVE_NODE_EXAMPLE, THREE_NODE_EXAMPLE},
raft_server::{handle_bootstrap, run_rafts, setup_test, RAFTS},
raft_server::{handle_bootstrap, run_rafts, RAFTS},
utils::{
load_peers, wait_for_until_cluster_size_decrease, wait_for_until_cluster_size_increase,
load_peers, wait_for_until_cluster_size_decrease, wait_for_until_cluster_size_increase, setup_test,
},
};

Expand Down
2 changes: 0 additions & 2 deletions raftify/src/storage/heed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,6 @@ impl HeedStorageCore {
})
.collect();

println!("Entries!!!: {:?}", entries);

Ok(entries)
}

Expand Down

0 comments on commit 661654f

Please sign in to comment.