|
|
@ -16,18 +16,18 @@ extern crate rocksdb; |
|
|
|
mod util; |
|
|
|
mod util; |
|
|
|
|
|
|
|
|
|
|
|
use rocksdb::{DB, MergeOperands, Options, ColumnFamilyDescriptor}; |
|
|
|
use rocksdb::{DB, MergeOperands, Options, ColumnFamilyDescriptor}; |
|
|
|
use util::DBName; |
|
|
|
use util::DBPath; |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
pub fn test_column_family() { |
|
|
|
pub fn test_column_family() { |
|
|
|
let n = DBName::new("_rust_rocksdb_cftest"); |
|
|
|
let n = DBPath::new("_rust_rocksdb_cftest"); |
|
|
|
|
|
|
|
|
|
|
|
// should be able to create column families
|
|
|
|
// should be able to create column families
|
|
|
|
{ |
|
|
|
{ |
|
|
|
let mut opts = Options::default(); |
|
|
|
let mut opts = Options::default(); |
|
|
|
opts.create_if_missing(true); |
|
|
|
opts.create_if_missing(true); |
|
|
|
opts.set_merge_operator("test operator", test_provided_merge, None); |
|
|
|
opts.set_merge_operator("test operator", test_provided_merge, None); |
|
|
|
let mut db = DB::open(&opts, &n.name).unwrap(); |
|
|
|
let mut db = DB::open(&opts, &n).unwrap(); |
|
|
|
let opts = Options::default(); |
|
|
|
let opts = Options::default(); |
|
|
|
match db.create_cf("cf1", &opts) { |
|
|
|
match db.create_cf("cf1", &opts) { |
|
|
|
Ok(_db) => println!("cf1 created successfully"), |
|
|
|
Ok(_db) => println!("cf1 created successfully"), |
|
|
@ -41,7 +41,7 @@ pub fn test_column_family() { |
|
|
|
{ |
|
|
|
{ |
|
|
|
let mut opts = Options::default(); |
|
|
|
let mut opts = Options::default(); |
|
|
|
opts.set_merge_operator("test operator", test_provided_merge, None); |
|
|
|
opts.set_merge_operator("test operator", test_provided_merge, None); |
|
|
|
match DB::open(&opts, &n.name) { |
|
|
|
match DB::open(&opts, &n) { |
|
|
|
Ok(_db) => { |
|
|
|
Ok(_db) => { |
|
|
|
panic!("should not have opened DB successfully without \ |
|
|
|
panic!("should not have opened DB successfully without \ |
|
|
|
specifying column |
|
|
|
specifying column |
|
|
@ -59,7 +59,7 @@ pub fn test_column_family() { |
|
|
|
{ |
|
|
|
{ |
|
|
|
let mut opts = Options::default(); |
|
|
|
let mut opts = Options::default(); |
|
|
|
opts.set_merge_operator("test operator", test_provided_merge, None); |
|
|
|
opts.set_merge_operator("test operator", test_provided_merge, None); |
|
|
|
match DB::open_cf(&opts, &n.name, &["cf1"]) { |
|
|
|
match DB::open_cf(&opts, &n, &["cf1"]) { |
|
|
|
Ok(_db) => println!("successfully opened db with column family"), |
|
|
|
Ok(_db) => println!("successfully opened db with column family"), |
|
|
|
Err(e) => panic!("failed to open db with column family: {}", e), |
|
|
|
Err(e) => panic!("failed to open db with column family: {}", e), |
|
|
|
} |
|
|
|
} |
|
|
@ -68,7 +68,7 @@ pub fn test_column_family() { |
|
|
|
// should be able to list a cf
|
|
|
|
// should be able to list a cf
|
|
|
|
{ |
|
|
|
{ |
|
|
|
let opts = Options::default(); |
|
|
|
let opts = Options::default(); |
|
|
|
let vec = DB::list_cf(&opts, &n.name); |
|
|
|
let vec = DB::list_cf(&opts, &n); |
|
|
|
match vec { |
|
|
|
match vec { |
|
|
|
Ok(vec) => assert_eq!(vec, vec!["default", "cf1"]), |
|
|
|
Ok(vec) => assert_eq!(vec, vec!["default", "cf1"]), |
|
|
|
Err(e) => panic!("failed to drop column family: {}", e), |
|
|
|
Err(e) => panic!("failed to drop column family: {}", e), |
|
|
@ -83,7 +83,7 @@ pub fn test_column_family() { |
|
|
|
} |
|
|
|
} |
|
|
|
// should b able to drop a cf
|
|
|
|
// should b able to drop a cf
|
|
|
|
{ |
|
|
|
{ |
|
|
|
let mut db = DB::open_cf(&Options::default(), &n.name, &["cf1"]).unwrap(); |
|
|
|
let mut db = DB::open_cf(&Options::default(), &n, &["cf1"]).unwrap(); |
|
|
|
match db.drop_cf("cf1") { |
|
|
|
match db.drop_cf("cf1") { |
|
|
|
Ok(_) => println!("cf1 successfully dropped."), |
|
|
|
Ok(_) => println!("cf1 successfully dropped."), |
|
|
|
Err(e) => panic!("failed to drop column family: {}", e), |
|
|
|
Err(e) => panic!("failed to drop column family: {}", e), |
|
|
@ -93,7 +93,7 @@ pub fn test_column_family() { |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_create_missing_column_family() { |
|
|
|
fn test_create_missing_column_family() { |
|
|
|
let n = DBName::new("_rust_rocksdb_missing_cftest"); |
|
|
|
let n = DBPath::new("_rust_rocksdb_missing_cftest"); |
|
|
|
|
|
|
|
|
|
|
|
// should be able to create new column families when opening a new database
|
|
|
|
// should be able to create new column families when opening a new database
|
|
|
|
{ |
|
|
|
{ |
|
|
@ -101,7 +101,7 @@ fn test_create_missing_column_family() { |
|
|
|
opts.create_if_missing(true); |
|
|
|
opts.create_if_missing(true); |
|
|
|
opts.create_missing_column_families(true); |
|
|
|
opts.create_missing_column_families(true); |
|
|
|
|
|
|
|
|
|
|
|
match DB::open_cf(&opts, &n.name, &["cf1"]) { |
|
|
|
match DB::open_cf(&opts, &n, &["cf1"]) { |
|
|
|
Ok(_db) => println!("successfully created new column family"), |
|
|
|
Ok(_db) => println!("successfully created new column family"), |
|
|
|
Err(e) => panic!("failed to create new column family: {}", e), |
|
|
|
Err(e) => panic!("failed to create new column family: {}", e), |
|
|
|
} |
|
|
|
} |
|
|
@ -111,12 +111,12 @@ fn test_create_missing_column_family() { |
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
#[ignore] |
|
|
|
#[ignore] |
|
|
|
fn test_merge_operator() { |
|
|
|
fn test_merge_operator() { |
|
|
|
let n = DBName::new("_rust_rocksdb_cftest_merge"); |
|
|
|
let n = DBPath::new("_rust_rocksdb_cftest_merge"); |
|
|
|
// TODO should be able to write, read, merge, batch, and iterate over a cf
|
|
|
|
// TODO should be able to write, read, merge, batch, and iterate over a cf
|
|
|
|
{ |
|
|
|
{ |
|
|
|
let mut opts = Options::default(); |
|
|
|
let mut opts = Options::default(); |
|
|
|
opts.set_merge_operator("test operator", test_provided_merge, None); |
|
|
|
opts.set_merge_operator("test operator", test_provided_merge, None); |
|
|
|
let db = match DB::open_cf(&opts, &n.name, &["cf1"]) { |
|
|
|
let db = match DB::open_cf(&opts, &n, &["cf1"]) { |
|
|
|
Ok(db) => { |
|
|
|
Ok(db) => { |
|
|
|
println!("successfully opened db with column family"); |
|
|
|
println!("successfully opened db with column family"); |
|
|
|
db |
|
|
|
db |
|
|
@ -178,7 +178,7 @@ fn test_provided_merge(_: &[u8], |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
pub fn test_column_family_with_options() { |
|
|
|
pub fn test_column_family_with_options() { |
|
|
|
let n = DBName::new("_rust_rocksdb_cf_with_optionstest"); |
|
|
|
let n = DBPath::new("_rust_rocksdb_cf_with_optionstest"); |
|
|
|
{ |
|
|
|
{ |
|
|
|
let mut cfopts = Options::default(); |
|
|
|
let mut cfopts = Options::default(); |
|
|
|
cfopts.set_max_write_buffer_number(16); |
|
|
|
cfopts.set_max_write_buffer_number(16); |
|
|
@ -189,7 +189,7 @@ pub fn test_column_family_with_options() { |
|
|
|
opts.create_missing_column_families(true); |
|
|
|
opts.create_missing_column_families(true); |
|
|
|
|
|
|
|
|
|
|
|
let cfs = vec![cf_descriptor]; |
|
|
|
let cfs = vec![cf_descriptor]; |
|
|
|
match DB::open_cf_descriptors(&opts, &n.name, cfs) { |
|
|
|
match DB::open_cf_descriptors(&opts, &n, cfs) { |
|
|
|
Ok(_db) => println!("created db with column family descriptors succesfully"), |
|
|
|
Ok(_db) => println!("created db with column family descriptors succesfully"), |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
panic!("could not create new database with column family descriptors: {}", e); |
|
|
|
panic!("could not create new database with column family descriptors: {}", e); |
|
|
@ -205,7 +205,7 @@ pub fn test_column_family_with_options() { |
|
|
|
let opts = Options::default(); |
|
|
|
let opts = Options::default(); |
|
|
|
let cfs = vec![cf_descriptor]; |
|
|
|
let cfs = vec![cf_descriptor]; |
|
|
|
|
|
|
|
|
|
|
|
match DB::open_cf_descriptors(&opts, &n.name, cfs) { |
|
|
|
match DB::open_cf_descriptors(&opts, &n, cfs) { |
|
|
|
Ok(_db) => println!("succesfully re-opened database with column family descriptors"), |
|
|
|
Ok(_db) => println!("succesfully re-opened database with column family descriptors"), |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
panic!("unable to re-open database with column family descriptors: {}", e); |
|
|
|
panic!("unable to re-open database with column family descriptors: {}", e); |
|
|
|