Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions score/kvs/rust_kvs/tests/test_scenarios/cit/persistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,60 @@ impl Scenario for ExplicitFlush {
}
}

/// Run KVS calls on storage that may already have snapshots.
///
/// The calls are those of the C++ scenario without discard (eclipse-score/persistency#713).
/// Before open and after each call, logs the fingerprints of the files in the working directory.
/// Also logs "result" ("ok" or "error") and the I32 value of key "slot", or "absent", or "none" without a KVS.
/// A failed call does not stop the scenario.
struct ExplicitSnapshotOperations;

impl Scenario for ExplicitSnapshotOperations {
fn name(&self) -> &str {
"explicit_snapshot_operations"
}

fn run(&self, input: &str) -> Result<(), String> {
let params = KvsParameters::from_json(input).expect("Failed to parse parameters");
let dir = params.dir.clone().expect("Working directory must be set");

// Logs the result of the step, the files and the value of "slot".
let step = |name: &str, result: Result<(), ErrorCode>, kvs: Option<&Kvs>| {
let result = if result.is_ok() { "ok" } else { "error" };
let slot = match kvs {
None => "none".to_string(),
Some(kvs) if !kvs.key_exists("slot").expect("Failed to check key slot") => "absent".to_string(),
Some(kvs) => kvs
.get_value_as::<i32>("slot")
.expect("Failed to read slot")
.to_string(),
};
info!(step = name, result, storage = storage_fingerprints(&dir), slot);
};

step("before_open", Ok(()), None);
let kvs = kvs_instance(params).expect("Failed to create KVS instance");
step("open", Ok(()), Some(&kvs));
step("set", kvs.set_value("slot", 10), Some(&kvs));
step("remove", kvs.remove_key("slot"), Some(&kvs));
step("reset", kvs.reset(), Some(&kvs));
step("set", kvs.set_value("slot", 11), Some(&kvs));
step("restore_invalid", kvs.snapshot_restore(SnapshotId(4)), Some(&kvs));
// The Rust snapshot count cannot fail.
kvs.snapshot_count();
step("snapshot_count", Ok(()), Some(&kvs));
step("restore", kvs.snapshot_restore(SnapshotId(1)), Some(&kvs));
step("set", kvs.set_value("slot", 12), Some(&kvs));
step("flush", kvs.flush(), Some(&kvs));

// The KVS object is dropped: a file written now was written by the drop.
drop(kvs);
step("drop", Ok(()), None);

Ok(())
}
}

/// Open the KVS and log every written key with its I32 value.
struct StoredValues;

Expand Down Expand Up @@ -350,6 +404,7 @@ pub fn persistency_group() -> Box<dyn ScenarioGroup> {
"persistency",
vec![
Box::new(ExplicitFlush),
Box::new(ExplicitSnapshotOperations),
Box::new(StoredValues),
// There is no counterpart of the C++ scenario `values_after_discard`: the Rust KVS has no API to discard
// pending changes.
Expand Down
Loading
Loading