use super::Cache;
#[test]
fn metadata_priority_defaults_on_and_toggles() {
assert!(Cache::with_capacity_bytes(1024).metadata_priority());
let off = Cache::with_capacity_bytes(1024).with_metadata_priority(false);
assert!(!off.metadata_priority());
assert!(off.with_metadata_priority(true).metadata_priority());
}
#[test]
fn a_blob_lookup_under_a_conflicting_key_misses_rather_than_serving_the_other_value() {
use crate::vlog::ValueHandle;
let cache = Cache::with_capacity_bytes(1024 * 1024);
let vhandle = ValueHandle {
blob_file_id: 7,
offset: 4096,
on_disk_size: 5,
};
cache.insert_blob(
0,
&vhandle,
b"real-key",
crate::UserValue::from(&b"value"[..]),
);
assert_eq!(
cache.get_blob(0, &vhandle, b"real-key").as_deref(),
Some(&b"value"[..]),
"the owning key must still hit",
);
assert!(
cache.get_blob(0, &vhandle, b"other-key").is_none(),
"a conflicting key must not be served the value at that offset",
);
}
#[test]
fn a_blob_lookup_with_a_conflicting_size_misses_rather_than_serving_the_value() {
use crate::vlog::ValueHandle;
let cache = Cache::with_capacity_bytes(1024 * 1024);
let stored = ValueHandle {
blob_file_id: 7,
offset: 4096,
on_disk_size: 5,
};
cache.insert_blob(0, &stored, b"key", crate::UserValue::from(&b"value"[..]));
assert_eq!(
cache.get_blob(0, &stored, b"key").as_deref(),
Some(&b"value"[..]),
"the handle it was stored under must still hit",
);
let conflicting = ValueHandle {
on_disk_size: 9,
..stored
};
assert!(
cache.get_blob(0, &conflicting, b"key").is_none(),
"a handle declaring a different size must not be served the cached value",
);
}