@@ -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,21 @@ 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 ) ) ; 
36-     println ! ( 
37-         "start_key {:?}, end_key {:?}" , 
38-         start_key. clone( ) , 
39-         end_key. clone( ) 
40-     ) ; 
40+     println ! ( "start_key {:?}, end_key {:?}" ,  start_key,  end_key, ) ; 
4141    let  files_error_margin:  f64  = 1.0 ; 
4242    let  f = db
4343        . get_approximate_sizes_with_option ( 
44-             cf1, 
44+             & cf1, 
4545            & [ Ranges :: new ( start_key,  end_key) ] , 
4646            files_error_margin, 
4747        ) 
@@ -53,18 +53,18 @@ fn test_approximate() {
5353
5454    for  key in  0 ..10000  { 
5555        if  key % 2  == 1  { 
56-             db. delete_cf ( cf1,  key. to_string ( ) ) . unwrap ( ) ; 
56+             db. delete_cf ( & cf1,  key. to_string ( ) ) . unwrap ( ) ; 
5757        }  else  { 
58-             db. delete_cf ( cf2,  key. to_string ( ) ) . unwrap ( ) ; 
58+             db. delete_cf ( & cf2,  key. to_string ( ) ) . unwrap ( ) ; 
5959        } 
6060    } 
61-     db. flush_cf ( cf1) . unwrap ( ) ; 
61+     db. flush_cf ( & cf1) . unwrap ( ) ; 
6262    std:: thread:: sleep ( Duration :: from_secs ( 5 ) ) ; 
6363    let  none:  Option < Vec < u8 > >  = None ; 
6464    db. compact_range ( none. clone ( ) ,  none) ; 
6565    let  f = db
6666        . get_approximate_sizes_with_option ( 
67-             cf1, 
67+             & cf1, 
6868            & [ Ranges :: new ( start_key,  end_key) ] , 
6969            files_error_margin, 
7070        ) 
0 commit comments