adding backup & restore test case

master
Rohit Joshi 6 years ago
parent f8267c8303
commit 419084cf0f
  1. 41
      src/backup.rs

@ -92,7 +92,7 @@ impl BackupEngine {
/// ```ignore /// ```ignore
/// use rocksdb::backup::{BackupEngine, BackupEngineOptions}; /// use rocksdb::backup::{BackupEngine, BackupEngineOptions};
/// let backup_opts = BackupEngineOptions::default(); /// let backup_opts = BackupEngineOptions::default();
/// let backup_engine = BackupEngine::open(&backup_opts, &backup_path).unwrap(); /// let mut backup_engine = BackupEngine::open(&backup_opts, &backup_path).unwrap();
/// let mut restore_option = rocksdb::backup::RestoreOptions::default(); /// let mut restore_option = rocksdb::backup::RestoreOptions::default();
/// restore_option.set_keep_log_files(true); /// true to keep log files /// restore_option.set_keep_log_files(true); /// true to keep log files
/// if let Err(e) = backup_engine.restore_from_latest_backup(&db_path, &wal_dir, &restore_option) { /// if let Err(e) = backup_engine.restore_from_latest_backup(&db_path, &wal_dir, &restore_option) {
@ -201,3 +201,42 @@ impl Drop for RestoreOptions {
} }
} }
} }
#[test]
fn backup_restore() {
use db::DBVector;
// create backup
let path = "_rust_rocksdb_backup_restore_test";
{
let db = DB::open_default(path).unwrap();
let p = db.put(b"k1", b"v1111");
assert!(p.is_ok());
let r: Result<Option<DBVector>, Error> = db.get(b"k1");
assert!(r.unwrap().unwrap().to_utf8().unwrap() == "v1111");
let backup_path = "_rust_rocksdb_backup_path";
{
let backup_opts = BackupEngineOptions::default();
let mut backup_engine = BackupEngine::open(&backup_opts, &backup_path).unwrap();
let r = backup_engine.create_new_backup(&db);
assert!(r.is_ok());
let restore_path = "_rust_rocksdb_restore_from_backup_path";
{
let mut restore_option = RestoreOptions::default();
restore_option.set_keep_log_files(true); // true to keep log files
let restore_status = backup_engine.restore_from_latest_backup(&restore_path, &restore_path, &restore_option);
assert!(restore_status.is_ok());
let db = DB::open_default(restore_path).unwrap();
let r: Result<Option<DBVector>, Error> = db.get(b"k1");
assert!(r.unwrap().unwrap().to_utf8().unwrap() == "v1111");
}
}
}
}

Loading…
Cancel
Save