summaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-06-10 22:50:38 -0400
committerDeterminant <[email protected]>2020-06-10 22:50:38 -0400
commit350f2638cb3e15df231381b8fd286595058b7a54 (patch)
tree0109ab503043e7e325bc18cd03288b19f7ba28ef /tests/common
parent557392fe0672bc6b83ef2e0fec2c8ff7a6f22a54 (diff)
add closure to WALStoreEmul
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/mod.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index ce27e16..a8dab51 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -89,18 +89,29 @@ impl WALStoreEmulState {
}
/// Emulate the persistent storage state.
-pub struct WALStoreEmul<'a, G: FailGen> {
+pub struct WALStoreEmul<'a, G, F>
+where
+ G: FailGen,
+ F: Fn(WALBytes, WALPos) {
state: &'a mut WALStoreEmulState,
- fgen: Rc<G>
+ fgen: Rc<G>,
+ recover: F
}
-impl<'a, G: FailGen> WALStoreEmul<'a, G> {
- pub fn new(state: &'a mut WALStoreEmulState, fail_gen: G) -> Self {
- WALStoreEmul { state, fgen: Rc::new(fail_gen) }
+impl<'a, G: FailGen, F: Fn(WALBytes, WALPos)> WALStoreEmul<'a, G, F> {
+ pub fn new(state: &'a mut WALStoreEmulState, fail_gen: G,
+ recover: F) -> Self {
+ WALStoreEmul {
+ state,
+ fgen: Rc::new(fail_gen),
+ recover
+ }
}
}
-impl<'a, G: 'static + FailGen> WALStore for WALStoreEmul<'a, G> {
+impl<'a, G, F> WALStore for WALStoreEmul<'a, G, F>
+where
+ G: 'static + FailGen, F: Fn(WALBytes, WALPos) {
type FileNameIter = std::vec::IntoIter<String>;
fn open_file(&mut self, filename: &str, touch: bool) -> Result<Box<dyn WALFile>, ()> {
@@ -122,7 +133,7 @@ impl<'a, G: 'static + FailGen> WALStore for WALStoreEmul<'a, G> {
}
fn remove_file(&mut self, filename: &str) -> Result<(), ()> {
- println!("remove {}", filename);
+ println!("remove_file(filename={})", filename);
if self.fgen.next_fail() { return Err(()) }
self.state.files.remove(filename).ok_or(()).and_then(|_| Ok(()))
}
@@ -141,6 +152,7 @@ impl<'a, G: 'static + FailGen> WALStore for WALStoreEmul<'a, G> {
println!("apply_payload(payload=0x{}, wal_off={})",
hex::encode(&payload),
wal_off);
+ (self.recover)(payload, wal_off);
Ok(())
}
}