liminal-server 0.25.4

Standalone server for the liminal messaging bus
Documentation
//! DUR-024 R5: the census prints one plain line per figure and never a row
//! body; the command's wrapper refuses a configuration with nothing to
//! count, by name.

use std::collections::BTreeMap;

use crate::server::participant::{CheckpointCensus, PublicationBound};

fn census() -> CheckpointCensus {
    let mut nodes = BTreeMap::new();
    nodes.insert("index pages", (3, 300));
    nodes.insert("retained history values", (4, 1_000));
    nodes.insert("retired history", (0, 0));
    CheckpointCensus {
        conversation_id: 2,
        nodes,
        history_nodes: 7,
        history_bytes: 1_300,
        tokens: 2,
        committed_admissions: 4,
        slots: 2,
        attach_provenance: 1,
        retired: 0,
        locator: Some((255, 9)),
        log_rows_behind: 256,
        log_rows_ahead: 10,
        outbox_rows_behind: 9,
        outbox_rows_ahead: 1,
        body: Ok(512),
        bound: PublicationBound {
            pinned: 16 * 1024 * 1024,
            store: Some(8 * 1024 * 1024),
            bound: 8 * 1024 * 1024,
        },
        batches: 1,
    }
}

#[test]
fn the_census_prints_one_plain_line_per_figure() {
    let lines = census().lines();
    assert_eq!(
        lines,
        vec![
            "conversation: 2".to_owned(),
            "index pages: 3 nodes, 300 bytes".to_owned(),
            "retained history values: 4 nodes, 1000 bytes".to_owned(),
            "retired history: 0 nodes, 0 bytes".to_owned(),
            "history to publish: 7 nodes, 1300 bytes".to_owned(),
            "tokens: 2".to_owned(),
            "committed admissions: 4".to_owned(),
            "slots: 2".to_owned(),
            "attach provenance entries: 1".to_owned(),
            "retired identities: 0".to_owned(),
            "latest locator: covered log sequence 255, extension boundary 9".to_owned(),
            "operation log rows: 256 behind the locator, 10 ahead".to_owned(),
            "outbox rows: 9 behind the locator, 1 ahead".to_owned(),
            "checkpoint body and locator: 512 bytes".to_owned(),
            "batch bound: 8388608 bytes (pinned 16777216, store 8388608)".to_owned(),
            "batches a publication commits: 1".to_owned(),
        ]
    );
}

#[test]
fn an_uncapturable_owner_and_an_unbounded_store_are_said_by_name() {
    let mut census = census();
    census.body = Err("pending debt transition".to_owned());
    census.bound = PublicationBound {
        pinned: 16 * 1024 * 1024,
        store: None,
        bound: 16 * 1024 * 1024,
    };
    census.locator = None;
    let lines = census.lines();
    assert!(lines.contains(&"checkpoint body: not capturable: pending debt transition".to_owned()));
    assert!(
        lines
            .contains(&"batch bound: 16777216 bytes (pinned 16777216, store unbounded)".to_owned())
    );
    assert!(lines.contains(&"latest locator: absent".to_owned()));
}

#[test]
fn the_wrapper_refuses_a_missing_configuration_by_name() -> Result<(), String> {
    let missing = std::path::Path::new("/nonexistent/liminal-checkpoint-census.toml");
    match super::run_checkpoint_census(missing, Some(2), None) {
        Ok(lines) => Err(format!("a missing configuration answered {lines:?}")),
        Err(error) => {
            assert!(!error.to_string().is_empty());
            Ok(())
        }
    }
}