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 = []
[dependencies]
libc = "0.2.11"
crc = "1.2"
[dependencies.librocksdb_sys]
path = "librocksdb_sys"
[dev-dependencies]
byteorder = "1.0.0"
rand = "0.3"
tempdir = "0.3"
rand = "0.7"
crc = "1.8"
tempfile = "3.1"
......@@ -12,12 +12,10 @@
// limitations under the License.
use super::rocksdb::{ColumnFamilyOptions, DBOptions, WriteOptions, DB};
use super::tempdir::TempDir;
use super::test::Bencher;
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();
opts.create_if_missing(true);
opts.set_max_background_jobs(6);
......
extern crate test;
extern crate byteorder;
extern crate crc;
extern crate rand;
extern crate rocksdb;
extern crate tempdir;
extern crate tempfile;
mod bench_wal;
......@@ -10,7 +10,7 @@ libc = "0.2.11"
libtitan_sys = { path = "libtitan_sys" }
[dev-dependencies]
tempdir = "0.3"
tempfile = "3.1"
[features]
default = []
......
......@@ -16,12 +16,13 @@
extern crate bzip2_sys;
extern crate libc;
#[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::fmt;
use libc::{c_char, c_double, c_int, c_uchar, c_void, size_t};
// FFI-safe opaque types.
//
// These represent opaque RocksDB types. They are used behind pointers, but are
......@@ -2118,7 +2119,10 @@ mod test {
use libc::{self, c_void};
use std::ffi::{CStr, CString};
use std::{fs, ptr, slice};
use tempdir::TempDir;
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {
tempfile::Builder::new().prefix(prefix).tempdir().expect()
}
#[test]
fn internal() {
......@@ -2129,8 +2133,7 @@ mod test {
crocksdb_options_increase_parallelism(opts, 0);
crocksdb_options_optimize_level_style_compaction(opts, 0);
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_ptr = cpath.as_ptr();
......@@ -2236,7 +2239,7 @@ mod test {
let opts = crocksdb_options_create();
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_ptr = cpath.as_ptr();
......@@ -2248,7 +2251,7 @@ mod test {
let io_options = crocksdb_options_create();
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 c_sst_path = CString::new(sst_path.to_str().unwrap()).unwrap();
let c_sst_path_ptr = c_sst_path.as_ptr();
......
......@@ -18,7 +18,7 @@ extern crate libc;
#[macro_use]
pub extern crate librocksdb_sys;
#[cfg(test)]
extern crate tempdir;
extern crate tempfile;
pub use compaction_filter::CompactionFilter;
pub use event_listener::{
......@@ -68,3 +68,8 @@ mod table_properties;
mod table_properties_collector;
mod table_properties_collector_factory;
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 {
#[cfg(test)]
mod test {
use super::*;
use rocksdb::{DBVector, Writable, DB};
use rocksdb_options::{ColumnFamilyOptions, DBOptions};
use tempdir::TempDir;
use super::*;
use crate::tempdir_with_prefix;
#[allow(unused_variables)]
#[allow(dead_code)]
......@@ -175,7 +176,7 @@ mod test {
#[allow(dead_code)]
#[test]
fn mergetest() {
let path = TempDir::new("_rust_rocksdb_mergetest").expect("");
let path = tempdir_with_prefix("_rust_rocksdb_mergetest");
let mut opts = DBOptions::new();
opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new();
......
......@@ -396,16 +396,15 @@ impl IOStatsContext {
#[cfg(test)]
mod test {
use super::*;
use tempdir::TempDir;
use rocksdb::{SeekKey, Writable, DB};
use rocksdb_options::{DBOptions, WriteOptions};
use super::*;
use crate::tempdir_with_prefix;
#[test]
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();
opts.create_if_missing(true);
let db = DB::open(opts, temp_dir.path().to_str().unwrap()).unwrap();
......@@ -451,7 +450,7 @@ mod test {
#[test]
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();
opts.create_if_missing(true);
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) {
#[cfg(test)]
mod test {
use super::*;
use std::fs;
use std::path::Path;
use std::str;
use std::string::String;
use std::thread;
use tempdir::TempDir;
use super::*;
use crate::tempdir_with_prefix;
#[test]
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 p = db.put(b"k1", b"v1111");
assert!(p.is_ok());
......@@ -2670,7 +2671,7 @@ mod test {
#[allow(unused_variables)]
#[test]
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 db = DB::open_default(path_str).unwrap();
let opts = DBOptions::new();
......@@ -2689,7 +2690,7 @@ mod test {
#[test]
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();
// test put
......@@ -2760,7 +2761,7 @@ mod test {
#[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();
db.put(b"k1", b"v1111").expect("");
......@@ -2779,7 +2780,7 @@ mod test {
#[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();
for i in 1..8000 {
db.put(
......@@ -2807,7 +2808,7 @@ mod test {
#[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();
db.put(b"a1", b"v1").unwrap();
db.flush(true).unwrap();
......@@ -2822,7 +2823,7 @@ mod test {
#[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_opts = vec![];
......@@ -2853,13 +2854,13 @@ mod test {
let key = b"foo";
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 p = db.put(key, value);
assert!(p.is_ok());
// 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();
// Restore it.
......@@ -2868,7 +2869,7 @@ mod test {
ropt2.set_keep_log_files(true);
let ropts = [ropt1, ropt2];
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(
&backup_engine,
restore_dir.path().to_str().unwrap(),
......@@ -2884,7 +2885,7 @@ mod test {
#[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 log_path = format!("{}", Path::new(&db_path).join("log_path").display());
fs::create_dir_all(&log_path).unwrap();
......@@ -2910,7 +2911,7 @@ mod test {
#[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();
db.put(b"a", b"v1").unwrap();
......@@ -2945,7 +2946,7 @@ mod test {
#[test]
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 = Arc::new(db);
let db1 = db.clone();
......@@ -3000,7 +3001,7 @@ mod test {
#[test]
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();
for i in 0..200 {
......@@ -3018,7 +3019,7 @@ mod test {
#[test]
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();
opts.create_if_missing(true);
let mut db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
......@@ -3058,7 +3059,7 @@ mod test {
fn test_get_all_key_versions() {
let mut opts = DBOptions::new();
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 samples = vec![
......@@ -3084,7 +3085,7 @@ mod test {
fn test_get_approximate_memtable_stats() {
let mut opts = DBOptions::new();
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 samples = [
......@@ -3114,7 +3115,7 @@ mod test {
fn test_set_options() {
let mut opts = DBOptions::new();
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 cf = db.cf_handle("default").unwrap();
......@@ -3135,7 +3136,7 @@ mod test {
#[test]
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 cf_name: &str = "cf_dynamic_level_bytes";
......@@ -3170,7 +3171,7 @@ mod test {
#[test]
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();
opts.create_if_missing(true);
......@@ -3188,7 +3189,7 @@ mod test {
#[test]
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 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_compact_range;
mod test_compaction_filter;
......@@ -25,3 +19,7 @@ mod test_statistics;
mod test_table_properties;
mod test_titan;
mod test_ttl;
fn tempdir_with_prefix(prefix: &str) -> tempfile::TempDir {
tempfile::Builder::new().prefix(prefix).tempdir().expect("")
}
......@@ -14,11 +14,12 @@
//
use rocksdb::{ColumnFamilyOptions, DBOptions, MergeOperands, Writable, DB};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test]
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();
// should be able to create column families
......
......@@ -15,11 +15,12 @@ use rocksdb::{
ColumnFamilyOptions, CompactOptions, DBBottommostLevelCompaction, DBOptions, Range, Writable,
DB,
};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test]
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();
opts.create_if_missing(true);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
......@@ -50,7 +51,7 @@ fn test_compact_range() {
#[test]
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();
opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new();
......@@ -85,7 +86,7 @@ fn test_compact_range_change_level() {
#[test]
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();
opts.create_if_missing(true);
......
......@@ -11,10 +11,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rocksdb::{ColumnFamilyOptions, CompactionFilter, DBOptions, Writable, DB};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock};
use tempdir::TempDir;
use rocksdb::{ColumnFamilyOptions, CompactionFilter, DBOptions, Writable, DB};
use super::tempdir_with_prefix;
struct Filter {
drop_called: Arc<AtomicBool>,
......@@ -39,7 +41,7 @@ impl Drop for Filter {
#[test]
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 drop_called = Arc::new(AtomicBool::new(false));
let filtered_kvs = Arc::new(RwLock::new(vec![]));
......
......@@ -12,12 +12,13 @@
// limitations under the License.
use rocksdb::{ColumnFamilyOptions, DBCompressionType, DBOptions, DB};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test]
// Make sure all compression types are supported.
fn test_compression() {
let path = TempDir::new("_rust_rocksdb_test_metadata").unwrap();
let path = tempdir_with_prefix("_rust_rocksdb_test_metadata");
let compression_types = [
DBCompressionType::Snappy,
DBCompressionType::Zlib,
......
......@@ -13,9 +13,10 @@
use std::ops;
use rand::{self, Rng};
use rand::{self, RngCore};
use rocksdb::*;
use tempdir::TempDir;
use super::tempdir_with_prefix;
fn initial_data(path: &str) -> DB {
let mut opts = DBOptions::new();
......@@ -54,7 +55,7 @@ fn generate_file_bottom_level(db: &DB, handle: &CFHandle, range: ops::Range<u32>
#[test]
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 db = initial_data(path_str);
......@@ -77,7 +78,7 @@ fn test_delete_files_in_range_with_iter() {
#[test]
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 db = initial_data(path_str);
......@@ -103,7 +104,7 @@ fn test_delete_files_in_range_with_snap() {
#[test]
fn test_delete_files_in_range_with_delete_range() {
// 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 sst_size = 1 << 10;
......@@ -168,7 +169,7 @@ fn test_delete_files_in_range_with_delete_range() {
#[test]
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 db = initial_data(path_str);
......
This diff is collapsed.
......@@ -11,10 +11,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rocksdb::Env;
use rocksdb::{DBOptions, Writable, DB};
use std::sync::Arc;
use tempdir::TempDir;
use rocksdb::{DBOptions, Env, Writable, DB};
use super::tempdir_with_prefix;
#[test]
fn test_ctr_encrypted_env() {
......@@ -36,7 +37,7 @@ fn test_ctr_encrypted_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 mut opts = DBOptions::new();
......
......@@ -11,11 +11,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use cases::test_ingest_external_file::gen_sst;
use rocksdb::*;
use std::sync::atomic::*;
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)]
struct EventCounter {
......@@ -134,7 +136,7 @@ impl EventListener for BackgroundErrorCounter {
#[test]
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 mut opts = DBOptions::new();
......@@ -179,7 +181,7 @@ fn test_event_listener_stall_conditions_changed() {
#[test]
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 mut opts = DBOptions::new();
......@@ -225,7 +227,7 @@ fn test_event_listener_basic() {
#[test]
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 mut opts = DBOptions::new();
......@@ -234,7 +236,7 @@ fn test_event_listener_ingestion() {
opts.create_if_missing(true);
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_str = test_sstfile.to_str().unwrap();
......@@ -259,7 +261,7 @@ fn test_event_listener_ingestion() {
fn test_event_listener_background_error() {
// TODO(yiwu): should create a test Env object which inject some IO error, to
// 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 mut opts = DBOptions::new();
......
......@@ -11,11 +11,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rocksdb::*;
use std::fs;
use std::io::{Read, Write};
use std::sync::Arc;
use tempdir::TempDir;
use rocksdb::*;
use super::tempdir_with_prefix;
pub fn gen_sst(
opt: ColumnFamilyOptions,
......@@ -99,11 +101,11 @@ fn concat_merge(_: &[u8], existing_val: Option<&[u8]>, operands: &mut MergeOpera
#[test]
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);
db.create_cf("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_str = test_sstfile.to_str().unwrap();
let default_options = db.get_options();
......@@ -153,14 +155,14 @@ fn test_ingest_external_file() {
#[test]
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 mut opts = DBOptions::new();
opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new();
cf_opts.add_merge_operator("merge operator", concat_merge);
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_str = test_sstfile.to_str().unwrap();
let default_options = db.get_options();
......@@ -213,9 +215,9 @@ fn test_ingest_external_file_new() {
#[test]
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 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_str = test_sstfile.to_str().unwrap();
let mut cf_opts = ColumnFamilyOptions::new();
......@@ -296,7 +298,7 @@ fn gen_sst_from_cf(opt: ColumnFamilyOptions, db: &DB, cf: &CFHandle, path: &str)
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 mut opts = DBOptions::new();
opts.create_if_missing(true);
......@@ -314,9 +316,9 @@ fn create_cfs(db: &mut DB, cfs: &[&str]) {
#[test]
fn test_ingest_simulate_real_world() {
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 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);
for cf in &ALL_CFS {
let handle = db.cf_handle(cf).unwrap();
......@@ -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);
for cf in &ALL_CFS {
if *cf != "default" {
......@@ -389,7 +391,7 @@ fn test_ingest_simulate_real_world() {
#[test]
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 env = Arc::new(Env::new_mem());
......@@ -440,9 +442,9 @@ fn test_mem_sst_file_writer() {
#[test]
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 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 sstfile_str = file.to_str().unwrap();
gen_sst(
......@@ -471,9 +473,9 @@ fn test_set_external_sst_file_global_seq_no() {
#[test]
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 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_str = test_sstfile.to_str().unwrap();
let handle = db.cf_handle("default").unwrap();
......@@ -508,7 +510,7 @@ fn test_ingest_external_file_optimized() {
#[test]
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_str = sst_path.to_str().unwrap();
gen_sst_put(ColumnFamilyOptions::new(), None, sst_path_str);
......@@ -533,7 +535,7 @@ fn test_read_sst() {
#[test]
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_str = sst_path.to_str().unwrap();
gen_sst_put(ColumnFamilyOptions::new(), None, sst_path_str);
......
......@@ -11,12 +11,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rocksdb::rocksdb::Snapshot;
use rocksdb::*;
use std::ops::Deref;
use std::sync::*;
use std::thread;
use tempdir::TempDir;
use rocksdb::rocksdb::Snapshot;
use rocksdb::*;
use super::tempdir_with_prefix;
struct FixedPrefixTransform {
pub prefix_len: usize,
......@@ -66,7 +68,7 @@ fn next_collect<D: Deref<Target = DB>>(iter: &mut DBIterator<D>) -> Vec<Kv> {
#[test]
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 k2 = b"k2";
......@@ -176,7 +178,7 @@ pub fn test_iterator() {
#[test]
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());
db.put(b"k1", b"v1").unwrap();
......@@ -219,7 +221,7 @@ fn test_send_iterator() {
#[test]
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();
opts.create_if_missing(true);
{
......@@ -267,7 +269,7 @@ fn test_seek_for_prev() {
#[test]
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();
opts.create_if_missing(true);
{
......@@ -290,7 +292,7 @@ fn read_with_upper_bound() {
#[test]
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();
bbto.set_bloom_filter(10, false);
bbto.set_whole_key_filtering(false);
......@@ -378,7 +380,7 @@ fn test_total_order_seek() {
#[test]
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();
bbto.set_bloom_filter(10, false);
bbto.set_whole_key_filtering(false);
......
......@@ -14,11 +14,12 @@
use rocksdb::{
CFHandle, ColumnFamilyOptions, CompactionOptions, DBCompressionType, DBOptions, Writable, DB,
};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test]
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();
opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new();
......@@ -72,7 +73,7 @@ fn get_files_cf(db: &DB, cf: &CFHandle, max_level: usize) -> Vec<String> {
#[test]
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();
opts.create_if_missing(true);
let mut cf_opts = ColumnFamilyOptions::new();
......
......@@ -11,16 +11,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rocksdb::{Writable, DB};
use std::sync::Arc;
use std::thread;
use tempdir::TempDir;
use rocksdb::{Writable, DB};
use super::tempdir_with_prefix;
const N: usize = 100_000;
#[test]
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 = Arc::new(db);
......
......@@ -12,7 +12,8 @@
// limitations under the License.
use rocksdb::*;
use tempdir::TempDir;
use super::tempdir_with_prefix;
struct FixedPrefixTransform {
pub prefix_len: usize,
......@@ -30,7 +31,7 @@ impl SliceTransform for FixedPrefixTransform {
#[test]
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![
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 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rocksdb::RateLimiter;
use std::thread;
use rocksdb::RateLimiter;
#[test]
fn test_rate_limiter() {
let rate_limiter = RateLimiter::new(10 * 1024 * 1024, 100 * 1000, 10);
......
use rocksdb::{DBOptions, Writable, DB};
use tempdir::TempDir;
use super::tempdir_with_prefix;
macro_rules! check_kv {
($db:expr, $key:expr, $val:expr) => {
......@@ -12,7 +13,7 @@ macro_rules! check_kv {
#[test]
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 mut opts = DBOptions::new();
opts.create_if_missing(true);
......@@ -48,7 +49,7 @@ fn test_open_for_read_only() {
#[test]
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();
{
......
This diff is collapsed.
......@@ -14,7 +14,8 @@
use rocksdb::{
BlockBasedOptions, ColumnFamilyOptions, DBOptions, SeekKey, SliceTransform, Writable, DB,
};
use tempdir::TempDir;
use super::tempdir_with_prefix;
struct FixedPostfixTransform {
pub postfix_len: usize,
......@@ -33,7 +34,7 @@ impl SliceTransform for FixedPostfixTransform {
#[test]
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 cf_opts = ColumnFamilyOptions::new();
......
......@@ -13,11 +13,12 @@
use rocksdb::*;
use rocksdb::{DBStatisticsHistogramType as HistogramType, DBStatisticsTickerType as TickerType};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test]
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();
opts.create_if_missing(true);
opts.enable_statistics(true);
......@@ -49,7 +50,7 @@ fn test_db_statistics() {
#[test]
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();
opts.create_if_missing(true);
opts.enable_statistics(false);
......
......@@ -11,15 +11,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::collections::HashMap;
use std::fmt;
use rocksdb::{
ColumnFamilyOptions, DBEntryType, DBOptions, Range, ReadOptions, SeekKey, TableFilter,
TableProperties, TablePropertiesCollection, TablePropertiesCollector,
TablePropertiesCollectorFactory, UserCollectedProperties, Writable, DB,
};
use std::collections::HashMap;
use std::fmt;
use tempdir::TempDir;
use super::tempdir_with_prefix;
enum Props {
NumKeys = 0,
......@@ -29,13 +30,13 @@ enum Props {
}
fn encode_u32(x: u32) -> Vec<u8> {
let mut w = Vec::new();
w.write_u32::<LittleEndian>(x).unwrap();
w
x.to_le_bytes().to_vec()
}
fn decode_u32(mut x: &[u8]) -> u32 {
x.read_u32::<LittleEndian>().unwrap()
fn decode_u32(x: &[u8]) -> u32 {
let mut dst = [0u8; 4];
dst.copy_from_slice(&x[..4]);
u32::from_le_bytes(dst)
}
struct ExampleCollector {
......@@ -169,7 +170,7 @@ fn test_table_properties_collector_factory() {
opts.create_if_missing(true);
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(
opts,
path.path().to_str().unwrap(),
......@@ -243,7 +244,7 @@ fn test_table_properties_with_table_filter() {
opts.create_if_missing(true);
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(
opts,
path.path().to_str().unwrap(),
......
......@@ -14,9 +14,6 @@
use std::collections::HashMap;
use std::ops;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use tempdir::TempDir;
use rand::Rng;
use rocksdb::{
CFHandle, ColumnFamilyOptions, CompactOptions, DBBottommostLevelCompaction, DBCompressionType,
......@@ -25,14 +22,16 @@ use rocksdb::{
Writable, DB,
};
use super::tempdir_with_prefix;
fn encode_u32(x: u32) -> Vec<u8> {
let mut w = Vec::new();
w.write_u32::<LittleEndian>(x).unwrap();
w
x.to_le_bytes().to_vec()
}
fn decode_u32(mut x: &[u8]) -> u32 {
x.read_u32::<LittleEndian>().unwrap()
fn decode_u32(x: &[u8]) -> u32 {
let mut dst = [0u8; 4];
dst.copy_from_slice(&x[..4]);
u32::from_le_bytes(dst)
}
#[derive(Default)]
......@@ -103,7 +102,7 @@ fn check_table_properties(db: &DB, num_blobs: u32, num_entries: u32) {
fn test_titandb() {
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 mut tdb_opts = TitanDBOptions::new();
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>
#[test]
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 mut tdb_opts = TitanDBOptions::new();
tdb_opts.set_dirname(tdb_path.to_str().unwrap());
......@@ -290,7 +289,7 @@ fn test_titan_delete_files_in_ranges() {
#[test]
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 mut tdb_opts = TitanDBOptions::new();
tdb_opts.set_dirname(tdb_path.to_str().unwrap());
......@@ -324,7 +323,7 @@ fn test_get_blob_cache_usage() {
#[test]
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 mut tdb_opts = TitanDBOptions::new();
tdb_opts.set_dirname(tdb_path.to_str().unwrap());
......
use rocksdb::{ColumnFamilyOptions, DBOptions, Writable, DB};
use tempdir::TempDir;
use super::tempdir_with_prefix;
#[test]
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();
// should be able to open db with ttl
......
extern crate byteorder;
extern crate crc;
extern crate rand;
extern crate rocksdb;
extern crate tempdir;
extern crate tempfile;
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