From 415578aa48a12cac01d763b7c08384dbcd46911b Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 10 Jun 2020 14:40:36 -0400 Subject: WIP: random failure test (with emulated storage) --- examples/demo1.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'examples/demo1.rs') diff --git a/examples/demo1.rs b/examples/demo1.rs index e0c7d58..e395adf 100644 --- a/examples/demo1.rs +++ b/examples/demo1.rs @@ -49,11 +49,12 @@ impl WALFile for WALFileTest { self.filename, offset, offset + data.len() as u64, hex::encode(&data)); pwrite(self.fd, &*data, offset as off_t).unwrap(); } - fn read(&self, offset: WALPos, length: usize) -> WALBytes { + fn read(&self, offset: WALPos, length: usize) -> Option { let mut buff = Vec::new(); buff.resize(length, 0); - pread(self.fd, &mut buff[..], offset as off_t).unwrap(); - buff.into_boxed_slice() + if pread(self.fd, &mut buff[..], offset as off_t).unwrap() == length { + Some(buff.into_boxed_slice()) + } else { None } } } @@ -89,13 +90,13 @@ impl Drop for WALStoreTest { impl WALStore for WALStoreTest { type FileNameIter = std::vec::IntoIter; - fn open_file(&self, filename: &str, touch: bool) -> Option> { + fn open_file(&mut self, filename: &str, touch: bool) -> Option> { println!("open_file(filename={}, touch={})", filename, touch); let filename = filename.to_string(); Some(Box::new(WALFileTest::new(self.rootfd, &filename))) } - fn remove_file(&self, filename: &str) -> Result<(), ()> { + fn remove_file(&mut self, filename: &str) -> Result<(), ()> { println!("remove_file(filename={})", filename); unlinkat(Some(self.rootfd), filename, UnlinkatFlags::NoRemoveDir).or_else(|_| Err(())) } @@ -109,7 +110,7 @@ impl WALStore for WALStoreTest { logfiles.into_iter() } - fn apply_payload(&self, payload: WALBytes) { + fn apply_payload(&mut self, payload: WALBytes) { println!("apply_payload(payload={})", std::str::from_utf8(&payload).unwrap()) } } -- cgit v1.2.3-70-g09d2