From 388d4be39fb980d559078e722aabecbdb556cffa Mon Sep 17 00:00:00 2001 From: Chen Chen Date: Thu, 1 Aug 2024 13:56:54 -0500 Subject: [PATCH] stores: add rocksdb tests --- .github/workflows/test.yml | 3 +-- Cargo.toml | 3 +++ src/bench.rs | 15 +++++++++++++++ src/server.rs | 34 ++++++++++++++++++++++++++++++++++ src/stores.rs | 11 +++++++++++ src/stores/rocksdb.rs | 2 +- 6 files changed, 65 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3c394c1..ff16f4a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,8 +24,6 @@ jobs: - uses: baptiste0928/cargo-install@v3 with: crate: cargo-hack - - name: check - run: cargo hack check --feature-powerset --no-dev-deps - name: build run: | cargo build --verbose --release @@ -33,4 +31,5 @@ jobs: - name: test run: | cargo test --release + cargo hack test --each-feature --release cargo test --release --all-features diff --git a/Cargo.toml b/Cargo.toml index a6fdb40..e198ff7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/bench.rs b/src/bench.rs index caf4ed8..ec8206e 100644 --- a/src/bench.rs +++ b/src/bench.rs @@ -1393,6 +1393,21 @@ mod tests { )); example(OPT); } + + #[test] + #[cfg(feature = "rocksdb")] + 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 diff --git a/src/server.rs b/src/server.rs index 6946d6d..65b35ce 100644 --- a/src/server.rs +++ b/src/server.rs @@ -824,6 +824,29 @@ 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] + #[cfg(feature = "rocksdb")] + 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; @@ -977,4 +1000,15 @@ mod tests { let map = BenchKVMap::Regular(Box::new(btreemap::RwLockBTreeMap::new())); batch(map); } + + #[test] + #[cfg(feature = "rocksdb")] + 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); + } } diff --git a/src/stores.rs b/src/stores.rs index b67f739..a062a61 100644 --- a/src/stores.rs +++ b/src/stores.rs @@ -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); + } } diff --git a/src/stores/rocksdb.rs b/src/stores/rocksdb.rs index 2d237f5..c658686 100644 --- a/src/stores/rocksdb.rs +++ b/src/stores/rocksdb.rs @@ -17,7 +17,7 @@ use serde::Deserialize; #[derive(Deserialize)] pub struct RocksDBOpt { - path: String, + pub path: String, } #[derive(Clone)]