Skip to content

Commit

Permalink
stores: add rocksdb tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdroychan committed Aug 1, 2024
1 parent 25cf9b2 commit bdefd9a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ serde = { version = "1.0.204", features = ["derive"] }
toml = "0.8.19"
zipf = "7.0.1"

[dev-dependencies]
tempfile = "3.10.1"

[features]
chashmap = ["dep:chashmap"]
contrie = ["dep:contrie"]
Expand Down
14 changes: 14 additions & 0 deletions src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,20 @@ mod tests {
));
example(OPT);
}

#[test]
fn example_rocksdb() {
let tmp_dir = tempfile::tempdir().unwrap();
let opt = format!(
r#"
[map]
name = "rocksdb"
path = "{}"
"#,
tmp_dir.path().to_str().unwrap().to_string()
);
example(&opt);
}
}

// }}} tests
32 changes: 32 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,28 @@ mod tests {
simple(map);
}

#[test]
fn simple_mutex_btreemap() {
let map = BenchKVMap::Regular(Box::new(btreemap::MutexBTreeMap::new()));
simple(map);
}

#[test]
fn simple_rwlock_btreemap() {
let map = BenchKVMap::Regular(Box::new(btreemap::RwLockBTreeMap::new()));
simple(map);
}

#[test]
fn simple_rocksdb() {
let tmp_dir = tempfile::tempdir().unwrap();
let opt = rocksdb::RocksDBOpt {
path: tmp_dir.path().to_str().unwrap().to_string(),
};
let map = BenchKVMap::Regular(Box::new(rocksdb::RocksDB::new(&opt)));
simple(map);
}

fn batch(map: BenchKVMap) {
const NR_CLIENTS: usize = 8;
const NR_BATCHES: usize = 1000;
Expand Down Expand Up @@ -977,4 +999,14 @@ mod tests {
let map = BenchKVMap::Regular(Box::new(btreemap::RwLockBTreeMap::new()));
batch(map);
}

#[test]
fn batch_rocksdb() {
let tmp_dir = tempfile::tempdir().unwrap();
let opt = rocksdb::RocksDBOpt {
path: tmp_dir.path().to_str().unwrap().to_string(),
};
let map = BenchKVMap::Regular(Box::new(rocksdb::RocksDB::new(&opt)));
batch(map);
}
}
11 changes: 11 additions & 0 deletions src/stores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,15 @@ mod tests {
let mut map = scc::SccHashMap::new();
map_test(&mut map);
}

#[test]
#[cfg(feature = "rocksdb")]
fn rocksdb() {
let tmp_dir = tempfile::tempdir().unwrap();
let opt = rocksdb::RocksDBOpt {
path: tmp_dir.path().to_str().unwrap().to_string(),
};
let mut map = rocksdb::RocksDB::new(&opt);
map_test(&mut map);
}
}
2 changes: 1 addition & 1 deletion src/stores/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde::Deserialize;

#[derive(Deserialize)]
pub struct RocksDBOpt {
path: String,
pub path: String,
}

#[derive(Clone)]
Expand Down

0 comments on commit bdefd9a

Please sign in to comment.