Commit 3c918a7f authored by Qinxuan Chen's avatar Qinxuan Chen Committed by Connor

Update some dependencies (#392)

- Update `rand` to v0.7
- Move `crc` to `dev-dependencies`
- Remove `byteorder`
- Replace `tempdir` with `tempfile`
Signed-off-by: 's avatarkoushiro <koushiro.cqx@gmail.com>
parent 970a27c2
...@@ -23,12 +23,11 @@ valgrind = [] ...@@ -23,12 +23,11 @@ valgrind = []
[dependencies] [dependencies]
libc = "0.2.11" libc = "0.2.11"
crc = "1.2"
[dependencies.librocksdb_sys] [dependencies.librocksdb_sys]
path = "librocksdb_sys" path = "librocksdb_sys"
[dev-dependencies] [dev-dependencies]
byteorder = "1.0.0" rand = "0.7"
rand = "0.3" crc = "1.8"
tempdir = "0.3" tempfile = "3.1"
...@@ -12,12 +12,10 @@ ...@@ -12,12 +12,10 @@
// limitations under the License. // limitations under the License.
use super::rocksdb::{ColumnFamilyOptions, DBOptions, WriteOptions, DB}; use super::rocksdb::{ColumnFamilyOptions, DBOptions, WriteOptions, DB};
use super::tempdir::TempDir;
use super::test::Bencher; use super::test::Bencher;
fn run_bench_wal(b: &mut Bencher, name: &str, mut opts: DBOptions, wopts: WriteOptions) { fn run_bench_wal(b: &mut Bencher, name: &str, mut opts: DBOptions, wopts: WriteOptions) {
let path = TempDir::new(name).expect(""); let path = tempfile::Builder::new().prefix(name).tempdir().expect("");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_max_background_jobs(6); opts.set_max_background_jobs(6);
......
extern crate test; extern crate test;
extern crate byteorder;
extern crate crc; extern crate crc;
extern crate rand; extern crate rand;
extern crate rocksdb; extern crate rocksdb;
extern crate tempdir; extern crate tempfile;
mod bench_wal; mod bench_wal;
...@@ -10,7 +10,7 @@ libc = "0.2.11" ...@@ -10,7 +10,7 @@ libc = "0.2.11"
libtitan_sys = { path = "libtitan_sys" } libtitan_sys = { path = "libtitan_sys" }
[dev-dependencies] [dev-dependencies]
tempdir = "0.3" tempfile = "3.1"
[features] [features]
default = [] default = []
......
...@@ -16,12 +16,13 @@ ...@@ -16,12 +16,13 @@
extern crate bzip2_sys; extern crate bzip2_sys;
extern crate libc; extern crate libc;
#[cfg(test)] #[cfg(test)]
extern crate tempdir; extern crate tempfile;
use libc::{c_char, c_double, c_int, c_uchar, c_void, size_t};
use std::ffi::CStr; use std::ffi::CStr;
use std::fmt; use std::fmt;
use libc::{c_char, c_double, c_int, c_uchar, c_void, size_t};
// FFI-safe opaque types. // FFI-safe opaque types.
// //
// These represent opaque RocksDB types. They are used behind pointers, but are // These represent opaque RocksDB types. They are used behind pointers, but are
...@@ -2118,7 +2119,10 @@ mod test { ...@@ -2118,7 +2119,10 @@ mod test {
use libc::{self, c_void}; use libc::{self, c_void};
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::{fs, ptr, slice}; use std::{fs, ptr, slice};
use tempdir::TempDir;
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {
tempfile::Builder::new().prefix(prefix).tempdir().expect()
}
#[test] #[test]
fn internal() { fn internal() {
...@@ -2129,8 +2133,7 @@ mod test { ...@@ -2129,8 +2133,7 @@ mod test {
crocksdb_options_increase_parallelism(opts, 0); crocksdb_options_increase_parallelism(opts, 0);
crocksdb_options_optimize_level_style_compaction(opts, 0); crocksdb_options_optimize_level_style_compaction(opts, 0);
crocksdb_options_set_create_if_missing(opts, true); crocksdb_options_set_create_if_missing(opts, true);
let rustpath = tempdir_with_prefix("_rust_rocksdb_internaltest");
let rustpath = TempDir::new("_rust_rocksdb_internaltest").expect("");
let cpath = CString::new(rustpath.path().to_str().unwrap()).unwrap(); let cpath = CString::new(rustpath.path().to_str().unwrap()).unwrap();
let cpath_ptr = cpath.as_ptr(); let cpath_ptr = cpath.as_ptr();
...@@ -2236,7 +2239,7 @@ mod test { ...@@ -2236,7 +2239,7 @@ mod test {
let opts = crocksdb_options_create(); let opts = crocksdb_options_create();
crocksdb_options_set_create_if_missing(opts, true); crocksdb_options_set_create_if_missing(opts, true);
let rustpath = TempDir::new("_rust_rocksdb_internaltest").expect(""); let rustpath = tempdir_with_prefix("_rust_rocksdb_internaltest");
let cpath = CString::new(rustpath.path().to_str().unwrap()).unwrap(); let cpath = CString::new(rustpath.path().to_str().unwrap()).unwrap();
let cpath_ptr = cpath.as_ptr(); let cpath_ptr = cpath.as_ptr();
...@@ -2248,7 +2251,7 @@ mod test { ...@@ -2248,7 +2251,7 @@ mod test {
let io_options = crocksdb_options_create(); let io_options = crocksdb_options_create();
let writer = crocksdb_sstfilewriter_create(env_opt, io_options); let writer = crocksdb_sstfilewriter_create(env_opt, io_options);
let sst_dir = TempDir::new("_rust_rocksdb_internaltest").expect(""); let sst_dir = tempdir_with_prefix("_rust_rocksdb_internaltest");
let sst_path = sst_dir.path().join("sstfilename"); let sst_path = sst_dir.path().join("sstfilename");
let c_sst_path = CString::new(sst_path.to_str().unwrap()).unwrap(); let c_sst_path = CString::new(sst_path.to_str().unwrap()).unwrap();
let c_sst_path_ptr = c_sst_path.as_ptr(); let c_sst_path_ptr = c_sst_path.as_ptr();
......
...@@ -18,7 +18,7 @@ extern crate libc; ...@@ -18,7 +18,7 @@ extern crate libc;
#[macro_use] #[macro_use]
pub extern crate librocksdb_sys; pub extern crate librocksdb_sys;
#[cfg(test)] #[cfg(test)]
extern crate tempdir; extern crate tempfile;
pub use compaction_filter::CompactionFilter; pub use compaction_filter::CompactionFilter;
pub use event_listener::{ pub use event_listener::{
...@@ -68,3 +68,8 @@ mod table_properties; ...@@ -68,3 +68,8 @@ mod table_properties;
mod table_properties_collector; mod table_properties_collector;
mod table_properties_collector_factory; mod table_properties_collector_factory;
mod titan; mod titan;
#[cfg(test)]
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {
tempfile::Builder::new().prefix(prefix).tempdir().expect("")
}
...@@ -145,10 +145,11 @@ impl<'a> Iterator for &'a mut MergeOperands { ...@@ -145,10 +145,11 @@ impl<'a> Iterator for &'a mut MergeOperands {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*;
use rocksdb::{DBVector, Writable, DB}; use rocksdb::{DBVector, Writable, DB};
use rocksdb_options::{ColumnFamilyOptions, DBOptions}; use rocksdb_options::{ColumnFamilyOptions, DBOptions};
use tempdir::TempDir;
use super::*;
use crate::tempdir_with_prefix;
#[allow(unused_variables)] #[allow(unused_variables)]
#[allow(dead_code)] #[allow(dead_code)]
...@@ -175,7 +176,7 @@ mod test { ...@@ -175,7 +176,7 @@ mod test {
#[allow(dead_code)] #[allow(dead_code)]
#[test] #[test]
fn mergetest() { fn mergetest() {
let path = TempDir::new("_rust_rocksdb_mergetest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_mergetest");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
......
...@@ -396,16 +396,15 @@ impl IOStatsContext { ...@@ -396,16 +396,15 @@ impl IOStatsContext {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*;
use tempdir::TempDir;
use rocksdb::{SeekKey, Writable, DB}; use rocksdb::{SeekKey, Writable, DB};
use rocksdb_options::{DBOptions, WriteOptions}; use rocksdb_options::{DBOptions, WriteOptions};
use super::*;
use crate::tempdir_with_prefix;
#[test] #[test]
fn test_perf_context() { fn test_perf_context() {
let temp_dir = TempDir::new("test_perf_context").unwrap(); let temp_dir = tempdir_with_prefix("test_perf_context");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open(opts, temp_dir.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, temp_dir.path().to_str().unwrap()).unwrap();
...@@ -451,7 +450,7 @@ mod test { ...@@ -451,7 +450,7 @@ mod test {
#[test] #[test]
fn test_iostats_context() { fn test_iostats_context() {
let temp_dir = TempDir::new("test_iostats_context").unwrap(); let temp_dir = tempdir_with_prefix("test_iostats_context");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open(opts, temp_dir.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, temp_dir.path().to_str().unwrap()).unwrap();
......
...@@ -2647,17 +2647,18 @@ pub fn run_ldb_tool(ldb_args: &[String], opts: &DBOptions) { ...@@ -2647,17 +2647,18 @@ pub fn run_ldb_tool(ldb_args: &[String], opts: &DBOptions) {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*;
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use std::str; use std::str;
use std::string::String; use std::string::String;
use std::thread; use std::thread;
use tempdir::TempDir;
use super::*;
use crate::tempdir_with_prefix;
#[test] #[test]
fn external() { fn external() {
let path = TempDir::new("_rust_rocksdb_externaltest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_externaltest");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
let p = db.put(b"k1", b"v1111"); let p = db.put(b"k1", b"v1111");
assert!(p.is_ok()); assert!(p.is_ok());
...@@ -2670,7 +2671,7 @@ mod test { ...@@ -2670,7 +2671,7 @@ mod test {
#[allow(unused_variables)] #[allow(unused_variables)]
#[test] #[test]
fn errors_do_stuff() { fn errors_do_stuff() {
let path = TempDir::new("_rust_rocksdb_error").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_error");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let db = DB::open_default(path_str).unwrap(); let db = DB::open_default(path_str).unwrap();
let opts = DBOptions::new(); let opts = DBOptions::new();
...@@ -2689,7 +2690,7 @@ mod test { ...@@ -2689,7 +2690,7 @@ mod test {
#[test] #[test]
fn writebatch_works() { fn writebatch_works() {
let path = TempDir::new("_rust_rocksdb_writebacktest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_writebacktest");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
// test put // test put
...@@ -2760,7 +2761,7 @@ mod test { ...@@ -2760,7 +2761,7 @@ mod test {
#[test] #[test]
fn iterator_test() { fn iterator_test() {
let path = TempDir::new("_rust_rocksdb_iteratortest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_iteratortest");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
db.put(b"k1", b"v1111").expect(""); db.put(b"k1", b"v1111").expect("");
...@@ -2779,7 +2780,7 @@ mod test { ...@@ -2779,7 +2780,7 @@ mod test {
#[test] #[test]
fn approximate_size_test() { fn approximate_size_test() {
let path = TempDir::new("_rust_rocksdb_iteratortest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_iteratortest");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
for i in 1..8000 { for i in 1..8000 {
db.put( db.put(
...@@ -2807,7 +2808,7 @@ mod test { ...@@ -2807,7 +2808,7 @@ mod test {
#[test] #[test]
fn property_test() { fn property_test() {
let path = TempDir::new("_rust_rocksdb_propertytest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_propertytest");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
db.put(b"a1", b"v1").unwrap(); db.put(b"a1", b"v1").unwrap();
db.flush(true).unwrap(); db.flush(true).unwrap();
...@@ -2822,7 +2823,7 @@ mod test { ...@@ -2822,7 +2823,7 @@ mod test {
#[test] #[test]
fn list_column_families_test() { fn list_column_families_test() {
let path = TempDir::new("_rust_rocksdb_list_column_families_test").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_list_column_families_test");
let mut cfs = ["default", "cf1", "cf2", "cf3"]; let mut cfs = ["default", "cf1", "cf2", "cf3"];
{ {
let mut cfs_opts = vec![]; let mut cfs_opts = vec![];
...@@ -2853,13 +2854,13 @@ mod test { ...@@ -2853,13 +2854,13 @@ mod test {
let key = b"foo"; let key = b"foo";
let value = b"bar"; let value = b"bar";
let db_dir = TempDir::new("_rust_rocksdb_backuptest").unwrap(); let db_dir = tempdir_with_prefix("_rust_rocksdb_backuptest");
let db = DB::open_default(db_dir.path().to_str().unwrap()).unwrap(); let db = DB::open_default(db_dir.path().to_str().unwrap()).unwrap();
let p = db.put(key, value); let p = db.put(key, value);
assert!(p.is_ok()); assert!(p.is_ok());
// Make a backup. // Make a backup.
let backup_dir = TempDir::new("_rust_rocksdb_backuptest_backup").unwrap(); let backup_dir = tempdir_with_prefix("_rust_rocksdb_backuptest_backup");
let backup_engine = db.backup_at(backup_dir.path().to_str().unwrap()).unwrap(); let backup_engine = db.backup_at(backup_dir.path().to_str().unwrap()).unwrap();
// Restore it. // Restore it.
...@@ -2868,7 +2869,7 @@ mod test { ...@@ -2868,7 +2869,7 @@ mod test {
ropt2.set_keep_log_files(true); ropt2.set_keep_log_files(true);
let ropts = [ropt1, ropt2]; let ropts = [ropt1, ropt2];
for ropt in &ropts { for ropt in &ropts {
let restore_dir = TempDir::new("_rust_rocksdb_backuptest_restore").unwrap(); let restore_dir = tempdir_with_prefix("_rust_rocksdb_backuptest_restore");
let restored_db = DB::restore_from( let restored_db = DB::restore_from(
&backup_engine, &backup_engine,
restore_dir.path().to_str().unwrap(), restore_dir.path().to_str().unwrap(),
...@@ -2884,7 +2885,7 @@ mod test { ...@@ -2884,7 +2885,7 @@ mod test {
#[test] #[test]
fn log_dir_test() { fn log_dir_test() {
let db_dir = TempDir::new("_rust_rocksdb_logdirtest").unwrap(); let db_dir = tempdir_with_prefix("_rust_rocksdb_logdirtest");
let db_path = db_dir.path().to_str().unwrap(); let db_path = db_dir.path().to_str().unwrap();
let log_path = format!("{}", Path::new(&db_path).join("log_path").display()); let log_path = format!("{}", Path::new(&db_path).join("log_path").display());
fs::create_dir_all(&log_path).unwrap(); fs::create_dir_all(&log_path).unwrap();
...@@ -2910,7 +2911,7 @@ mod test { ...@@ -2910,7 +2911,7 @@ mod test {
#[test] #[test]
fn single_delete_test() { fn single_delete_test() {
let path = TempDir::new("_rust_rocksdb_singledeletetest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_singledeletetest");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
db.put(b"a", b"v1").unwrap(); db.put(b"a", b"v1").unwrap();
...@@ -2945,7 +2946,7 @@ mod test { ...@@ -2945,7 +2946,7 @@ mod test {
#[test] #[test]
fn test_pause_bg_work() { fn test_pause_bg_work() {
let path = TempDir::new("_rust_rocksdb_pause_bg_work").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_pause_bg_work");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
let db = Arc::new(db); let db = Arc::new(db);
let db1 = db.clone(); let db1 = db.clone();
...@@ -3000,7 +3001,7 @@ mod test { ...@@ -3000,7 +3001,7 @@ mod test {
#[test] #[test]
fn block_cache_usage() { fn block_cache_usage() {
let path = TempDir::new("_rust_rocksdb_block_cache_usage").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_block_cache_usage");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
for i in 0..200 { for i in 0..200 {
...@@ -3018,7 +3019,7 @@ mod test { ...@@ -3018,7 +3019,7 @@ mod test {
#[test] #[test]
fn flush_cf() { fn flush_cf() {
let path = TempDir::new("_rust_rocksdb_flush_cf").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_flush_cf");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let mut db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
...@@ -3058,7 +3059,7 @@ mod test { ...@@ -3058,7 +3059,7 @@ mod test {
fn test_get_all_key_versions() { fn test_get_all_key_versions() {
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let path = TempDir::new("_rust_rocksdb_get_all_key_version_test").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_get_all_key_version_test");
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
let samples = vec![ let samples = vec![
...@@ -3084,7 +3085,7 @@ mod test { ...@@ -3084,7 +3085,7 @@ mod test {
fn test_get_approximate_memtable_stats() { fn test_get_approximate_memtable_stats() {
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let path = TempDir::new("_rust_rocksdb_get_approximate_memtable_stats").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_get_approximate_memtable_stats");
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
let samples = [ let samples = [
...@@ -3114,7 +3115,7 @@ mod test { ...@@ -3114,7 +3115,7 @@ mod test {
fn test_set_options() { fn test_set_options() {
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let path = TempDir::new("_rust_rocksdb_set_option").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_option");
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
let cf = db.cf_handle("default").unwrap(); let cf = db.cf_handle("default").unwrap();
...@@ -3135,7 +3136,7 @@ mod test { ...@@ -3135,7 +3136,7 @@ mod test {
#[test] #[test]
fn test_load_latest_options() { fn test_load_latest_options() {
let path = TempDir::new("_rust_rocksdb_load_latest_option").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_load_latest_option");
let dbpath = path.path().to_str().unwrap().clone(); let dbpath = path.path().to_str().unwrap().clone();
let cf_name: &str = "cf_dynamic_level_bytes"; let cf_name: &str = "cf_dynamic_level_bytes";
...@@ -3170,7 +3171,7 @@ mod test { ...@@ -3170,7 +3171,7 @@ mod test {
#[test] #[test]
fn test_sequence_number() { fn test_sequence_number() {
let path = TempDir::new("_rust_rocksdb_sequence_number").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_sequence_number");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -3188,7 +3189,7 @@ mod test { ...@@ -3188,7 +3189,7 @@ mod test {
#[test] #[test]
fn test_map_property() { fn test_map_property() {
let path = TempDir::new("_rust_rocksdb_get_map_property").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_get_map_property");
let dbpath = path.path().to_str().unwrap().clone(); let dbpath = path.path().to_str().unwrap().clone();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
......
extern crate byteorder;
extern crate crc;
extern crate rand;
extern crate rocksdb;
extern crate tempdir;
mod test_column_family; mod test_column_family;
mod test_compact_range; mod test_compact_range;
mod test_compaction_filter; mod test_compaction_filter;
...@@ -25,3 +19,7 @@ mod test_statistics; ...@@ -25,3 +19,7 @@ mod test_statistics;
mod test_table_properties; mod test_table_properties;
mod test_titan; mod test_titan;
mod test_ttl; mod test_ttl;
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {
tempfile::Builder::new().prefix(prefix).tempdir().expect("")
}
...@@ -14,11 +14,12 @@ ...@@ -14,11 +14,12 @@
// //
use rocksdb::{ColumnFamilyOptions, DBOptions, MergeOperands, Writable, DB}; use rocksdb::{ColumnFamilyOptions, DBOptions, MergeOperands, Writable, DB};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test] #[test]
pub fn test_column_family() { pub fn test_column_family() {
let path = TempDir::new("_rust_rocksdb_cftest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_cftest");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
// should be able to create column families // should be able to create column families
......
...@@ -15,11 +15,12 @@ use rocksdb::{ ...@@ -15,11 +15,12 @@ use rocksdb::{
ColumnFamilyOptions, CompactOptions, DBBottommostLevelCompaction, DBOptions, Range, Writable, ColumnFamilyOptions, CompactOptions, DBBottommostLevelCompaction, DBOptions, Range, Writable,
DB, DB,
}; };
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test] #[test]
fn test_compact_range() { fn test_compact_range() {
let path = TempDir::new("_rust_rocksdb_test_compact_range").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_compact_range");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
...@@ -50,7 +51,7 @@ fn test_compact_range() { ...@@ -50,7 +51,7 @@ fn test_compact_range() {
#[test] #[test]
fn test_compact_range_change_level() { fn test_compact_range_change_level() {
let path = TempDir::new("_rust_rocksdb_test_compact_range_change_level").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_compact_range_change_level");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
...@@ -85,7 +86,7 @@ fn test_compact_range_change_level() { ...@@ -85,7 +86,7 @@ fn test_compact_range_change_level() {
#[test] #[test]
fn test_compact_range_bottommost_level_compaction() { fn test_compact_range_bottommost_level_compaction() {
let path = TempDir::new("test_compact_range_bottommost_level_compaction").expect(""); let path = tempdir_with_prefix("test_compact_range_bottommost_level_compaction");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
......
...@@ -11,10 +11,12 @@ ...@@ -11,10 +11,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use rocksdb::{ColumnFamilyOptions, CompactionFilter, DBOptions, Writable, DB};
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use tempdir::TempDir;
use rocksdb::{ColumnFamilyOptions, CompactionFilter, DBOptions, Writable, DB};
use super::tempdir_with_prefix;
struct Filter { struct Filter {
drop_called: Arc<AtomicBool>, drop_called: Arc<AtomicBool>,
...@@ -39,7 +41,7 @@ impl Drop for Filter { ...@@ -39,7 +41,7 @@ impl Drop for Filter {
#[test] #[test]
fn test_compaction_filter() { fn test_compaction_filter() {
let path = TempDir::new("_rust_rocksdb_writebacktest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_writebacktest");
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
let drop_called = Arc::new(AtomicBool::new(false)); let drop_called = Arc::new(AtomicBool::new(false));
let filtered_kvs = Arc::new(RwLock::new(vec![])); let filtered_kvs = Arc::new(RwLock::new(vec![]));
......
...@@ -12,12 +12,13 @@ ...@@ -12,12 +12,13 @@
// limitations under the License. // limitations under the License.
use rocksdb::{ColumnFamilyOptions, DBCompressionType, DBOptions, DB}; use rocksdb::{ColumnFamilyOptions, DBCompressionType, DBOptions, DB};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test] #[test]
// Make sure all compression types are supported. // Make sure all compression types are supported.
fn test_compression() { fn test_compression() {
let path = TempDir::new("_rust_rocksdb_test_metadata").unwrap(); let path = tempdir_with_prefix("_rust_rocksdb_test_metadata");
let compression_types = [ let compression_types = [
DBCompressionType::Snappy, DBCompressionType::Snappy,
DBCompressionType::Zlib, DBCompressionType::Zlib,
......
...@@ -13,9 +13,10 @@ ...@@ -13,9 +13,10 @@
use std::ops; use std::ops;
use rand::{self, Rng}; use rand::{self, RngCore};
use rocksdb::*; use rocksdb::*;
use tempdir::TempDir;
use super::tempdir_with_prefix;
fn initial_data(path: &str) -> DB { fn initial_data(path: &str) -> DB {
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
...@@ -54,7 +55,7 @@ fn generate_file_bottom_level(db: &DB, handle: &CFHandle, range: ops::Range<u32> ...@@ -54,7 +55,7 @@ fn generate_file_bottom_level(db: &DB, handle: &CFHandle, range: ops::Range<u32>
#[test] #[test]
fn test_delete_files_in_range_with_iter() { fn test_delete_files_in_range_with_iter() {
let path = TempDir::new("_rust_rocksdb_test_delete_files_in_range_with_iter").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_files_in_range_with_iter");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let db = initial_data(path_str); let db = initial_data(path_str);
...@@ -77,7 +78,7 @@ fn test_delete_files_in_range_with_iter() { ...@@ -77,7 +78,7 @@ fn test_delete_files_in_range_with_iter() {
#[test] #[test]
fn test_delete_files_in_range_with_snap() { fn test_delete_files_in_range_with_snap() {
let path = TempDir::new("_rust_rocksdb_test_delete_files_in_range_with_snap").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_files_in_range_with_snap");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let db = initial_data(path_str); let db = initial_data(path_str);
...@@ -103,7 +104,7 @@ fn test_delete_files_in_range_with_snap() { ...@@ -103,7 +104,7 @@ fn test_delete_files_in_range_with_snap() {
#[test] #[test]
fn test_delete_files_in_range_with_delete_range() { fn test_delete_files_in_range_with_delete_range() {
// Regression test for https://github.com/facebook/rocksdb/issues/2833. // Regression test for https://github.com/facebook/rocksdb/issues/2833.
let path = TempDir::new("_rocksdb_test_delete_files_in_range_with_delete_range").expect(""); let path = tempdir_with_prefix("_rocksdb_test_delete_files_in_range_with_delete_range");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let sst_size = 1 << 10; let sst_size = 1 << 10;
...@@ -168,7 +169,7 @@ fn test_delete_files_in_range_with_delete_range() { ...@@ -168,7 +169,7 @@ fn test_delete_files_in_range_with_delete_range() {
#[test] #[test]
fn test_delete_files_in_ranges() { fn test_delete_files_in_ranges() {
let path = TempDir::new("_rust_rocksdb_test_delete_files_in_multi_ranges").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_files_in_multi_ranges");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let db = initial_data(path_str); let db = initial_data(path_str);
......
...@@ -11,10 +11,12 @@ ...@@ -11,10 +11,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::fs;
use crc::crc32::{self, Digest, Hasher32}; use crc::crc32::{self, Digest, Hasher32};
use rocksdb::*; use rocksdb::*;
use std::fs;
use tempdir::TempDir; use super::tempdir_with_prefix;
fn gen_sst(opt: ColumnFamilyOptions, cf: Option<&CFHandle>, path: &str) { fn gen_sst(opt: ColumnFamilyOptions, cf: Option<&CFHandle>, path: &str) {
let _ = fs::remove_file(path); let _ = fs::remove_file(path);
...@@ -79,7 +81,7 @@ fn gen_crc32_from_db_in_range(db: &DB, start_key: &[u8], end_key: &[u8]) -> u32 ...@@ -79,7 +81,7 @@ fn gen_crc32_from_db_in_range(db: &DB, start_key: &[u8], end_key: &[u8]) -> u32
#[test] #[test]
fn test_delete_range_case_1() { fn test_delete_range_case_1() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_1").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_1");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -96,7 +98,7 @@ fn test_delete_range_case_1() { ...@@ -96,7 +98,7 @@ fn test_delete_range_case_1() {
} }
let before = gen_crc32_from_db(&db); let before = gen_crc32_from_db(&db);
let gen_path = TempDir::new("_rust_rocksdb_case_1_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_1_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -140,7 +142,7 @@ fn test_delete_range_case_1() { ...@@ -140,7 +142,7 @@ fn test_delete_range_case_1() {
#[test] #[test]
fn test_delete_range_case_2() { fn test_delete_range_case_2() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_2_1").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_2_1");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -157,7 +159,7 @@ fn test_delete_range_case_2() { ...@@ -157,7 +159,7 @@ fn test_delete_range_case_2() {
} }
let before = gen_crc32_from_db(&db); let before = gen_crc32_from_db(&db);
let gen_path = TempDir::new("_rust_rocksdb_case_2_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_2_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -182,7 +184,7 @@ fn test_delete_range_case_2() { ...@@ -182,7 +184,7 @@ fn test_delete_range_case_2() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_2_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_2_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -207,7 +209,7 @@ fn test_delete_range_case_2() { ...@@ -207,7 +209,7 @@ fn test_delete_range_case_2() {
#[test] #[test]
fn test_delete_range_case_3() { fn test_delete_range_case_3() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_3").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_3");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -239,7 +241,7 @@ fn test_delete_range_case_3() { ...@@ -239,7 +241,7 @@ fn test_delete_range_case_3() {
], ],
); );
let path2 = TempDir::new("_rust_rocksdb_test_delete_range_case_3_2").expect(""); let path2 = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_3_2");
let path_str2 = path2.path().to_str().unwrap(); let path_str2 = path2.path().to_str().unwrap();
let mut opts2 = DBOptions::new(); let mut opts2 = DBOptions::new();
opts2.create_if_missing(true); opts2.create_if_missing(true);
...@@ -251,7 +253,7 @@ fn test_delete_range_case_3() { ...@@ -251,7 +253,7 @@ fn test_delete_range_case_3() {
assert_eq!(v, &*db2.get(k).unwrap().unwrap()); assert_eq!(v, &*db2.get(k).unwrap().unwrap());
} }
let gen_path = TempDir::new("_rust_rocksdb_case_3_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_3_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -284,7 +286,7 @@ fn test_delete_range_case_3() { ...@@ -284,7 +286,7 @@ fn test_delete_range_case_3() {
#[test] #[test]
fn test_delete_range_case_4() { fn test_delete_range_case_4() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_4").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_4");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -316,7 +318,7 @@ fn test_delete_range_case_4() { ...@@ -316,7 +318,7 @@ fn test_delete_range_case_4() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_4_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_4_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -328,7 +330,7 @@ fn test_delete_range_case_4() { ...@@ -328,7 +330,7 @@ fn test_delete_range_case_4() {
assert_eq!(v, &*db2.get(k).unwrap().unwrap()); assert_eq!(v, &*db2.get(k).unwrap().unwrap());
} }
let gen_path = TempDir::new("_rust_rocksdb_case_4_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_4_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -361,7 +363,7 @@ fn test_delete_range_case_4() { ...@@ -361,7 +363,7 @@ fn test_delete_range_case_4() {
#[test] #[test]
fn test_delete_range_case_5() { fn test_delete_range_case_5() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_5").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_5");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -392,7 +394,7 @@ fn test_delete_range_case_5() { ...@@ -392,7 +394,7 @@ fn test_delete_range_case_5() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_5_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_5_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -405,7 +407,7 @@ fn test_delete_range_case_5() { ...@@ -405,7 +407,7 @@ fn test_delete_range_case_5() {
} }
let before = gen_crc32_from_db(&db2); let before = gen_crc32_from_db(&db2);
let gen_path = TempDir::new("_rust_rocksdb_case_5_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_5_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -432,7 +434,7 @@ fn test_delete_range_case_5() { ...@@ -432,7 +434,7 @@ fn test_delete_range_case_5() {
#[test] #[test]
fn test_delete_range_case_6() { fn test_delete_range_case_6() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_6").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_6");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -465,7 +467,7 @@ fn test_delete_range_case_6() { ...@@ -465,7 +467,7 @@ fn test_delete_range_case_6() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_5_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_5_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -481,7 +483,7 @@ fn test_delete_range_case_6() { ...@@ -481,7 +483,7 @@ fn test_delete_range_case_6() {
assert_eq!(v, &*db2.get(k).unwrap().unwrap()); assert_eq!(v, &*db2.get(k).unwrap().unwrap());
} }
let gen_path = TempDir::new("_rust_rocksdb_case_6_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_6_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -514,7 +516,7 @@ fn test_delete_range_case_6() { ...@@ -514,7 +516,7 @@ fn test_delete_range_case_6() {
#[test] #[test]
fn test_delete_range_compact() { fn test_delete_range_compact() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_6").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_6");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -547,7 +549,7 @@ fn test_delete_range_compact() { ...@@ -547,7 +549,7 @@ fn test_delete_range_compact() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_case_5_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_case_5_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -563,7 +565,7 @@ fn test_delete_range_compact() { ...@@ -563,7 +565,7 @@ fn test_delete_range_compact() {
assert_eq!(v, &*db2.get(k).unwrap().unwrap()); assert_eq!(v, &*db2.get(k).unwrap().unwrap());
} }
let gen_path = TempDir::new("_rust_rocksdb_case_6_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_6_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -630,7 +632,7 @@ pub fn get_cf_handle<'a>(db: &'a DB, cf: &str) -> Result<&'a CFHandle, String> { ...@@ -630,7 +632,7 @@ pub fn get_cf_handle<'a>(db: &'a DB, cf: &str) -> Result<&'a CFHandle, String> {
#[test] #[test]
fn test_delete_range_prefix_bloom_case_1() { fn test_delete_range_prefix_bloom_case_1() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_1").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_1");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -660,7 +662,7 @@ fn test_delete_range_prefix_bloom_case_1() { ...@@ -660,7 +662,7 @@ fn test_delete_range_prefix_bloom_case_1() {
} }
let before = gen_crc32_from_db(&db); let before = gen_crc32_from_db(&db);
let gen_path = TempDir::new("_rust_rocksdb_case_prefix_bloom_1_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_prefix_bloom_1_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -705,7 +707,7 @@ fn test_delete_range_prefix_bloom_case_1() { ...@@ -705,7 +707,7 @@ fn test_delete_range_prefix_bloom_case_1() {
#[test] #[test]
fn test_delete_range_prefix_bloom_case_2() { fn test_delete_range_prefix_bloom_case_2() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -735,7 +737,7 @@ fn test_delete_range_prefix_bloom_case_2() { ...@@ -735,7 +737,7 @@ fn test_delete_range_prefix_bloom_case_2() {
} }
let before = gen_crc32_from_db(&db); let before = gen_crc32_from_db(&db);
let gen_path = TempDir::new("_rust_rocksdb_case_prefix_bloom_1_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_prefix_bloom_1_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -761,7 +763,7 @@ fn test_delete_range_prefix_bloom_case_2() { ...@@ -761,7 +763,7 @@ fn test_delete_range_prefix_bloom_case_2() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_2_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_2_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -798,7 +800,7 @@ fn test_delete_range_prefix_bloom_case_2() { ...@@ -798,7 +800,7 @@ fn test_delete_range_prefix_bloom_case_2() {
#[test] #[test]
fn test_delete_range_prefix_bloom_case_3() { fn test_delete_range_prefix_bloom_case_3() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_3").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_3");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -843,7 +845,7 @@ fn test_delete_range_prefix_bloom_case_3() { ...@@ -843,7 +845,7 @@ fn test_delete_range_prefix_bloom_case_3() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_3_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_3_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -866,7 +868,7 @@ fn test_delete_range_prefix_bloom_case_3() { ...@@ -866,7 +868,7 @@ fn test_delete_range_prefix_bloom_case_3() {
assert_eq!(v, &*db2.get(k).unwrap().unwrap()); assert_eq!(v, &*db2.get(k).unwrap().unwrap());
} }
let gen_path = TempDir::new("_rust_rocksdb_prefix_bloom_case_3_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_prefix_bloom_case_3_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -894,7 +896,7 @@ fn test_delete_range_prefix_bloom_case_3() { ...@@ -894,7 +896,7 @@ fn test_delete_range_prefix_bloom_case_3() {
#[test] #[test]
fn test_delete_range_prefix_bloom_case_4() { fn test_delete_range_prefix_bloom_case_4() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_4").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_4");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -939,7 +941,7 @@ fn test_delete_range_prefix_bloom_case_4() { ...@@ -939,7 +941,7 @@ fn test_delete_range_prefix_bloom_case_4() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_4_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_4_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -963,7 +965,7 @@ fn test_delete_range_prefix_bloom_case_4() { ...@@ -963,7 +965,7 @@ fn test_delete_range_prefix_bloom_case_4() {
assert_eq!(v, &*db2.get(k).unwrap().unwrap()); assert_eq!(v, &*db2.get(k).unwrap().unwrap());
} }
let gen_path = TempDir::new("_rust_rocksdb_case_prefix_bloom_4_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_prefix_bloom_4_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -991,7 +993,7 @@ fn test_delete_range_prefix_bloom_case_4() { ...@@ -991,7 +993,7 @@ fn test_delete_range_prefix_bloom_case_4() {
#[test] #[test]
fn test_delete_range_prefix_bloom_case_5() { fn test_delete_range_prefix_bloom_case_5() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_5").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_5");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -1034,7 +1036,7 @@ fn test_delete_range_prefix_bloom_case_5() { ...@@ -1034,7 +1036,7 @@ fn test_delete_range_prefix_bloom_case_5() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_5_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_5_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -1058,7 +1060,7 @@ fn test_delete_range_prefix_bloom_case_5() { ...@@ -1058,7 +1060,7 @@ fn test_delete_range_prefix_bloom_case_5() {
} }
let before = gen_crc32_from_db(&db2); let before = gen_crc32_from_db(&db2);
let gen_path = TempDir::new("_rust_rocksdb_case_prefix_bloom_5_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_prefix_bloom_5_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -1083,7 +1085,7 @@ fn test_delete_range_prefix_bloom_case_5() { ...@@ -1083,7 +1085,7 @@ fn test_delete_range_prefix_bloom_case_5() {
#[test] #[test]
fn test_delete_range_prefix_bloom_case_6() { fn test_delete_range_prefix_bloom_case_6() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_6").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_6");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -1128,7 +1130,7 @@ fn test_delete_range_prefix_bloom_case_6() { ...@@ -1128,7 +1130,7 @@ fn test_delete_range_prefix_bloom_case_6() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_6_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_6_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -1155,7 +1157,7 @@ fn test_delete_range_prefix_bloom_case_6() { ...@@ -1155,7 +1157,7 @@ fn test_delete_range_prefix_bloom_case_6() {
assert_eq!(v, &*db2.get(k).unwrap().unwrap()); assert_eq!(v, &*db2.get(k).unwrap().unwrap());
} }
let gen_path = TempDir::new("_rust_rocksdb_case_6_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_6_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -1201,7 +1203,7 @@ fn check_kv(db: &DB, cf: Option<&CFHandle>, data: &[(&[u8], Option<&[u8]>)]) { ...@@ -1201,7 +1203,7 @@ fn check_kv(db: &DB, cf: Option<&CFHandle>, data: &[(&[u8], Option<&[u8]>)]) {
#[test] #[test]
fn test_delete_range_prefix_bloom_compact_case() { fn test_delete_range_prefix_bloom_compact_case() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_6").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_6");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -1246,7 +1248,7 @@ fn test_delete_range_prefix_bloom_compact_case() { ...@@ -1246,7 +1248,7 @@ fn test_delete_range_prefix_bloom_compact_case() {
], ],
); );
let path = TempDir::new("_rust_rocksdb_test_delete_range_prefix_bloom_case_6_2").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_prefix_bloom_case_6_2");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -1273,7 +1275,7 @@ fn test_delete_range_prefix_bloom_compact_case() { ...@@ -1273,7 +1275,7 @@ fn test_delete_range_prefix_bloom_compact_case() {
assert_eq!(v, &*db2.get(k).unwrap().unwrap()); assert_eq!(v, &*db2.get(k).unwrap().unwrap());
} }
let gen_path = TempDir::new("_rust_rocksdb_case_6_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_case_6_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
...@@ -1303,7 +1305,7 @@ fn test_delete_range_prefix_bloom_compact_case() { ...@@ -1303,7 +1305,7 @@ fn test_delete_range_prefix_bloom_compact_case() {
#[test] #[test]
fn test_delete_range() { fn test_delete_range() {
// Test `DB::delete_range()` // Test `DB::delete_range()`
let path = TempDir::new("_rust_rocksdb_test_delete_range").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
// Prepare some data. // Prepare some data.
...@@ -1354,7 +1356,7 @@ fn test_delete_range() { ...@@ -1354,7 +1356,7 @@ fn test_delete_range() {
#[test] #[test]
fn test_delete_range_sst_files() { fn test_delete_range_sst_files() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_sst_files").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_sst_files");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
let samples_a = vec![ let samples_a = vec![
(b"key1", b"value1"), (b"key1", b"value1"),
...@@ -1417,12 +1419,12 @@ fn test_delete_range_sst_files() { ...@@ -1417,12 +1419,12 @@ fn test_delete_range_sst_files() {
#[test] #[test]
fn test_delete_range_ingest_file() { fn test_delete_range_ingest_file() {
let path = TempDir::new("_rust_rocksdb_test_delete_range_ingest_file").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_delete_range_ingest_file");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut db = DB::open(opts, path_str).unwrap(); let mut db = DB::open(opts, path_str).unwrap();
let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let ingest_opt = IngestExternalFileOptions::new(); let ingest_opt = IngestExternalFileOptions::new();
......
...@@ -11,10 +11,11 @@ ...@@ -11,10 +11,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use rocksdb::Env;
use rocksdb::{DBOptions, Writable, DB};
use std::sync::Arc; use std::sync::Arc;
use tempdir::TempDir;
use rocksdb::{DBOptions, Env, Writable, DB};
use super::tempdir_with_prefix;
#[test] #[test]
fn test_ctr_encrypted_env() { fn test_ctr_encrypted_env() {
...@@ -36,7 +37,7 @@ fn test_ctr_encrypted_env() { ...@@ -36,7 +37,7 @@ fn test_ctr_encrypted_env() {
} }
fn test_ctr_encrypted_env_impl(encrypted_env: Arc<Env>) { fn test_ctr_encrypted_env_impl(encrypted_env: Arc<Env>) {
let path = TempDir::new("_rust_rocksdb_cryption_env").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_cryption_env");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
......
...@@ -11,11 +11,13 @@ ...@@ -11,11 +11,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use cases::test_ingest_external_file::gen_sst;
use rocksdb::*;
use std::sync::atomic::*; use std::sync::atomic::*;
use std::sync::Arc; use std::sync::Arc;
use tempdir::TempDir;
use rocksdb::*;
use super::tempdir_with_prefix;
use super::test_ingest_external_file::gen_sst;
#[derive(Default, Clone)] #[derive(Default, Clone)]
struct EventCounter { struct EventCounter {
...@@ -134,7 +136,7 @@ impl EventListener for BackgroundErrorCounter { ...@@ -134,7 +136,7 @@ impl EventListener for BackgroundErrorCounter {
#[test] #[test]
fn test_event_listener_stall_conditions_changed() { fn test_event_listener_stall_conditions_changed() {
let path = TempDir::new("_rust_rocksdb_event_listener_stall_conditions").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_event_listener_stall_conditions");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
...@@ -179,7 +181,7 @@ fn test_event_listener_stall_conditions_changed() { ...@@ -179,7 +181,7 @@ fn test_event_listener_stall_conditions_changed() {
#[test] #[test]
fn test_event_listener_basic() { fn test_event_listener_basic() {
let path = TempDir::new("_rust_rocksdb_event_listener_flush").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_event_listener_flush");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
...@@ -225,7 +227,7 @@ fn test_event_listener_basic() { ...@@ -225,7 +227,7 @@ fn test_event_listener_basic() {
#[test] #[test]
fn test_event_listener_ingestion() { fn test_event_listener_ingestion() {
let path = TempDir::new("_rust_rocksdb_event_listener_ingestion").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_event_listener_ingestion");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
...@@ -234,7 +236,7 @@ fn test_event_listener_ingestion() { ...@@ -234,7 +236,7 @@ fn test_event_listener_ingestion() {
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open(opts, path_str).unwrap(); let db = DB::open(opts, path_str).unwrap();
let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
...@@ -259,7 +261,7 @@ fn test_event_listener_ingestion() { ...@@ -259,7 +261,7 @@ fn test_event_listener_ingestion() {
fn test_event_listener_background_error() { fn test_event_listener_background_error() {
// TODO(yiwu): should create a test Env object which inject some IO error, to // TODO(yiwu): should create a test Env object which inject some IO error, to
// actually trigger background error. // actually trigger background error.
let path = TempDir::new("_rust_rocksdb_event_listener_ingestion").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_event_listener_ingestion");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
......
...@@ -11,11 +11,13 @@ ...@@ -11,11 +11,13 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use rocksdb::*;
use std::fs; use std::fs;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::sync::Arc; use std::sync::Arc;
use tempdir::TempDir;
use rocksdb::*;
use super::tempdir_with_prefix;
pub fn gen_sst( pub fn gen_sst(
opt: ColumnFamilyOptions, opt: ColumnFamilyOptions,
...@@ -99,11 +101,11 @@ fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOpera ...@@ -99,11 +101,11 @@ fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOpera
#[test] #[test]
fn test_ingest_external_file() { fn test_ingest_external_file() {
let path = TempDir::new("_rust_rocksdb_ingest_sst").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_ingest_sst");
let mut db = create_default_database(&path); let mut db = create_default_database(&path);
db.create_cf("cf1").unwrap(); db.create_cf("cf1").unwrap();
let handle = db.cf_handle("cf1").unwrap(); let handle = db.cf_handle("cf1").unwrap();
let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_ingest_sst_gen");
let test_sstfile = gen_path.path().join("test_sst_file"); let test_sstfile = gen_path.path().join("test_sst_file");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let default_options = db.get_options(); let default_options = db.get_options();
...@@ -153,14 +155,14 @@ fn test_ingest_external_file() { ...@@ -153,14 +155,14 @@ fn test_ingest_external_file() {
#[test] #[test]
fn test_ingest_external_file_new() { fn test_ingest_external_file_new() {
let path = TempDir::new("_rust_rocksdb_ingest_sst_new").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_ingest_sst_new");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
cf_opts.add_merge_operator("merge operator", concat_merge); cf_opts.add_merge_operator("merge operator", concat_merge);
let db = DB::open_cf(opts, path_str, vec![("default", cf_opts)]).unwrap(); let db = DB::open_cf(opts, path_str, vec![("default", cf_opts)]).unwrap();
let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen_new").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_ingest_sst_gen_new");
let test_sstfile = gen_path.path().join("test_sst_file_new"); let test_sstfile = gen_path.path().join("test_sst_file_new");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let default_options = db.get_options(); let default_options = db.get_options();
...@@ -213,9 +215,9 @@ fn test_ingest_external_file_new() { ...@@ -213,9 +215,9 @@ fn test_ingest_external_file_new() {
#[test] #[test]
fn test_ingest_external_file_new_cf() { fn test_ingest_external_file_new_cf() {
let path = TempDir::new("_rust_rocksdb_ingest_sst_new_cf").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_ingest_sst_new_cf");
let mut db = create_default_database(&path); let mut db = create_default_database(&path);
let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen_new_cf").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_ingest_sst_gen_new_cf");
let test_sstfile = gen_path.path().join("test_sst_file_new_cf"); let test_sstfile = gen_path.path().join("test_sst_file_new_cf");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
...@@ -296,7 +298,7 @@ fn gen_sst_from_cf(opt: ColumnFamilyOptions, db: &DB, cf: &CFHandle, path: &str) ...@@ -296,7 +298,7 @@ fn gen_sst_from_cf(opt: ColumnFamilyOptions, db: &DB, cf: &CFHandle, path: &str)
assert!(info.num_entries() > 0); assert!(info.num_entries() > 0);
} }
fn create_default_database(path: &TempDir) -> DB { fn create_default_database(path: &tempfile::TempDir) -> DB {
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -314,9 +316,9 @@ fn create_cfs(db: &mut DB, cfs: &[&str]) { ...@@ -314,9 +316,9 @@ fn create_cfs(db: &mut DB, cfs: &[&str]) {
#[test] #[test]
fn test_ingest_simulate_real_world() { fn test_ingest_simulate_real_world() {
const ALL_CFS: [&str; 3] = ["lock", "write", "default"]; const ALL_CFS: [&str; 3] = ["lock", "write", "default"];
let path = TempDir::new("_rust_rocksdb_ingest_real_world_1").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_ingest_real_world_1");
let mut db = create_default_database(&path); let mut db = create_default_database(&path);
let gen_path = TempDir::new("_rust_rocksdb_ingest_real_world_new_cf").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_ingest_real_world_new_cf");
create_cfs(&mut db, &ALL_CFS); create_cfs(&mut db, &ALL_CFS);
for cf in &ALL_CFS { for cf in &ALL_CFS {
let handle = db.cf_handle(cf).unwrap(); let handle = db.cf_handle(cf).unwrap();
...@@ -329,7 +331,7 @@ fn test_ingest_simulate_real_world() { ...@@ -329,7 +331,7 @@ fn test_ingest_simulate_real_world() {
); );
} }
let path2 = TempDir::new("_rust_rocksdb_ingest_real_world_2").expect(""); let path2 = tempdir_with_prefix("_rust_rocksdb_ingest_real_world_2");
let mut db2 = create_default_database(&path2); let mut db2 = create_default_database(&path2);
for cf in &ALL_CFS { for cf in &ALL_CFS {
if *cf != "default" { if *cf != "default" {
...@@ -389,7 +391,7 @@ fn test_ingest_simulate_real_world() { ...@@ -389,7 +391,7 @@ fn test_ingest_simulate_real_world() {
#[test] #[test]
fn test_mem_sst_file_writer() { fn test_mem_sst_file_writer() {
let path = TempDir::new("_rust_mem_sst_file_writer").expect(""); let path = tempdir_with_prefix("_rust_mem_sst_file_writer");
let db = create_default_database(&path); let db = create_default_database(&path);
let env = Arc::new(Env::new_mem()); let env = Arc::new(Env::new_mem());
...@@ -440,9 +442,9 @@ fn test_mem_sst_file_writer() { ...@@ -440,9 +442,9 @@ fn test_mem_sst_file_writer() {
#[test] #[test]
fn test_set_external_sst_file_global_seq_no() { fn test_set_external_sst_file_global_seq_no() {
let db_path = TempDir::new("_rust_rocksdb_set_external_sst_file_global_seq_no_db").expect(""); let db_path = tempdir_with_prefix("_rust_rocksdb_set_external_sst_file_global_seq_no_db");
let db = create_default_database(&db_path); let db = create_default_database(&db_path);
let path = TempDir::new("_rust_rocksdb_set_external_sst_file_global_seq_no").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_external_sst_file_global_seq_no");
let file = path.path().join("sst_file"); let file = path.path().join("sst_file");
let sstfile_str = file.to_str().unwrap(); let sstfile_str = file.to_str().unwrap();
gen_sst( gen_sst(
...@@ -471,9 +473,9 @@ fn test_set_external_sst_file_global_seq_no() { ...@@ -471,9 +473,9 @@ fn test_set_external_sst_file_global_seq_no() {
#[test] #[test]
fn test_ingest_external_file_optimized() { fn test_ingest_external_file_optimized() {
let path = TempDir::new("_rust_rocksdb_ingest_sst_optimized").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_ingest_sst_optimized");
let db = create_default_database(&path); let db = create_default_database(&path);
let gen_path = TempDir::new("_rust_rocksdb_ingest_sst_gen_new_cf").expect(""); let gen_path = tempdir_with_prefix("_rust_rocksdb_ingest_sst_gen_new_cf");
let test_sstfile = gen_path.path().join("test_sst_file_optimized"); let test_sstfile = gen_path.path().join("test_sst_file_optimized");
let test_sstfile_str = test_sstfile.to_str().unwrap(); let test_sstfile_str = test_sstfile.to_str().unwrap();
let handle = db.cf_handle("default").unwrap(); let handle = db.cf_handle("default").unwrap();
...@@ -508,7 +510,7 @@ fn test_ingest_external_file_optimized() { ...@@ -508,7 +510,7 @@ fn test_ingest_external_file_optimized() {
#[test] #[test]
fn test_read_sst() { fn test_read_sst() {
let dir = TempDir::new("_rust_rocksdb_test_read_sst").unwrap(); let dir = tempdir_with_prefix("_rust_rocksdb_test_read_sst");
let sst_path = dir.path().join("sst"); let sst_path = dir.path().join("sst");
let sst_path_str = sst_path.to_str().unwrap(); let sst_path_str = sst_path.to_str().unwrap();
gen_sst_put(ColumnFamilyOptions::new(), None, sst_path_str); gen_sst_put(ColumnFamilyOptions::new(), None, sst_path_str);
...@@ -533,7 +535,7 @@ fn test_read_sst() { ...@@ -533,7 +535,7 @@ fn test_read_sst() {
#[test] #[test]
fn test_read_invalid_sst() { fn test_read_invalid_sst() {
let dir = TempDir::new("_rust_rocksdb_test_read_invalid_sst").unwrap(); let dir = tempdir_with_prefix("_rust_rocksdb_test_read_invalid_sst");
let sst_path = dir.path().join("sst"); let sst_path = dir.path().join("sst");
let sst_path_str = sst_path.to_str().unwrap(); let sst_path_str = sst_path.to_str().unwrap();
gen_sst_put(ColumnFamilyOptions::new(), None, sst_path_str); gen_sst_put(ColumnFamilyOptions::new(), None, sst_path_str);
......
...@@ -11,12 +11,14 @@ ...@@ -11,12 +11,14 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use rocksdb::rocksdb::Snapshot;
use rocksdb::*;
use std::ops::Deref; use std::ops::Deref;
use std::sync::*; use std::sync::*;
use std::thread; use std::thread;
use tempdir::TempDir;
use rocksdb::rocksdb::Snapshot;
use rocksdb::*;
use super::tempdir_with_prefix;
struct FixedPrefixTransform { struct FixedPrefixTransform {
pub prefix_len: usize, pub prefix_len: usize,
...@@ -66,7 +68,7 @@ fn next_collect<D: Deref<Target = DB>>(iter: &mut DBIterator<D>) -> Vec<Kv> { ...@@ -66,7 +68,7 @@ fn next_collect<D: Deref<Target = DB>>(iter: &mut DBIterator<D>) -> Vec<Kv> {
#[test] #[test]
pub fn test_iterator() { pub fn test_iterator() {
let path = TempDir::new("_rust_rocksdb_iteratortest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_iteratortest");
let k1 = b"k1"; let k1 = b"k1";
let k2 = b"k2"; let k2 = b"k2";
...@@ -176,7 +178,7 @@ pub fn test_iterator() { ...@@ -176,7 +178,7 @@ pub fn test_iterator() {
#[test] #[test]
fn test_send_iterator() { fn test_send_iterator() {
let path = TempDir::new("_rust_rocksdb_iteratortest_send").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_iteratortest_send");
let db = Arc::new(DB::open_default(path.path().to_str().unwrap()).unwrap()); let db = Arc::new(DB::open_default(path.path().to_str().unwrap()).unwrap());
db.put(b"k1", b"v1").unwrap(); db.put(b"k1", b"v1").unwrap();
...@@ -219,7 +221,7 @@ fn test_send_iterator() { ...@@ -219,7 +221,7 @@ fn test_send_iterator() {
#[test] #[test]
fn test_seek_for_prev() { fn test_seek_for_prev() {
let path = TempDir::new("_rust_rocksdb_seek_for_prev").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_seek_for_prev");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
{ {
...@@ -267,7 +269,7 @@ fn test_seek_for_prev() { ...@@ -267,7 +269,7 @@ fn test_seek_for_prev() {
#[test] #[test]
fn read_with_upper_bound() { fn read_with_upper_bound() {
let path = TempDir::new("_rust_rocksdb_read_with_upper_bound_test").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_read_with_upper_bound_test");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
{ {
...@@ -290,7 +292,7 @@ fn read_with_upper_bound() { ...@@ -290,7 +292,7 @@ fn read_with_upper_bound() {
#[test] #[test]
fn test_total_order_seek() { fn test_total_order_seek() {
let path = TempDir::new("_rust_rocksdb_total_order_seek").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_total_order_seek");
let mut bbto = BlockBasedOptions::new(); let mut bbto = BlockBasedOptions::new();
bbto.set_bloom_filter(10, false); bbto.set_bloom_filter(10, false);
bbto.set_whole_key_filtering(false); bbto.set_whole_key_filtering(false);
...@@ -378,7 +380,7 @@ fn test_total_order_seek() { ...@@ -378,7 +380,7 @@ fn test_total_order_seek() {
#[test] #[test]
fn test_fixed_suffix_seek() { fn test_fixed_suffix_seek() {
let path = TempDir::new("_rust_rocksdb_fixed_suffix_seek").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_fixed_suffix_seek");
let mut bbto = BlockBasedOptions::new(); let mut bbto = BlockBasedOptions::new();
bbto.set_bloom_filter(10, false); bbto.set_bloom_filter(10, false);
bbto.set_whole_key_filtering(false); bbto.set_whole_key_filtering(false);
......
...@@ -14,11 +14,12 @@ ...@@ -14,11 +14,12 @@
use rocksdb::{ use rocksdb::{
CFHandle, ColumnFamilyOptions, CompactionOptions, DBCompressionType, DBOptions, Writable, DB, CFHandle, ColumnFamilyOptions, CompactionOptions, DBCompressionType, DBOptions, Writable, DB,
}; };
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test] #[test]
fn test_metadata() { fn test_metadata() {
let path = TempDir::new("_rust_rocksdb_test_metadata").unwrap(); let path = tempdir_with_prefix("_rust_rocksdb_test_metadata");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
...@@ -72,7 +73,7 @@ fn get_files_cf(db: &DB, cf: &CFHandle, max_level: usize) -> Vec<String> { ...@@ -72,7 +73,7 @@ fn get_files_cf(db: &DB, cf: &CFHandle, max_level: usize) -> Vec<String> {
#[test] #[test]
fn test_compact_files() { fn test_compact_files() {
let path = TempDir::new("_rust_rocksdb_test_metadata").unwrap(); let path = tempdir_with_prefix("_rust_rocksdb_test_metadata");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
......
...@@ -11,16 +11,18 @@ ...@@ -11,16 +11,18 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use rocksdb::{Writable, DB};
use std::sync::Arc; use std::sync::Arc;
use std::thread; use std::thread;
use tempdir::TempDir;
use rocksdb::{Writable, DB};
use super::tempdir_with_prefix;
const N: usize = 100_000; const N: usize = 100_000;
#[test] #[test]
pub fn test_multithreaded() { pub fn test_multithreaded() {
let path = TempDir::new("_rust_rocksdb_multithreadtest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_multithreadtest");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
let db = Arc::new(db); let db = Arc::new(db);
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
// limitations under the License. // limitations under the License.
use rocksdb::*; use rocksdb::*;
use tempdir::TempDir;
use super::tempdir_with_prefix;
struct FixedPrefixTransform { struct FixedPrefixTransform {
pub prefix_len: usize, pub prefix_len: usize,
...@@ -30,7 +31,7 @@ impl SliceTransform for FixedPrefixTransform { ...@@ -30,7 +31,7 @@ impl SliceTransform for FixedPrefixTransform {
#[test] #[test]
fn test_prefix_extractor_compatibility() { fn test_prefix_extractor_compatibility() {
let path = TempDir::new("_rust_rocksdb_prefix_extractor_compatibility").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_prefix_extractor_compatibility");
let keys = vec![ let keys = vec![
b"k1-0", b"k1-1", b"k1-2", b"k1-3", b"k1-4", b"k1-5", b"k1-6", b"k1-7", b"k1-8", b"k1-0", b"k1-1", b"k1-2", b"k1-3", b"k1-4", b"k1-5", b"k1-6", b"k1-7", b"k1-8",
]; ];
......
...@@ -11,9 +11,10 @@ ...@@ -11,9 +11,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use rocksdb::RateLimiter;
use std::thread; use std::thread;
use rocksdb::RateLimiter;
#[test] #[test]
fn test_rate_limiter() { fn test_rate_limiter() {
let rate_limiter = RateLimiter::new(10 * 1024 * 1024, 100 * 1000, 10); let rate_limiter = RateLimiter::new(10 * 1024 * 1024, 100 * 1000, 10);
......
use rocksdb::{DBOptions, Writable, DB}; use rocksdb::{DBOptions, Writable, DB};
use tempdir::TempDir;
use super::tempdir_with_prefix;
macro_rules! check_kv { macro_rules! check_kv {
($db:expr, $key:expr, $val:expr) => { ($db:expr, $key:expr, $val:expr) => {
...@@ -12,7 +13,7 @@ macro_rules! check_kv { ...@@ -12,7 +13,7 @@ macro_rules! check_kv {
#[test] #[test]
fn test_open_for_read_only() { fn test_open_for_read_only() {
let temp = TempDir::new("_rust_rocksdb_test_open_for_read_only").expect(""); let temp = tempdir_with_prefix("_rust_rocksdb_test_open_for_read_only");
let path = temp.path().to_str().unwrap(); let path = temp.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -48,7 +49,7 @@ fn test_open_for_read_only() { ...@@ -48,7 +49,7 @@ fn test_open_for_read_only() {
#[test] #[test]
fn test_open_cf_for_read_only() { fn test_open_cf_for_read_only() {
let temp = TempDir::new("_rust_rocksdb_test_open_cf_for_read_only").expect(""); let temp = tempdir_with_prefix("_rust_rocksdb_test_open_cf_for_read_only");
let path = temp.path().to_str().unwrap(); let path = temp.path().to_str().unwrap();
{ {
......
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use std::path::Path;
use std::sync::Arc;
use std::thread;
use std::time::Duration;
use rocksdb::crocksdb_ffi::{ use rocksdb::crocksdb_ffi::{
CompactionPriority, DBCompressionType, DBInfoLogLevel as InfoLogLevel, DBRateLimiterMode, CompactionPriority, DBCompressionType, DBInfoLogLevel as InfoLogLevel, DBRateLimiterMode,
DBStatisticsHistogramType as HistogramType, DBStatisticsTickerType as TickerType, DBStatisticsHistogramType as HistogramType, DBStatisticsTickerType as TickerType,
...@@ -20,15 +25,12 @@ use rocksdb::{ ...@@ -20,15 +25,12 @@ use rocksdb::{
FifoCompactionOptions, IndexType, LRUCacheOptions, ReadOptions, SeekKey, SliceTransform, FifoCompactionOptions, IndexType, LRUCacheOptions, ReadOptions, SeekKey, SliceTransform,
Writable, WriteOptions, DB, Writable, WriteOptions, DB,
}; };
use std::path::Path;
use std::sync::Arc; use super::tempdir_with_prefix;
use std::thread;
use std::time::Duration;
use tempdir::TempDir;
#[test] #[test]
fn test_set_num_levels() { fn test_set_num_levels() {
let path = TempDir::new("_rust_rocksdb_test_set_num_levels").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_set_num_levels");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -45,7 +47,7 @@ fn test_set_num_levels() { ...@@ -45,7 +47,7 @@ fn test_set_num_levels() {
#[test] #[test]
fn test_log_file_opt() { fn test_log_file_opt() {
let path = TempDir::new("_rust_rocksdb_log_file_opt").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_log_file_opt");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_max_log_file_size(100 * 1024 * 1024); opts.set_max_log_file_size(100 * 1024 * 1024);
...@@ -57,7 +59,7 @@ fn test_log_file_opt() { ...@@ -57,7 +59,7 @@ fn test_log_file_opt() {
#[test] #[test]
fn test_compaction_readahead_size() { fn test_compaction_readahead_size() {
let path = TempDir::new("_rust_rocksdb_compaction_readahead_size").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_compaction_readahead_size");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_compaction_readahead_size(2048); opts.set_compaction_readahead_size(2048);
...@@ -117,7 +119,7 @@ impl SliceTransform for FixedPrefixTransform { ...@@ -117,7 +119,7 @@ impl SliceTransform for FixedPrefixTransform {
#[test] #[test]
fn test_memtable_insert_hint_prefix_extractor() { fn test_memtable_insert_hint_prefix_extractor() {
let path = TempDir::new("_rust_rocksdb_memtable_insert_hint_prefix_extractor").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_memtable_insert_hint_prefix_extractor");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -145,7 +147,7 @@ fn test_memtable_insert_hint_prefix_extractor() { ...@@ -145,7 +147,7 @@ fn test_memtable_insert_hint_prefix_extractor() {
#[test] #[test]
fn test_set_delayed_write_rate() { fn test_set_delayed_write_rate() {
let path = TempDir::new("_rust_rocksdb_test_set_delayed_write_rate").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_set_delayed_write_rate");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_delayed_write_rate(2 * 1024 * 1024); opts.set_delayed_write_rate(2 * 1024 * 1024);
...@@ -155,7 +157,7 @@ fn test_set_delayed_write_rate() { ...@@ -155,7 +157,7 @@ fn test_set_delayed_write_rate() {
#[test] #[test]
fn test_set_ratelimiter() { fn test_set_ratelimiter() {
let path = TempDir::new("_rust_rocksdb_test_set_rate_limiter").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_set_rate_limiter");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
// compaction and flush rate limited below 100MB/sec // compaction and flush rate limited below 100MB/sec
...@@ -166,7 +168,7 @@ fn test_set_ratelimiter() { ...@@ -166,7 +168,7 @@ fn test_set_ratelimiter() {
#[test] #[test]
fn test_set_ratelimiter_with_auto_tuned() { fn test_set_ratelimiter_with_auto_tuned() {
let path = TempDir::new("_rust_rocksdb_test_set_rate_limiter_with_auto_tuned").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_set_rate_limiter_with_auto_tuned");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_ratelimiter_with_auto_tuned(100 * 1024 * 1024, DBRateLimiterMode::AllIo, true); opts.set_ratelimiter_with_auto_tuned(100 * 1024 * 1024, DBRateLimiterMode::AllIo, true);
...@@ -176,12 +178,12 @@ fn test_set_ratelimiter_with_auto_tuned() { ...@@ -176,12 +178,12 @@ fn test_set_ratelimiter_with_auto_tuned() {
#[test] #[test]
fn test_set_wal_opt() { fn test_set_wal_opt() {
let path = TempDir::new("_rust_rocksdb_test_set_wal_opt").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_set_wal_opt");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_wal_ttl_seconds(86400); opts.set_wal_ttl_seconds(86400);
opts.set_wal_size_limit_mb(10); opts.set_wal_size_limit_mb(10);
let wal_dir = TempDir::new("_rust_rocksdb_test_set_wal_dir").expect(""); let wal_dir = tempdir_with_prefix("_rust_rocksdb_test_set_wal_dir");
opts.set_wal_dir(wal_dir.path().to_str().unwrap()); opts.set_wal_dir(wal_dir.path().to_str().unwrap());
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
drop(db); drop(db);
...@@ -190,7 +192,7 @@ fn test_set_wal_opt() { ...@@ -190,7 +192,7 @@ fn test_set_wal_opt() {
#[cfg(not(windows))] #[cfg(not(windows))]
#[test] #[test]
fn test_flush_wal() { fn test_flush_wal() {
let path = TempDir::new("_rust_rocksdb_test_flush_wal").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_flush_wal");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.manual_wal_flush(true); opts.manual_wal_flush(true);
...@@ -203,7 +205,7 @@ fn test_flush_wal() { ...@@ -203,7 +205,7 @@ fn test_flush_wal() {
#[cfg(not(windows))] #[cfg(not(windows))]
#[test] #[test]
fn test_sync_wal() { fn test_sync_wal() {
let path = TempDir::new("_rust_rocksdb_test_sync_wal").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_sync_wal");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap(); let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
...@@ -214,13 +216,13 @@ fn test_sync_wal() { ...@@ -214,13 +216,13 @@ fn test_sync_wal() {
#[test] #[test]
fn test_create_info_log() { fn test_create_info_log() {
let path = TempDir::new("_rust_rocksdb_test_create_info_log_opt").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_create_info_log_opt");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_info_log_level(InfoLogLevel::Debug); opts.set_info_log_level(InfoLogLevel::Debug);
opts.set_log_file_time_to_roll(1); opts.set_log_file_time_to_roll(1);
let info_dir = TempDir::new("_rust_rocksdb_test_info_log_dir").expect(""); let info_dir = tempdir_with_prefix("_rust_rocksdb_test_info_log_dir");
opts.create_info_log(info_dir.path().to_str().unwrap()) opts.create_info_log(info_dir.path().to_str().unwrap())
.unwrap(); .unwrap();
...@@ -243,12 +245,12 @@ fn test_create_info_log() { ...@@ -243,12 +245,12 @@ fn test_create_info_log() {
#[test] #[test]
fn test_auto_roll_max_size_info_log() { fn test_auto_roll_max_size_info_log() {
let path = TempDir::new("_rust_rocksdb_test_max_size_info_log_opt").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_test_max_size_info_log_opt");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_max_log_file_size(10); opts.set_max_log_file_size(10);
let info_dir = TempDir::new("_rust_rocksdb_max_size_info_log_dir").expect(""); let info_dir = tempdir_with_prefix("_rust_rocksdb_max_size_info_log_dir");
opts.create_info_log(info_dir.path().to_str().unwrap()) opts.create_info_log(info_dir.path().to_str().unwrap())
.unwrap(); .unwrap();
...@@ -264,7 +266,7 @@ fn test_auto_roll_max_size_info_log() { ...@@ -264,7 +266,7 @@ fn test_auto_roll_max_size_info_log() {
#[test] #[test]
fn test_set_pin_l0_filter_and_index_blocks_in_cache() { fn test_set_pin_l0_filter_and_index_blocks_in_cache() {
let path = TempDir::new("_rust_rocksdb_set_cache_and_index").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_cache_and_index");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -281,7 +283,7 @@ fn test_set_pin_l0_filter_and_index_blocks_in_cache() { ...@@ -281,7 +283,7 @@ fn test_set_pin_l0_filter_and_index_blocks_in_cache() {
#[test] #[test]
fn test_partitioned_index_filters() { fn test_partitioned_index_filters() {
let path = TempDir::new("_rust_rocksdb_set_cache_and_index").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_cache_and_index");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -306,7 +308,7 @@ fn test_partitioned_index_filters() { ...@@ -306,7 +308,7 @@ fn test_partitioned_index_filters() {
#[test] #[test]
fn test_set_lru_cache() { fn test_set_lru_cache() {
let path = TempDir::new("_rust_rocksdb_set_set_lru_cache").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_set_lru_cache");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -321,7 +323,8 @@ fn test_set_lru_cache() { ...@@ -321,7 +323,8 @@ fn test_set_lru_cache() {
#[cfg(feature = "jemalloc")] #[cfg(feature = "jemalloc")]
#[test] #[test]
fn test_set_jemalloc_nodump_allocator_for_lru_cache() { fn test_set_jemalloc_nodump_allocator_for_lru_cache() {
let path = TempDir::new("_rust_rocksdb_set_jemalloc_nodump_allocator").expect(""); use rocksdb::MemoryAllocator;
let path = tempdir_with_prefix("_rust_rocksdb_set_jemalloc_nodump_allocator");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -336,7 +339,7 @@ fn test_set_jemalloc_nodump_allocator_for_lru_cache() { ...@@ -336,7 +339,7 @@ fn test_set_jemalloc_nodump_allocator_for_lru_cache() {
#[test] #[test]
fn test_set_cache_index_and_filter_blocks_with_high_priority() { fn test_set_cache_index_and_filter_blocks_with_high_priority() {
let path = TempDir::new("_rust_rocksdb_set_cache_and_index_with_high_priority").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_cache_and_index_with_high_priority");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -353,7 +356,7 @@ fn test_set_cache_index_and_filter_blocks_with_high_priority() { ...@@ -353,7 +356,7 @@ fn test_set_cache_index_and_filter_blocks_with_high_priority() {
#[test] #[test]
fn test_pending_compaction_bytes_limit() { fn test_pending_compaction_bytes_limit() {
let path = TempDir::new("_rust_rocksdb_pending_compaction_bytes_limit").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_pending_compaction_bytes_limit");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -369,7 +372,7 @@ fn test_pending_compaction_bytes_limit() { ...@@ -369,7 +372,7 @@ fn test_pending_compaction_bytes_limit() {
#[test] #[test]
fn test_set_max_subcompactions() { fn test_set_max_subcompactions() {
let path = TempDir::new("_rust_rocksdb_max_subcompactions").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_max_subcompactions");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_max_subcompactions(4); opts.set_max_subcompactions(4);
...@@ -378,7 +381,7 @@ fn test_set_max_subcompactions() { ...@@ -378,7 +381,7 @@ fn test_set_max_subcompactions() {
#[test] #[test]
fn test_set_bytes_per_sync() { fn test_set_bytes_per_sync() {
let path = TempDir::new("_rust_rocksdb_bytes_per_sync").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_bytes_per_sync");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_bytes_per_sync(1024 * 1024); opts.set_bytes_per_sync(1024 * 1024);
...@@ -388,7 +391,7 @@ fn test_set_bytes_per_sync() { ...@@ -388,7 +391,7 @@ fn test_set_bytes_per_sync() {
#[test] #[test]
fn test_set_optimize_filters_for_hits() { fn test_set_optimize_filters_for_hits() {
let path = TempDir::new("_rust_rocksdb_optimize_filters_for_hits").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_optimize_filters_for_hits");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -403,7 +406,7 @@ fn test_set_optimize_filters_for_hits() { ...@@ -403,7 +406,7 @@ fn test_set_optimize_filters_for_hits() {
#[test] #[test]
fn test_set_force_consistency_checks() { fn test_set_force_consistency_checks() {
let path = TempDir::new("_rust_rocksdb_force_consistency_checks").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_force_consistency_checks");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -418,7 +421,7 @@ fn test_set_force_consistency_checks() { ...@@ -418,7 +421,7 @@ fn test_set_force_consistency_checks() {
#[test] #[test]
fn test_get_block_cache_usage() { fn test_get_block_cache_usage() {
let path = TempDir::new("_rust_rocksdb_set_cache_and_index").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_cache_and_index");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
...@@ -450,7 +453,7 @@ fn test_get_block_cache_usage() { ...@@ -450,7 +453,7 @@ fn test_get_block_cache_usage() {
#[test] #[test]
fn test_block_cache_capacity() { fn test_block_cache_capacity() {
let path = TempDir::new("_rust_rocksdb_set_and_get_block_cache_capacity").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_and_get_block_cache_capacity");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
...@@ -493,7 +496,7 @@ fn test_disable_block_cache() { ...@@ -493,7 +496,7 @@ fn test_disable_block_cache() {
#[test] #[test]
fn test_set_level_compaction_dynamic_level_bytes() { fn test_set_level_compaction_dynamic_level_bytes() {
let path = TempDir::new("_rust_rocksdb_level_compaction_dynamic_level_bytes").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_level_compaction_dynamic_level_bytes");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -508,7 +511,7 @@ fn test_set_level_compaction_dynamic_level_bytes() { ...@@ -508,7 +511,7 @@ fn test_set_level_compaction_dynamic_level_bytes() {
#[test] #[test]
fn test_compact_options() { fn test_compact_options() {
let path = TempDir::new("_rust_rocksdb_compact_options").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_compact_options");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
db.put(b"k1", b"v1").unwrap(); db.put(b"k1", b"v1").unwrap();
db.put(b"k2", b"v2").unwrap(); db.put(b"k2", b"v2").unwrap();
...@@ -522,7 +525,7 @@ fn test_compact_options() { ...@@ -522,7 +525,7 @@ fn test_compact_options() {
#[test] #[test]
fn test_direct_read_write() { fn test_direct_read_write() {
let path = TempDir::new("_rust_rocksdb_direct_read_write").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_direct_read_write");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_use_direct_reads(true); opts.set_use_direct_reads(true);
...@@ -532,7 +535,7 @@ fn test_direct_read_write() { ...@@ -532,7 +535,7 @@ fn test_direct_read_write() {
#[test] #[test]
fn test_writable_file_max_buffer_size() { fn test_writable_file_max_buffer_size() {
let path = TempDir::new("_rust_rocksdb_writable_file_max_buffer_size").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_writable_file_max_buffer_size");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_writable_file_max_buffer_size(1024 * 1024); opts.set_writable_file_max_buffer_size(1024 * 1024);
...@@ -541,7 +544,7 @@ fn test_writable_file_max_buffer_size() { ...@@ -541,7 +544,7 @@ fn test_writable_file_max_buffer_size() {
#[test] #[test]
fn test_set_max_background_jobs() { fn test_set_max_background_jobs() {
let path = TempDir::new("_rust_rocksdb_max_background_jobs").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_max_background_jobs");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_max_background_jobs(4); opts.set_max_background_jobs(4);
...@@ -550,7 +553,7 @@ fn test_set_max_background_jobs() { ...@@ -550,7 +553,7 @@ fn test_set_max_background_jobs() {
#[test] #[test]
fn test_set_compaction_pri() { fn test_set_compaction_pri() {
let path = TempDir::new("_rust_rocksdb_compaction_pri").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_compaction_pri");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -565,7 +568,7 @@ fn test_set_compaction_pri() { ...@@ -565,7 +568,7 @@ fn test_set_compaction_pri() {
#[test] #[test]
fn test_allow_concurrent_memtable_write() { fn test_allow_concurrent_memtable_write() {
let path = TempDir::new("_rust_rocksdb_allow_concurrent_memtable_write").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_allow_concurrent_memtable_write");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.allow_concurrent_memtable_write(false); opts.allow_concurrent_memtable_write(false);
...@@ -577,7 +580,7 @@ fn test_allow_concurrent_memtable_write() { ...@@ -577,7 +580,7 @@ fn test_allow_concurrent_memtable_write() {
#[test] #[test]
fn test_manual_wal_flush() { fn test_manual_wal_flush() {
let path = TempDir::new("_rust_rocksdb_manual_wal_flush").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_manual_wal_flush");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.manual_wal_flush(true); opts.manual_wal_flush(true);
...@@ -589,7 +592,7 @@ fn test_manual_wal_flush() { ...@@ -589,7 +592,7 @@ fn test_manual_wal_flush() {
#[test] #[test]
fn test_enable_pipelined_write() { fn test_enable_pipelined_write() {
let path = TempDir::new("_rust_rocksdb_enable_pipelined_write").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_enable_pipelined_write");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.enable_pipelined_write(true); opts.enable_pipelined_write(true);
...@@ -626,7 +629,7 @@ fn test_get_compression_per_level() { ...@@ -626,7 +629,7 @@ fn test_get_compression_per_level() {
#[test] #[test]
fn test_bottommost_compression() { fn test_bottommost_compression() {
let path = TempDir::new("_rust_rocksdb_bottommost_compression").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_bottommost_compression");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let cf_opts = ColumnFamilyOptions::new(); let cf_opts = ColumnFamilyOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -649,17 +652,17 @@ fn test_clone_options() { ...@@ -649,17 +652,17 @@ fn test_clone_options() {
#[test] #[test]
fn test_db_paths() { fn test_db_paths() {
let path = TempDir::new("_rust_rocksdb_db_paths").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_db_paths");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
let tmp_path = TempDir::new("_rust_rocksdb_test_db_path").expect(""); let tmp_path = tempdir_with_prefix("_rust_rocksdb_test_db_path");
opts.set_db_paths(&[(tmp_path.path(), 1073741824 as u64)]); opts.set_db_paths(&[(tmp_path.path(), 1073741824 as u64)]);
DB::open(opts, path.path().to_str().unwrap()).unwrap(); DB::open(opts, path.path().to_str().unwrap()).unwrap();
} }
#[test] #[test]
fn test_write_options() { fn test_write_options() {
let path = TempDir::new("_rust_rocksdb_write_options").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_write_options");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
let mut write_opts = WriteOptions::new(); let mut write_opts = WriteOptions::new();
...@@ -680,7 +683,7 @@ fn test_write_options() { ...@@ -680,7 +683,7 @@ fn test_write_options() {
#[test] #[test]
fn test_read_options() { fn test_read_options() {
let path = TempDir::new("_rust_rocksdb_write_options").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_write_options");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
let mut read_opts = ReadOptions::new(); let mut read_opts = ReadOptions::new();
...@@ -712,7 +715,7 @@ fn test_read_options() { ...@@ -712,7 +715,7 @@ fn test_read_options() {
#[test] #[test]
fn test_readoptions_lower_bound() { fn test_readoptions_lower_bound() {
let path = TempDir::new("_rust_rocksdb_readoptions_lower_bound").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_readoptions_lower_bound");
let db = DB::open_default(path.path().to_str().unwrap()).unwrap(); let db = DB::open_default(path.path().to_str().unwrap()).unwrap();
db.put(b"k1", b"b").unwrap(); db.put(b"k1", b"b").unwrap();
...@@ -734,7 +737,7 @@ fn test_readoptions_lower_bound() { ...@@ -734,7 +737,7 @@ fn test_readoptions_lower_bound() {
#[test] #[test]
fn test_block_based_options() { fn test_block_based_options() {
let path = TempDir::new("_rust_rocksdb_block_based_options").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_block_based_options");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
...@@ -765,7 +768,7 @@ fn test_block_based_options() { ...@@ -765,7 +768,7 @@ fn test_block_based_options() {
#[test] #[test]
fn test_fifo_compaction_options() { fn test_fifo_compaction_options() {
let path = TempDir::new("_rust_rocksdb_fifo_compaction_options").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_fifo_compaction_options");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
...@@ -786,7 +789,7 @@ fn test_readoptions_max_bytes_for_level_multiplier() { ...@@ -786,7 +789,7 @@ fn test_readoptions_max_bytes_for_level_multiplier() {
#[test] #[test]
fn test_vector_memtable_factory_options() { fn test_vector_memtable_factory_options() {
let path = TempDir::new("_rust_rocksdb_vector_memtable_factory_options").unwrap(); let path = tempdir_with_prefix("_rust_rocksdb_vector_memtable_factory_options");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
...@@ -817,7 +820,7 @@ fn test_vector_memtable_factory_options() { ...@@ -817,7 +820,7 @@ fn test_vector_memtable_factory_options() {
#[test] #[test]
fn test_dboptions_set_env() { fn test_dboptions_set_env() {
let path = TempDir::new("_rust_rocksdb_dboptions_set_env").unwrap(); let path = tempdir_with_prefix("_rust_rocksdb_dboptions_set_env");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
use rocksdb::{ use rocksdb::{
BlockBasedOptions, ColumnFamilyOptions, DBOptions, SeekKey, SliceTransform, Writable, DB, BlockBasedOptions, ColumnFamilyOptions, DBOptions, SeekKey, SliceTransform, Writable, DB,
}; };
use tempdir::TempDir;
use super::tempdir_with_prefix;
struct FixedPostfixTransform { struct FixedPostfixTransform {
pub postfix_len: usize, pub postfix_len: usize,
...@@ -33,7 +34,7 @@ impl SliceTransform for FixedPostfixTransform { ...@@ -33,7 +34,7 @@ impl SliceTransform for FixedPostfixTransform {
#[test] #[test]
fn test_slice_transform() { fn test_slice_transform() {
let path = TempDir::new("_rust_rocksdb_slice_transform_test").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_slice_transform_test");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
let mut cf_opts = ColumnFamilyOptions::new(); let mut cf_opts = ColumnFamilyOptions::new();
......
...@@ -13,11 +13,12 @@ ...@@ -13,11 +13,12 @@
use rocksdb::*; use rocksdb::*;
use rocksdb::{DBStatisticsHistogramType as HistogramType, DBStatisticsTickerType as TickerType}; use rocksdb::{DBStatisticsHistogramType as HistogramType, DBStatisticsTickerType as TickerType};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test] #[test]
fn test_db_statistics() { fn test_db_statistics() {
let path = TempDir::new("_rust_rocksdb_statistics").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_statistics");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.enable_statistics(true); opts.enable_statistics(true);
...@@ -49,7 +50,7 @@ fn test_db_statistics() { ...@@ -49,7 +50,7 @@ fn test_db_statistics() {
#[test] #[test]
fn test_disable_db_statistics() { fn test_disable_db_statistics() {
let path = TempDir::new("_rust_rocksdb_statistics").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_statistics");
let mut opts = DBOptions::new(); let mut opts = DBOptions::new();
opts.create_if_missing(true); opts.create_if_missing(true);
opts.enable_statistics(false); opts.enable_statistics(false);
......
...@@ -11,15 +11,16 @@ ...@@ -11,15 +11,16 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use std::collections::HashMap;
use std::fmt;
use rocksdb::{ use rocksdb::{
ColumnFamilyOptions, DBEntryType, DBOptions, Range, ReadOptions, SeekKey, TableFilter, ColumnFamilyOptions, DBEntryType, DBOptions, Range, ReadOptions, SeekKey, TableFilter,
TableProperties, TablePropertiesCollection, TablePropertiesCollector, TableProperties, TablePropertiesCollection, TablePropertiesCollector,
TablePropertiesCollectorFactory, UserCollectedProperties, Writable, DB, TablePropertiesCollectorFactory, UserCollectedProperties, Writable, DB,
}; };
use std::collections::HashMap;
use std::fmt; use super::tempdir_with_prefix;
use tempdir::TempDir;
enum Props { enum Props {
NumKeys = 0, NumKeys = 0,
...@@ -29,13 +30,13 @@ enum Props { ...@@ -29,13 +30,13 @@ enum Props {
} }
fn encode_u32(x: u32) -> Vec<u8> { fn encode_u32(x: u32) -> Vec<u8> {
let mut w = Vec::new(); x.to_le_bytes().to_vec()
w.write_u32::<LittleEndian>(x).unwrap();
w
} }
fn decode_u32(mut x: &[u8]) -> u32 { fn decode_u32(x: &[u8]) -> u32 {
x.read_u32::<LittleEndian>().unwrap() let mut dst = [0u8; 4];
dst.copy_from_slice(&x[..4]);
u32::from_le_bytes(dst)
} }
struct ExampleCollector { struct ExampleCollector {
...@@ -169,7 +170,7 @@ fn test_table_properties_collector_factory() { ...@@ -169,7 +170,7 @@ fn test_table_properties_collector_factory() {
opts.create_if_missing(true); opts.create_if_missing(true);
cf_opts.add_table_properties_collector_factory("example-collector", Box::new(f)); cf_opts.add_table_properties_collector_factory("example-collector", Box::new(f));
let path = TempDir::new("_rust_rocksdb_collectortest").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_collectortest");
let db = DB::open_cf( let db = DB::open_cf(
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
...@@ -243,7 +244,7 @@ fn test_table_properties_with_table_filter() { ...@@ -243,7 +244,7 @@ fn test_table_properties_with_table_filter() {
opts.create_if_missing(true); opts.create_if_missing(true);
cf_opts.add_table_properties_collector_factory("example-collector", Box::new(f)); cf_opts.add_table_properties_collector_factory("example-collector", Box::new(f));
let path = TempDir::new("_rust_rocksdb_collector_with_table_filter").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_collector_with_table_filter");
let db = DB::open_cf( let db = DB::open_cf(
opts, opts,
path.path().to_str().unwrap(), path.path().to_str().unwrap(),
......
...@@ -14,9 +14,6 @@ ...@@ -14,9 +14,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::ops; use std::ops;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use tempdir::TempDir;
use rand::Rng; use rand::Rng;
use rocksdb::{ use rocksdb::{
CFHandle, ColumnFamilyOptions, CompactOptions, DBBottommostLevelCompaction, DBCompressionType, CFHandle, ColumnFamilyOptions, CompactOptions, DBBottommostLevelCompaction, DBCompressionType,
...@@ -25,14 +22,16 @@ use rocksdb::{ ...@@ -25,14 +22,16 @@ use rocksdb::{
Writable, DB, Writable, DB,
}; };
use super::tempdir_with_prefix;
fn encode_u32(x: u32) -> Vec<u8> { fn encode_u32(x: u32) -> Vec<u8> {
let mut w = Vec::new(); x.to_le_bytes().to_vec()
w.write_u32::<LittleEndian>(x).unwrap();
w
} }
fn decode_u32(mut x: &[u8]) -> u32 { fn decode_u32(x: &[u8]) -> u32 {
x.read_u32::<LittleEndian>().unwrap() let mut dst = [0u8; 4];
dst.copy_from_slice(&x[..4]);
u32::from_le_bytes(dst)
} }
#[derive(Default)] #[derive(Default)]
...@@ -103,7 +102,7 @@ fn check_table_properties(db: &DB, num_blobs: u32, num_entries: u32) { ...@@ -103,7 +102,7 @@ fn check_table_properties(db: &DB, num_blobs: u32, num_entries: u32) {
fn test_titandb() { fn test_titandb() {
let max_value_size = 10; let max_value_size = 10;
let path = TempDir::new("test_titandb").unwrap(); let path = tempdir_with_prefix("test_titandb");
let tdb_path = path.path().join("titandb"); let tdb_path = path.path().join("titandb");
let mut tdb_opts = TitanDBOptions::new(); let mut tdb_opts = TitanDBOptions::new();
tdb_opts.set_dirname(tdb_path.to_str().unwrap()); tdb_opts.set_dirname(tdb_path.to_str().unwrap());
...@@ -229,7 +228,7 @@ fn generate_file_bottom_level(db: &DB, handle: &CFHandle, range: ops::Range<u32> ...@@ -229,7 +228,7 @@ fn generate_file_bottom_level(db: &DB, handle: &CFHandle, range: ops::Range<u32>
#[test] #[test]
fn test_titan_delete_files_in_ranges() { fn test_titan_delete_files_in_ranges() {
let path = TempDir::new("_rust_rocksdb_test_titan_delete_files_in_multi_ranges").unwrap(); let path = tempdir_with_prefix("_rust_rocksdb_test_titan_delete_files_in_multi_ranges");
let tdb_path = path.path().join("titandb"); let tdb_path = path.path().join("titandb");
let mut tdb_opts = TitanDBOptions::new(); let mut tdb_opts = TitanDBOptions::new();
tdb_opts.set_dirname(tdb_path.to_str().unwrap()); tdb_opts.set_dirname(tdb_path.to_str().unwrap());
...@@ -290,7 +289,7 @@ fn test_titan_delete_files_in_ranges() { ...@@ -290,7 +289,7 @@ fn test_titan_delete_files_in_ranges() {
#[test] #[test]
fn test_get_blob_cache_usage() { fn test_get_blob_cache_usage() {
let path = TempDir::new("_rust_rocksdb_set_blob_cache").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_blob_cache");
let tdb_path = path.path().join("titandb"); let tdb_path = path.path().join("titandb");
let mut tdb_opts = TitanDBOptions::new(); let mut tdb_opts = TitanDBOptions::new();
tdb_opts.set_dirname(tdb_path.to_str().unwrap()); tdb_opts.set_dirname(tdb_path.to_str().unwrap());
...@@ -324,7 +323,7 @@ fn test_get_blob_cache_usage() { ...@@ -324,7 +323,7 @@ fn test_get_blob_cache_usage() {
#[test] #[test]
fn test_blob_cache_capacity() { fn test_blob_cache_capacity() {
let path = TempDir::new("_rust_rocksdb_set_and_get_blob_cache_capacity").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_set_and_get_blob_cache_capacity");
let tdb_path = path.path().join("titandb"); let tdb_path = path.path().join("titandb");
let mut tdb_opts = TitanDBOptions::new(); let mut tdb_opts = TitanDBOptions::new();
tdb_opts.set_dirname(tdb_path.to_str().unwrap()); tdb_opts.set_dirname(tdb_path.to_str().unwrap());
......
use rocksdb::{ColumnFamilyOptions, DBOptions, Writable, DB}; use rocksdb::{ColumnFamilyOptions, DBOptions, Writable, DB};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test] #[test]
pub fn test_ttl() { pub fn test_ttl() {
let path = TempDir::new("_rust_rocksdb_ttl_test").expect(""); let path = tempdir_with_prefix("_rust_rocksdb_ttl_test");
let path_str = path.path().to_str().unwrap(); let path_str = path.path().to_str().unwrap();
// should be able to open db with ttl // should be able to open db with ttl
......
extern crate byteorder;
extern crate crc; extern crate crc;
extern crate rand; extern crate rand;
extern crate rocksdb; extern crate rocksdb;
extern crate tempdir; extern crate tempfile;
mod cases; mod cases;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment