Skip to content

Commit

Permalink
Add test for cache misses
Browse files Browse the repository at this point in the history
  • Loading branch information
rootmos committed Sep 30, 2020
1 parent 4ac3e95 commit 23af8cb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion engine/vault/src/vault/protocol.rs
Expand Up @@ -18,7 +18,7 @@ use crate::{

use serde::{Deserialize, Serialize};

#[derive(Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, Debug)]
pub enum Kind {
Transaction = 1,
Blob = 2,
Expand Down
47 changes: 44 additions & 3 deletions engine/vault/tests/vault.rs
Expand Up @@ -14,7 +14,7 @@ use utils::provider::Provider;

mod fresh;

use vault::{DBView, Key, Result, RecordId, ReadResult, WriteRequest, PreparedRead};
use vault::{DBView, Key, Result, RecordId, ReadResult, WriteRequest, PreparedRead, Kind};

use std::{
iter::empty,
Expand Down Expand Up @@ -98,9 +98,44 @@ fn test_write_cache_hit() -> Result<()> {
}

#[test]
#[ignore = "not yet implemented"]
fn test_write_cache_miss() -> Result<()> {
unimplemented!()
let k: Key<Provider> = Key::random()?;
let v0 = DBView::load(k.clone(), empty::<ReadResult>())?;

let mut writes = vec![];

let id = RecordId::random::<Provider>()?;
let mut w = v0.writer(id);
writes.push(w.truncate()?);
let data = fresh::data();
let hint = fresh::record_hint();
let blob = match w.write(&data, hint)?.as_slice() {
[w0, w1] => {
assert_eq!(w0.kind(), Kind::Transaction);
writes.push(w0.clone());

assert_eq!(w1.kind(), Kind::Blob);
w1.data().to_vec()
},
ws => panic!("{} unexpected writes", ws.len()),
};

let v1 = DBView::load(k, writes.iter().map(write_to_read))?;

assert_eq!(v1.all().len(), 1);
assert_eq!(v1.absolute_balance(), (2, 2));
assert_eq!(v1.chain_ctrs(), vec![(id, 1u64)].into_iter().collect());
assert_eq!(v1.gc().len(), 0);

let r = v1.reader();
let res = match r.prepare_read(&id)? {
PreparedRead::CacheMiss(req) => req.result(blob),
x => panic!("unexpected value: {:?}", x),
};

assert_eq!(r.read(res)?, data);

Ok(())
}

#[test]
Expand All @@ -114,3 +149,9 @@ fn test_rekove() -> Result<()> {
fn test_rekove_then_write() -> Result<()> {
unimplemented!()
}

#[test]
#[ignore = "not yet implemented"]
fn test_ensure_authenticty_of_blob() -> Result<()> {
unimplemented!()
}

0 comments on commit 23af8cb

Please sign in to comment.