@@ -4,16 +4,20 @@ use haizhi_rocksdb as rocksdb;
44
55use rocksdb:: Ranges ;
66use rocksdb:: { ColumnFamilyDescriptor , Options , DB } ;
7+
8+ mod util;
9+ use util:: DBPath ;
10+
711#[ test]
812fn test_approximate ( ) {
9- let path = "test1" ;
13+ let path = DBPath :: new ( "test_approximate_test1" ) ;
1014 let cf_opts = Options :: default ( ) ;
1115 let cf1 = ColumnFamilyDescriptor :: new ( "cf1" , cf_opts. clone ( ) ) ;
1216 let cf2 = ColumnFamilyDescriptor :: new ( "cf2" , cf_opts) ;
1317 let mut db_opts = Options :: default ( ) ;
1418 db_opts. create_missing_column_families ( true ) ;
1519 db_opts. create_if_missing ( true ) ;
16- let db = DB :: open_cf_descriptors ( & db_opts, path, vec ! [ cf1, cf2] ) . unwrap ( ) ;
20+ let db = DB :: open_cf_descriptors ( & db_opts, & path, vec ! [ cf1, cf2] ) . unwrap ( ) ;
1721 //
1822 let a = 1 . to_string ( ) ;
1923 let start_key: & [ u8 ] = a. as_ref ( ) ;
@@ -23,25 +27,25 @@ fn test_approximate() {
2327 let cf2 = db. cf_handle ( "cf2" ) . unwrap ( ) ;
2428 for key in 0 ..10000 {
2529 if key % 2 == 1 {
26- db. put_cf ( cf1, key. to_string ( ) , ( key * 2 ) . to_string ( ) )
30+ db. put_cf ( & cf1, key. to_string ( ) , ( key * 2 ) . to_string ( ) )
2731 . unwrap ( ) ;
2832 } else {
29- db. put_cf ( cf2, key. to_string ( ) , ( key * 2 ) . to_string ( ) )
33+ db. put_cf ( & cf2, key. to_string ( ) , ( key * 2 ) . to_string ( ) )
3034 . unwrap ( ) ;
3135 }
3236 }
33- db. flush_cf ( cf1) . unwrap ( ) ;
34- db. flush_cf ( cf2) . unwrap ( ) ;
37+ db. flush_cf ( & cf1) . unwrap ( ) ;
38+ db. flush_cf ( & cf2) . unwrap ( ) ;
3539 std:: thread:: sleep ( Duration :: from_secs ( 2 ) ) ;
3640 println ! (
3741 "start_key {:?}, end_key {:?}" ,
38- start_key. clone ( ) ,
39- end_key. clone ( )
42+ start_key,
43+ end_key,
4044 ) ;
4145 let files_error_margin: f64 = 1.0 ;
4246 let f = db
4347 . get_approximate_sizes_with_option (
44- cf1,
48+ & cf1,
4549 & [ Ranges :: new ( start_key, end_key) ] ,
4650 files_error_margin,
4751 )
@@ -53,18 +57,18 @@ fn test_approximate() {
5357
5458 for key in 0 ..10000 {
5559 if key % 2 == 1 {
56- db. delete_cf ( cf1, key. to_string ( ) ) . unwrap ( ) ;
60+ db. delete_cf ( & cf1, key. to_string ( ) ) . unwrap ( ) ;
5761 } else {
58- db. delete_cf ( cf2, key. to_string ( ) ) . unwrap ( ) ;
62+ db. delete_cf ( & cf2, key. to_string ( ) ) . unwrap ( ) ;
5963 }
6064 }
61- db. flush_cf ( cf1) . unwrap ( ) ;
65+ db. flush_cf ( & cf1) . unwrap ( ) ;
6266 std:: thread:: sleep ( Duration :: from_secs ( 5 ) ) ;
6367 let none: Option < Vec < u8 > > = None ;
6468 db. compact_range ( none. clone ( ) , none) ;
6569 let f = db
6670 . get_approximate_sizes_with_option (
67- cf1,
71+ & cf1,
6872 & [ Ranges :: new ( start_key, end_key) ] ,
6973 files_error_margin,
7074 )
0 commit comments