|
|
@ -13,22 +13,24 @@ |
|
|
|
// limitations under the License.
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
extern crate rocksdb; |
|
|
|
extern crate rocksdb; |
|
|
|
|
|
|
|
mod util; |
|
|
|
|
|
|
|
|
|
|
|
use rocksdb::{DB, MergeOperands, Options, ColumnFamilyDescriptor}; |
|
|
|
use rocksdb::{DB, MergeOperands, Options, ColumnFamilyDescriptor}; |
|
|
|
|
|
|
|
use util::DBPath; |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
pub fn test_column_family() { |
|
|
|
pub fn test_column_family() { |
|
|
|
let path = "_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, path).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(_) => println!("cf1 created successfully"), |
|
|
|
Ok(_db) => println!("cf1 created successfully"), |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
panic!("could not create column family: {}", e); |
|
|
|
panic!("could not create column family: {}", e); |
|
|
|
} |
|
|
|
} |
|
|
@ -39,8 +41,8 @@ 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, path) { |
|
|
|
match DB::open(&opts, &n) { |
|
|
|
Ok(_) => { |
|
|
|
Ok(_db) => { |
|
|
|
panic!("should not have opened DB successfully without \ |
|
|
|
panic!("should not have opened DB successfully without \ |
|
|
|
specifying column |
|
|
|
specifying column |
|
|
|
families") |
|
|
|
families") |
|
|
@ -57,8 +59,8 @@ 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, path, &["cf1"]) { |
|
|
|
match DB::open_cf(&opts, &n, &["cf1"]) { |
|
|
|
Ok(_) => 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), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -66,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, path); |
|
|
|
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), |
|
|
@ -81,19 +83,17 @@ 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(), path, &["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), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assert!(DB::destroy(&Options::default(), path).is_ok()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn test_create_missing_column_family() { |
|
|
|
fn test_create_missing_column_family() { |
|
|
|
let path = "_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,24 +101,22 @@ 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, path, &["cf1"]) { |
|
|
|
match DB::open_cf(&opts, &n, &["cf1"]) { |
|
|
|
Ok(_) => 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), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assert!(DB::destroy(&Options::default(), path).is_ok()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
#[ignore] |
|
|
|
#[ignore] |
|
|
|
fn test_merge_operator() { |
|
|
|
fn test_merge_operator() { |
|
|
|
let path = "_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, path, &["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 |
|
|
@ -180,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 path = "_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); |
|
|
@ -191,8 +189,8 @@ 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, path, cfs) { |
|
|
|
match DB::open_cf_descriptors(&opts, &n, cfs) { |
|
|
|
Ok(_) => 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); |
|
|
|
} |
|
|
|
} |
|
|
@ -207,13 +205,11 @@ 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, path, cfs) { |
|
|
|
match DB::open_cf_descriptors(&opts, &n, cfs) { |
|
|
|
Ok(_) => println!("succesfully re-opened database with column family descriptorrs"), |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
assert!(DB::destroy(&Options::default(), path).is_ok()); |
|
|
|
|
|
|
|
} |
|
|
|
} |