Adding test to validate correct behavior of prefix_iterator...

master
Jordan Terrell 6 years ago
parent f4bd7c39f5
commit 4c0d662435
  1. 44
      tests/test_iterator.rs

@ -207,6 +207,50 @@ pub fn test_prefix_iterator() {
} }
} }
#[test]
pub fn test_prefix_iterator_uses_full_prefix() {
// Test scenario derived from GitHub issue #221
// Explanation: `db.prefix_iterator` sets the underlying
// options to seek to the first key that matches the *entire*
// prefix. From there, the iterator will continue to read pairs
// as long as the prefix extracted from `key` matches the
// prefix extracted from `prefix`.
let path = DBPath::new("_rust_rocksdb_prefixiteratorusesfullprefixtest");
{
let data = [
([0,0,0,0], b"111"),
([0,0,0,1], b"222"),
([0,1,0,1], b"333"),
([0,1,1,1], b"444"),
([0,1,2,1], b"555"),
([0,2,0,0], b"666"),
([2,0,0,0], b"777"),
([2,2,2,2], b"888")
];
let prefix_extractor = rocksdb::SliceTransform::create_fixed_prefix(1);
let mut opts = Options::default();
opts.create_if_missing(true);
opts.set_prefix_extractor(prefix_extractor);
let db = DB::open(&opts, &path).unwrap();
for (key, value) in &data {
assert!(db.put(key, *value).is_ok());
}
let prefix = [0,1,1];
let results: Vec<_> = db.prefix_iterator(&prefix)
.map(|(_,v)| std::str::from_utf8(&v).unwrap().to_string())
.collect();
assert_eq!(results, vec!("444", "555", "666"));
}
}
#[test] #[test]
pub fn test_full_iterator() { pub fn test_full_iterator() {
let path = "_rust_rocksdb_fulliteratortest"; let path = "_rust_rocksdb_fulliteratortest";

Loading…
Cancel
Save