-
Notifications
You must be signed in to change notification settings - Fork 5
/
replication-tests.rs
243 lines (220 loc) · 9.05 KB
/
replication-tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#[cfg(test)]
pub mod helpers;
mod tests {
use crate::helpers::*;
use predicates::prelude::*; // Used for writing assertions
#[test]
#[cfg(not(tarpaulin))]
fn should_replicate_user_creation() -> Result<(), Box<dyn std::error::Error>> {
helpers::clean_env();
let replicas_processes = helpers::start_3_replicas();
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from("create-db test test-pwd;"),
)
.success()
.stdout(predicate::str::contains("create-db success")); // Empty is the expected response here
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from("use-db test test-pwd; create-user foo bar;set-permissions foo rw *; set-safe name 0 mateus;"),
)
.success()
.stdout(predicate::str::contains("empty")); // Empty is the expected response here
helpers::wait_seconds(3);
helpers::nundb_exec(
//&helpers::PRIMARY_HTTP_URI.to_string(),
&helpers::SECOUNDAR_HTTP_URI.to_string(),
&String::from("use-db test foo bar;get name"),
)
.success()
.stdout(predicate::str::contains("value mateus"));
helpers::nundb_exec(
&helpers::SECOUNDAR2_HTTP_URI.to_string(),
&String::from("use-db test foo bar;get name"),
)
.success()
.stdout(predicate::str::contains("value mateus"));
helpers::kill_replicas(replicas_processes)?;
Ok(())
}
#[test]
fn should_replicate_as_expected() -> Result<(), Box<dyn std::error::Error>> {
helpers::clean_env();
let replicas_processes = helpers::start_3_replicas();
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from("create-db test test-pwd; use-db test test-pwd;set-safe name 0 mateus;"),
)
.success()
.stdout(predicate::str::contains("empty")); // Empty is the expected response here
helpers::wait_seconds(3); //Wait 1s to the replication
helpers::nundb_exec(
&helpers::SECOUNDAR_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;get name"),
)
.success()
.stdout(predicate::str::contains("value mateus"));
helpers::nundb_exec(
&helpers::SECOUNDAR2_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;get name"),
)
.success()
.stdout(predicate::str::contains("value mateus"));
helpers::kill_replicas(replicas_processes)?;
Ok(())
}
#[test]
fn should_replicate_as_expected_set_safe() -> Result<(), Box<dyn std::error::Error>> {
helpers::clean_env();
let replicas_processes = helpers::start_3_replicas();
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from("create-db test test-pwd; use-db test test-pwd;set-safe name 0 mateus;"),
)
.success()
.stdout(predicate::str::contains("empty;empty"));
helpers::wait_seconds(helpers::time_to_start_replica() * 3); //Wait 3s to the replication
helpers::nundb_exec(
&helpers::SECOUNDAR_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;get-safe name"),
)
.success()
.stdout(predicate::str::contains("value-version 1 mateus"));
helpers::nundb_exec(
&helpers::SECOUNDAR2_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;get-safe name"),
)
.success()
.stdout(predicate::str::contains("value-version 1 mateus"));
//Save from secoundary 2 read from primary and secoundary 1
helpers::nundb_exec(
&helpers::SECOUNDAR2_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;set-safe name 1 maria;"),
)
.success()
.stdout(predicate::str::contains("empty;empty"));
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;get name;get-safe name"),
)
.success()
.stdout(predicate::str::contains("value maria"))
.stdout(predicate::str::contains("value-version 2 maria"));
helpers::nundb_exec(
&helpers::SECOUNDAR_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;get name;get-safe name"),
)
.success()
.stdout(predicate::str::contains("value maria"))
.stdout(predicate::str::contains("value-version 2 maria"));
helpers::kill_replicas(replicas_processes)?;
Ok(())
}
#[test]
#[cfg(not(tarpaulin))]
fn should_use_exter_address_if_external_addr_is_provided(
) -> Result<(), Box<dyn std::error::Error>> {
helpers::clean_env();
let replicas_processes = helpers::start_3_replicas_with_external_addr();
helpers::wait_seconds(3); //Wait 3s to the replication
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from("create-db test test-pwd; use-db test test-pwd;set-safe name 0 mateus;"),
)
.success()
.stdout(predicate::str::contains("empty;empty"));
helpers::wait_seconds(3); //Wait 3s to the replication
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from("cluster-state"),
)
.success()
.stdout(predicate::str::contains("localhost:3016"));
helpers::wait_seconds(3); //Wait 3s to the replication
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from("metrics-state"),
)
.success()
.stdout(predicate::str::contains("pending_ops: 0"));
helpers::kill_replicas(replicas_processes)?;
Ok(())
}
/*
// This tests require latancy beetwhen processes
#[test]
fn should_set_and_imediatly_read_from_secoundary() -> Result<(), Box<dyn std::error::Error>> {
let db_name_seed = helpers::get_db_name_seed();
helpers::clean_env();
let replicas_processes = helpers::start_3_replicas();
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from(format!("create-db {} test-pwd; use-db {} test-pwd;", db_name_seed, db_name_seed)),
)
.success()
.stdout(predicate::str::contains("empty"));
helpers::wait_seconds(3); //Wait 3s to the replication
let db_name_seed_t1 = db_name_seed.clone();
let secound_thread = thread::spawn(move || {
helpers::nundb_exec(
&helpers::SECOUNDAR_HTTP_URI.to_string(),
&String::from(format!("use-db {} test-pwd;set-safe name 2 mateus; get-safe name", db_name_seed_t1)),
)
.success()
.stdout(predicate::str::contains("value-version 3 mateus"));
});
let db_name_seed_t1 = db_name_seed.clone();
let secound2_thread = thread::spawn(move || {
helpers::nundb_exec(
&helpers::SECOUNDAR2_HTTP_URI.to_string(),
&String::from(format!("use-db {} test-pwd;set-safe name 0 maria; get-safe name", db_name_seed_t1.clone())),
)
.success()
.stdout(predicate::str::contains("value-version 1 maria"));
});
secound_thread.join().unwrap();
secound2_thread.join().unwrap();
helpers::nundb_exec(
&helpers::PRIMARY_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;get-safe name"),
)
.success()
.stdout(predicate::str::contains("value-version 3 mateus"));
helpers::kill_replicas(replicas_processes)?;
Ok(())
}
#[test]
fn should_not_replicate_processing_from_the_sending_replica(
) -> Result<(), Box<dyn std::error::Error>> {
helpers::clean_env();
let replicas_processes = helpers::start_3_replicas();
helpers::create_test_db();
let secound_thread = thread::spawn(move || {
helpers::nundb_exec(
&helpers::SECOUNDAR_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;set-safe name 0 mateus; get-safe name"),
)
.success()
.stdout(predicate::str::contains("value-version 1 mateus"));
});
let secound2_thread = thread::spawn(move || {
helpers::nundb_exec(
&helpers::SECOUNDAR2_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;set-safe name 2 maria; get-safe name"),
)
.success()
.stdout(predicate::str::contains("value-version 3 maria"));
});
secound_thread.join().unwrap();
secound2_thread.join().unwrap();
helpers::nundb_exec(
&helpers::SECOUNDAR2_HTTP_URI.to_string(),
&String::from("use-db test test-pwd;get-safe name"),
)
.success()
.stdout(predicate::str::contains("value-version 3 maria"));
helpers::kill_replicas(replicas_processes)?;
Ok(())
}
*/
}