76 lines
2.4 KiB
Rust
76 lines
2.4 KiB
Rust
//! Tests for `execute_all` and the observed storage loader, the two pieces
|
|
//! behind the `plan-run --trace` narration.
|
|
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
use plan_runner::{
|
|
LoadEvent, build_tables, build_tables_via_storage_observed, execute, execute_all, parse_plan,
|
|
};
|
|
use storage::MemoryStorage;
|
|
|
|
fn fixture(name: &str) -> String {
|
|
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
.join("fixtures")
|
|
.join(name);
|
|
fs::read_to_string(path).expect("read fixture")
|
|
}
|
|
|
|
#[test]
|
|
fn execute_all_covers_every_node_and_agrees_with_execute_on_the_root() {
|
|
let plan = parse_plan(&fixture("two_atom_join.json")).expect("parse fixture");
|
|
let tables = build_tables(&plan).expect("build tables");
|
|
let all = execute_all(&tables, &plan.query).expect("execute_all");
|
|
assert_eq!(all.len(), plan.query.nodes.len());
|
|
for node in &plan.query.nodes {
|
|
assert!(all.contains_key(&node.id), "missing node {}", node.id);
|
|
}
|
|
let root = execute(&tables, &plan.query).expect("execute");
|
|
assert_eq!(all[&plan.query.root].columns, root.columns);
|
|
assert_eq!(all[&plan.query.root].rows, root.rows);
|
|
}
|
|
|
|
#[test]
|
|
fn observed_loader_reports_storage_events_in_sorted_relation_order() {
|
|
let plan = parse_plan(&fixture("two_atom_join.json")).expect("parse fixture");
|
|
let mut storage = MemoryStorage::default();
|
|
let mut events = Vec::new();
|
|
let tables = build_tables_via_storage_observed(&plan, &mut storage, &mut |e| events.push(e))
|
|
.expect("load via storage");
|
|
assert_eq!(tables.len(), 2);
|
|
let expected = vec![
|
|
LoadEvent::CreateRelation {
|
|
relation: "edge".into(),
|
|
arity: 3,
|
|
},
|
|
LoadEvent::CreateRelation {
|
|
relation: "node".into(),
|
|
arity: 1,
|
|
},
|
|
LoadEvent::Insert {
|
|
relation: "edge".into(),
|
|
rows: 2,
|
|
},
|
|
LoadEvent::Insert {
|
|
relation: "node".into(),
|
|
rows: 2,
|
|
},
|
|
LoadEvent::Commit,
|
|
LoadEvent::ScanTable {
|
|
relation: "edge".into(),
|
|
rows: 2,
|
|
},
|
|
LoadEvent::ScanTable {
|
|
relation: "node".into(),
|
|
rows: 2,
|
|
},
|
|
];
|
|
assert_eq!(events, expected);
|
|
}
|
|
|
|
#[test]
|
|
fn scenario_label_round_trips_from_the_fixture() {
|
|
let plan = parse_plan(&fixture("two_atom_join.json")).expect("parse fixture");
|
|
assert_eq!(plan.scenario.as_deref(), Some("two-atom-join"));
|
|
}
|