Skip to content

Commit 388139b

Browse files
committed
module separation
1 parent 70c3522 commit 388139b

22 files changed

Lines changed: 53 additions & 66 deletions

duva/tests/client_ops/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mod test_config_get_dir;
2+
mod test_del;
3+
mod test_exists;
4+
mod test_idempotent_client;
5+
mod test_keys;
6+
mod test_replication_info;
7+
mod test_set_get;
8+
mod test_snapshot_persists_and_recovers_state;

duva/tests/test_config_get_dir.rs renamed to duva/tests/client_ops/test_config_get_dir.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/// if the value of dir is /tmp, then the expected response to CONFIG GET dir is:
22
/// *2\r\n$3\r\ndir\r\n$4\r\n/tmp\r\n
3-
mod common;
43
use std::time::Duration;
54

6-
use crate::common::array;
7-
use common::{ServerEnv, spawn_server_process};
85
use duva::clients::ClientStreamHandler;
96
use tokio::time::sleep;
107

8+
use crate::common::{ServerEnv, array, spawn_server_process};
9+
1110
#[tokio::test]
1211
async fn test_config_get_dir() {
1312
// GIVEN
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
/// Firstly, we set a key with a value and an expiry of 300ms
33
/// Then we get the key and check if the value is returned
44
/// After 300ms, we get the key again and check if the value is not returned (-1)
5-
mod common;
6-
use common::{ServerEnv, array, spawn_server_process};
7-
85
use duva::{clients::ClientStreamHandler, domains::query_parsers::query_io::QueryIO};
96

7+
use crate::common::{ServerEnv, array, spawn_server_process};
108
#[tokio::test]
119
async fn test_del() {
1210
// GIVEN
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
/// Firstly, we set a key with a value and an expiry of 300ms
33
/// Then we get the key and check if the value is returned
44
/// After 300ms, we get the key again and check if the value is not returned (-1)
5-
mod common;
6-
use common::{ServerEnv, array, spawn_server_process};
7-
85
use duva::{clients::ClientStreamHandler, domains::query_parsers::query_io::QueryIO};
96

7+
use crate::common::{ServerEnv, array, spawn_server_process};
108
#[tokio::test]
119
async fn test_exists() {
1210
// GIVEN

duva/tests/test_idempotent_client.rs renamed to duva/tests/client_ops/test_idempotent_client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
mod common;
2-
use common::{ServerEnv, array, session_request, spawn_server_process};
31
use duva::{clients::ClientStreamHandler, domains::query_parsers::query_io::QueryIO};
42

3+
use crate::common::{ServerEnv, array, session_request, spawn_server_process};
4+
55
#[tokio::test]
66
async fn test_send_session_request() {
77
// GIVEN
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
mod common;
2-
use common::{ServerEnv, array, spawn_server_process};
1+
use crate::common::{ServerEnv, array, spawn_server_process};
32
use duva::{clients::ClientStreamHandler, domains::query_parsers::query_io::QueryIO};
43

54
#[tokio::test]

duva/tests/test_replication_info.rs renamed to duva/tests/client_ops/test_replication_info.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
44
/// if the value of dir is /tmp, then the expected response to CONFIG GET dir is:
55
/// *2\r\n$3\r\ndir\r\n$4\r\n/tmp\r\n
6-
mod common;
7-
8-
use common::{ServerEnv, array, spawn_server_process};
6+
use crate::common::{ServerEnv, array, spawn_server_process};
97

108
use duva::clients::ClientStreamHandler;
119

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
/// Firstly, we set a key with a value and an expiry of 300ms
33
/// Then we get the key and check if the value is returned
44
/// After 300ms, we get the key again and check if the value is not returned (-1)
5-
mod common;
6-
use common::{ServerEnv, array, spawn_server_process};
7-
5+
use crate::common::{ServerEnv, array, spawn_server_process};
86
use duva::{clients::ClientStreamHandler, domains::query_parsers::query_io::QueryIO};
97

108
#[tokio::test]

duva/tests/test_save_read_snapshot.rs renamed to duva/tests/client_ops/test_snapshot_persists_and_recovers_state.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
/// Cache config should be injected to the handler!
2-
/// This is to enable client to configure things dynamically.
3-
4-
/// if the value of dir is /tmp, then the expected response to CONFIG GET dir is:
5-
/// *2\r\n$3\r\ndir\r\n$4\r\n/tmp\r\n
6-
mod common;
7-
use crate::common::array;
8-
use common::ServerEnv;
9-
use common::spawn_server_process;
1+
use crate::common::{ServerEnv, array, spawn_server_process};
2+
103
use duva::clients::ClientStreamHandler;
114
use duva::domains::query_parsers::query_io::QueryIO;
125
use std::time::SystemTime;
136
use std::time::UNIX_EPOCH;
147

158
// TODO response cannot be deterministic!
169
#[tokio::test]
17-
async fn test_save_read_snapshot() {
10+
async fn test_snapshot_persists_and_recovers_state() {
1811
// GIVEN
1912
let env = ServerEnv::default().with_file_name(create_unique_file_name("test_save_dump"));
2013
let leader_process = spawn_server_process(&env);
@@ -38,39 +31,31 @@ async fn test_save_read_snapshot() {
3831
// check replication info
3932
let res = h.send_and_get(&array(vec!["INFO", "replication"])).await;
4033
let info: Vec<&str> = res.split("\r\n").collect();
41-
let prev_leader_repl_id = info[3].split(":").collect::<Vec<&str>>()[1];
42-
let prev_leader_repl_offset = info[4].split(":").collect::<Vec<&str>>()[1];
4334

44-
// THEN
35+
// WHEN
4536
assert_eq!(h.send_and_get(&array(vec!["SAVE"])).await, QueryIO::Null.serialize());
4637

4738
// wait for the file to be created
4839
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
49-
50-
// THEN
5140
// kill leader process
5241
drop(leader_process);
5342

5443
// run server with the same file name
55-
let leader_process = spawn_server_process(&env);
44+
let new_process = spawn_server_process(&env);
5645

5746
// wait for the server to start
5847
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
5948

60-
let mut h = ClientStreamHandler::new(leader_process.bind_addr()).await;
49+
let mut client = ClientStreamHandler::new(new_process.bind_addr()).await;
6150

62-
// keys
63-
assert_eq!(h.send_and_get(&array(vec!["KEYS", "*"])).await, array(vec!["foo2", "foo"]));
51+
assert_eq!(client.send_and_get(&array(vec!["KEYS", "*"])).await, array(vec!["foo2", "foo"]));
6452

6553
// replication info
66-
let res = h.send_and_get(&array(vec!["INFO", "replication"])).await;
67-
let info: Vec<&str> = res.split("\r\n").collect();
68-
let leader_repl_id = info[3].split(":").collect::<Vec<&str>>()[1];
69-
let leader_repl_offset = info[4].split(":").collect::<Vec<&str>>()[1];
54+
let res = client.send_and_get(&array(vec!["INFO", "replication"])).await;
55+
let info2: Vec<&str> = res.split("\r\n").collect();
7056

7157
// THEN
72-
assert_eq!(leader_repl_id, prev_leader_repl_id);
73-
assert_eq!(leader_repl_offset, prev_leader_repl_offset);
58+
assert_eq!(info, info2);
7459
}
7560

7661
fn create_unique_file_name(function_name: &str) -> String {

duva/tests/cluster_ops/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mod test_cluster_forget_makes_all_nodes_forget_target_node;
2+
mod test_cluster_forget_when_wrong_id_given;
3+
mod test_cluster_known_nodes_increase_when_new_replica_is_added;
4+
mod test_disseminate_peers;
5+
mod test_heartbeat;
6+
mod test_removes_node_when_heartbeat_is_not_received_for_certain_time;

0 commit comments

Comments
 (0)