Mercurial > lbo > hg > leveldb-rs
changeset 318:113abed37a57
db_impl: Move a test around
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 29 Sep 2017 19:43:06 +0200 |
parents | 13a35941c2ff |
children | 29dd4509365f |
files | src/db_impl.rs |
diffstat | 1 files changed, 35 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/db_impl.rs Fri Sep 29 19:39:36 2017 +0200 +++ b/src/db_impl.rs Fri Sep 29 19:43:06 2017 +0200 @@ -979,40 +979,6 @@ } #[test] - fn test_db_impl_compaction_trivial_move() { - let mut db = DB::open("db", options::for_test()).unwrap(); - - db.put("abc".as_bytes(), "xyz".as_bytes()).unwrap(); - db.put("ab3".as_bytes(), "xyz".as_bytes()).unwrap(); - db.put("ab0".as_bytes(), "xyz".as_bytes()).unwrap(); - db.put("abz".as_bytes(), "xyz".as_bytes()).unwrap(); - assert_eq!(4, db.mem.len()); - let mut imm = MemTable::new(db.opt.cmp.clone()); - mem::swap(&mut imm, &mut db.mem); - db.imm = Some(imm); - db.compact_memtable().unwrap(); - - println!("children after: {:?}", - db.opt.env.children(Path::new("db/")).unwrap()); - assert!(db.opt.env.exists(Path::new("db/000004.ldb")).unwrap()); - - { - let v = db.vset.current(); - let mut v = v.borrow_mut(); - v.file_to_compact = Some(v.files[2][0].clone()); - v.file_to_compact_lvl = 2; - } - - db.maybe_do_compaction().unwrap(); - - { - let v = db.vset.current(); - let v = v.borrow_mut(); - assert_eq!(1, v.files[3].len()); - } - } - - #[test] fn test_db_impl_build_table() { let mut opt = options::for_test(); opt.block_size = 128; @@ -1051,8 +1017,6 @@ } } - // compaction tests // - /// build_db creates a database filled with the tables created by make_version(). fn build_db() -> DB { let name = "db"; @@ -1126,6 +1090,41 @@ assert!(env.exists(Path::new(&table_file_name(name, 13))).unwrap()); } + + #[test] + fn test_db_impl_compaction_trivial_move() { + let mut db = DB::open("db", options::for_test()).unwrap(); + + db.put("abc".as_bytes(), "xyz".as_bytes()).unwrap(); + db.put("ab3".as_bytes(), "xyz".as_bytes()).unwrap(); + db.put("ab0".as_bytes(), "xyz".as_bytes()).unwrap(); + db.put("abz".as_bytes(), "xyz".as_bytes()).unwrap(); + assert_eq!(4, db.mem.len()); + let mut imm = MemTable::new(db.opt.cmp.clone()); + mem::swap(&mut imm, &mut db.mem); + db.imm = Some(imm); + db.compact_memtable().unwrap(); + + println!("children after: {:?}", + db.opt.env.children(Path::new("db/")).unwrap()); + assert!(db.opt.env.exists(Path::new("db/000004.ldb")).unwrap()); + + { + let v = db.vset.current(); + let mut v = v.borrow_mut(); + v.file_to_compact = Some(v.files[2][0].clone()); + v.file_to_compact_lvl = 2; + } + + db.maybe_do_compaction().unwrap(); + + { + let v = db.vset.current(); + let v = v.borrow_mut(); + assert_eq!(1, v.files[3].len()); + } + } + #[test] fn test_db_impl_memtable_compaction() { let mut opt = options::for_test();