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 388d4be
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ 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
cargo build --verbose --release --all-features
- name: test
run: |
cargo test --release
cargo hack test --each-feature --release
cargo test --release --all-features
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
15 changes: 15 additions & 0 deletions src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 34 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
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 388d4be

Please sign in to comment.