T-190: M2.3q — tools/curate-etl: send-ilp CLI command wiring discover_ilp_shard_files + tcp_ilp_connector + send_ilp_shard_files into cli.rs + main.rs with parser tests and a loopback TcpListener end-to-end test (explicit --addr, no default target, no new crates, no bench changes, no live QuestDB)
This commit is contained in:
parent
b51ce9b22b
commit
e9fbea3dda
7 changed files with 703 additions and 4 deletions
|
|
@ -1749,6 +1749,22 @@ curate-etl curate-fx-1m \
|
||||||
- **Outputs & fail-closed publication:** writes `<out>/fx_1m.shard-<NN>.ilp` (`00`..`<shards-1>`) and prints the `format_curate_fx_1m_report` summary to stdout. Inherits the runner's fail-closed preflight and staging/rollback guarantees (refuses to overwrite existing `fx_1m.shard-*.ilp` files and leaves no partial shard or staging files on error).
|
- **Outputs & fail-closed publication:** writes `<out>/fx_1m.shard-<NN>.ilp` (`00`..`<shards-1>`) and prints the `format_curate_fx_1m_report` summary to stdout. Inherits the runner's fail-closed preflight and staging/rollback guarantees (refuses to overwrite existing `fx_1m.shard-*.ilp` files and leaves no partial shard or staging files on error).
|
||||||
- **File mode only:** MongoDB streaming flags (such as `--from-mongo` and `--mongo-uri`) are rejected; `--from-mongo` streaming and live QuestDB ingestion remain follow-ups.
|
- **File mode only:** MongoDB streaming flags (such as `--from-mongo` and `--mongo-uri`) are rejected; `--from-mongo` streaming and live QuestDB ingestion remain follow-ups.
|
||||||
|
|
||||||
|
### `send-ilp` Command (`M2.3q`)
|
||||||
|
|
||||||
|
CLI command wiring `discover_ilp_shard_files`, `tcp_ilp_connector`, and `send_ilp_shard_files` (`run_send_ilp`) into the `curate-etl` binary to stream published intraday ILP v2 shard files to an explicit QuestDB TCP endpoint:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curate-etl send-ilp \
|
||||||
|
--dir ./out \
|
||||||
|
--prefix bars_1m \
|
||||||
|
--addr 127.0.0.1:9009
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Required flags (no default target):** `--dir <published-shard-dir>`, `--prefix <bars_1m|bars_1m_qm|fx_1m>`, and `--addr <host:port>` are all required (accepting both `--flag value` and `--flag=value`). There is **no default address and no environment-variable fallback**, so QA QuestDB is never targeted by accident.
|
||||||
|
- **Allowed prefixes:** restricted to `bars_1m` (`curate-bars-1m`), `bars_1m_qm` (`run_curate_qm_bars_1m`), and `fx_1m` (`curate-fx-1m`).
|
||||||
|
- **Fail-closed order & reporting:** validates and discovers the contiguous `0..N` shard set in `--dir` before resolving `--addr` or opening any socket; streams each shard verbatim over its own TCP socket using `IlpTcpOptions::default()` and `IlpSendOptions::default()`; prints `format_ilp_send_report` to stdout on exit `0`, or `error: ...` plus any formatted partial report (`per_shard_bytes`) to stderr on non-zero exit.
|
||||||
|
- **Delivery & protocol caveats:** TCP ILP provides no per-row or per-batch server acknowledgement — exit `0` means all bytes were accepted by local sockets and write-half shutdown succeeded, **not** that rows were committed in QuestDB; verify committed row counts and representative values via PGWire after loading. QuestDB `10.2.0` acceptance of ILP v2 binary `DOUBLE` payloads over TCP without a handshake remains **unverified** until the manual `quant` load check.
|
||||||
|
|
||||||
## `run_curate_qm_bars_1m` Bounded-Memory File-to-File Runner (`M2.3m`)
|
## `run_curate_qm_bars_1m` Bounded-Memory File-to-File Runner (`M2.3m`)
|
||||||
|
|
||||||
`run_curate_qm_bars_1m` / `run_curate_qm_bars_1m_with_readers` (`src/run_curate_qm_bars_1m.rs`) streams a concatenated raw BSON `qmIntraday` dump alongside a headerless 5-column `provider_mapping.tsv` (`load_provider_mapping_tsv`) into per-shard QuestDB ILP v2 files (`<out_dir>/bars_1m_qm.shard-<NN>.ilp`) via `curate_and_write_qm_bars_1m` (`src/curate_qm_bars_1m.rs`):
|
`run_curate_qm_bars_1m` / `run_curate_qm_bars_1m_with_readers` (`src/run_curate_qm_bars_1m.rs`) streams a concatenated raw BSON `qmIntraday` dump alongside a headerless 5-column `provider_mapping.tsv` (`load_provider_mapping_tsv`) into per-shard QuestDB ILP v2 files (`<out_dir>/bars_1m_qm.shard-<NN>.ilp`) via `curate_and_write_qm_bars_1m` (`src/curate_qm_bars_1m.rs`):
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ use crate::bson_qm_events::{
|
||||||
use crate::bson_stream::BsonStreamOptions;
|
use crate::bson_stream::BsonStreamOptions;
|
||||||
use crate::curate_adj::AdjPointInTimeFence;
|
use crate::curate_adj::AdjPointInTimeFence;
|
||||||
use crate::ilp::IlpWriterOptions;
|
use crate::ilp::IlpWriterOptions;
|
||||||
|
use crate::ilp_send::SendIlpArgs;
|
||||||
use crate::mongo_stream::{
|
use crate::mongo_stream::{
|
||||||
MongoCliOptions, MongoUriSource, DEFAULT_MONGO_BATCH_SIZE, DEFAULT_MONGO_URI_ENV,
|
MongoCliOptions, MongoUriSource, DEFAULT_MONGO_BATCH_SIZE, DEFAULT_MONGO_URI_ENV,
|
||||||
MAX_MONGO_BATCH_SIZE,
|
MAX_MONGO_BATCH_SIZE,
|
||||||
|
|
@ -87,6 +88,7 @@ pub enum CliAction {
|
||||||
CurateBars1m(CurateBars1mArgs),
|
CurateBars1m(CurateBars1mArgs),
|
||||||
CurateFx1m(CurateFx1mArgs),
|
CurateFx1m(CurateFx1mArgs),
|
||||||
CuratePosts(CuratePostsArgs),
|
CuratePosts(CuratePostsArgs),
|
||||||
|
SendIlp(SendIlpArgs),
|
||||||
BenchSplit(usize),
|
BenchSplit(usize),
|
||||||
BenchAdj(usize),
|
BenchAdj(usize),
|
||||||
BenchCorporateActions(usize),
|
BenchCorporateActions(usize),
|
||||||
|
|
@ -154,6 +156,8 @@ pub fn format_usage(name: &str, version: &str) -> String {
|
||||||
Curate USD/CAD 1-minute FX bars from eodIntraday1M BSON into fx_1m.shard-<NN>.ilp\n\
|
Curate USD/CAD 1-minute FX bars from eodIntraday1M BSON into fx_1m.shard-<NN>.ilp\n\
|
||||||
{name} curate-posts --ceo-posts <path> --provider-mapping <path> --out <dir> --timestamp-unit <seconds|millis> [--key-field <name>] [--spiel-id-field <name>] [--timestamp-field <name>] [--edited-field <name>] [--bot-field <name>] [--user-id-field <name>] [--text-field <name>] [--mapping-source <name>]\n\
|
{name} curate-posts --ceo-posts <path> --provider-mapping <path> --out <dir> --timestamp-unit <seconds|millis> [--key-field <name>] [--spiel-id-field <name>] [--timestamp-field <name>] [--edited-field <name>] [--bot-field <name>] [--user-id-field <name>] [--text-field <name>] [--mapping-source <name>]\n\
|
||||||
Curate ceoPosts from BSON + provider_mapping TSV into <out>/events/year=YYYY/part.parquet using a dedicated --out directory (--timestamp-unit has no default; defaults: --key-field {DEFAULT_POSTS_KEY_FIELD}, --spiel-id-field {DEFAULT_POSTS_SPIEL_ID_FIELD}, --timestamp-field {DEFAULT_POSTS_TIMESTAMP_FIELD}, --edited-field {DEFAULT_POSTS_EDITED_FIELD}, --bot-field {DEFAULT_POSTS_BOT_FIELD}, --user-id-field {DEFAULT_POSTS_USER_ID_FIELD}, --text-field {DEFAULT_POSTS_TEXT_FIELD}, --mapping-source {DEFAULT_POSTS_MAPPING_SOURCE})\n\
|
Curate ceoPosts from BSON + provider_mapping TSV into <out>/events/year=YYYY/part.parquet using a dedicated --out directory (--timestamp-unit has no default; defaults: --key-field {DEFAULT_POSTS_KEY_FIELD}, --spiel-id-field {DEFAULT_POSTS_SPIEL_ID_FIELD}, --timestamp-field {DEFAULT_POSTS_TIMESTAMP_FIELD}, --edited-field {DEFAULT_POSTS_EDITED_FIELD}, --bot-field {DEFAULT_POSTS_BOT_FIELD}, --user-id-field {DEFAULT_POSTS_USER_ID_FIELD}, --text-field {DEFAULT_POSTS_TEXT_FIELD}, --mapping-source {DEFAULT_POSTS_MAPPING_SOURCE})\n\
|
||||||
|
{name} send-ilp --dir <dir> --prefix <bars_1m|bars_1m_qm|fx_1m> --addr <host:port>\n\
|
||||||
|
Stream published ILP v2 shard files to an explicit QuestDB TCP endpoint (no default address; success means bytes were accepted by local sockets, not rows committed — verify row counts via PGWire; ILP v2 binary doubles over TCP on QuestDB 10.2.0 are unverified until the manual quant load check)\n\
|
||||||
{name} bench-split [rows] Run fixed-seed split lookup + un-adjust benchmark (default: {DEFAULT_BENCH_ROWS})\n\
|
{name} bench-split [rows] Run fixed-seed split lookup + un-adjust benchmark (default: {DEFAULT_BENCH_ROWS})\n\
|
||||||
{name} bench-adj [events] Run fixed-seed adj_factors build benchmark (default: {DEFAULT_ADJ_BENCH_EVENTS})\n\
|
{name} bench-adj [events] Run fixed-seed adj_factors build benchmark (default: {DEFAULT_ADJ_BENCH_EVENTS})\n\
|
||||||
{name} bench-corporate-actions [events] Run fixed-seed corporate_actions build benchmark (default: {DEFAULT_CORPORATE_ACTIONS_BENCH_EVENTS})\n\
|
{name} bench-corporate-actions [events] Run fixed-seed corporate_actions build benchmark (default: {DEFAULT_CORPORATE_ACTIONS_BENCH_EVENTS})\n\
|
||||||
|
|
@ -205,6 +209,7 @@ pub fn format_usage_stderr(name: &str) -> String {
|
||||||
{name} curate-bars-1m --eod-intraday <path> --qm-splits <path> --provider-mapping <path> --out <dir> --shards <N> --known-at-micros <i64> [--mapping-source <name>]\n\
|
{name} curate-bars-1m --eod-intraday <path> --qm-splits <path> --provider-mapping <path> --out <dir> --shards <N> --known-at-micros <i64> [--mapping-source <name>]\n\
|
||||||
{name} curate-fx-1m --eod-intraday <path> --out <dir> --shards <N>\n\
|
{name} curate-fx-1m --eod-intraday <path> --out <dir> --shards <N>\n\
|
||||||
{name} curate-posts --ceo-posts <path> --provider-mapping <path> --out <dir> --timestamp-unit <seconds|millis> [--key-field <name>] [--spiel-id-field <name>] [--timestamp-field <name>] [--edited-field <name>] [--bot-field <name>] [--user-id-field <name>] [--text-field <name>] [--mapping-source <name>]\n\
|
{name} curate-posts --ceo-posts <path> --provider-mapping <path> --out <dir> --timestamp-unit <seconds|millis> [--key-field <name>] [--spiel-id-field <name>] [--timestamp-field <name>] [--edited-field <name>] [--bot-field <name>] [--user-id-field <name>] [--text-field <name>] [--mapping-source <name>]\n\
|
||||||
|
{name} send-ilp --dir <dir> --prefix <bars_1m|bars_1m_qm|fx_1m> --addr <host:port>\n\
|
||||||
{name} bench-split [rows]\n\
|
{name} bench-split [rows]\n\
|
||||||
{name} bench-adj [events]\n\
|
{name} bench-adj [events]\n\
|
||||||
{name} bench-corporate-actions [events]\n\
|
{name} bench-corporate-actions [events]\n\
|
||||||
|
|
@ -1818,6 +1823,80 @@ fn parse_curate_fx_1m_args(args: &[&str]) -> Result<CliAction, String> {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ALLOWED_SEND_ILP_PREFIXES: [&str; 3] = ["bars_1m", "bars_1m_qm", "fx_1m"];
|
||||||
|
|
||||||
|
fn parse_send_ilp_args(args: &[&str]) -> Result<CliAction, String> {
|
||||||
|
let mut dir: Option<PathBuf> = None;
|
||||||
|
let mut prefix: Option<String> = None;
|
||||||
|
let mut addr: Option<String> = None;
|
||||||
|
|
||||||
|
let mut i = 0usize;
|
||||||
|
while i < args.len() {
|
||||||
|
let token = args[i];
|
||||||
|
if !token.starts_with("--") {
|
||||||
|
return Err(format!(
|
||||||
|
"unexpected positional argument '{token}' for send-ilp"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let (flag, value) = if let Some((k, v)) = token.split_once('=') {
|
||||||
|
i += 1;
|
||||||
|
(k, v)
|
||||||
|
} else {
|
||||||
|
let Some(&v) = args.get(i + 1) else {
|
||||||
|
return Err(format!("missing value for flag '{token}'"));
|
||||||
|
};
|
||||||
|
if v.starts_with("--") {
|
||||||
|
return Err(format!("missing value for flag '{token}'"));
|
||||||
|
}
|
||||||
|
i += 2;
|
||||||
|
(token, v)
|
||||||
|
};
|
||||||
|
|
||||||
|
match flag {
|
||||||
|
"--dir" => {
|
||||||
|
if dir.is_some() {
|
||||||
|
return Err("duplicate flag '--dir'".to_string());
|
||||||
|
}
|
||||||
|
if value.is_empty() {
|
||||||
|
return Err("empty value for flag '--dir'".to_string());
|
||||||
|
}
|
||||||
|
dir = Some(PathBuf::from(value));
|
||||||
|
}
|
||||||
|
"--prefix" => {
|
||||||
|
if prefix.is_some() {
|
||||||
|
return Err("duplicate flag '--prefix'".to_string());
|
||||||
|
}
|
||||||
|
if value.is_empty() {
|
||||||
|
return Err("empty value for flag '--prefix'".to_string());
|
||||||
|
}
|
||||||
|
if !ALLOWED_SEND_ILP_PREFIXES.contains(&value) {
|
||||||
|
return Err(format!(
|
||||||
|
"unsupported --prefix '{value}' for send-ilp (expected one of: bars_1m, bars_1m_qm, fx_1m)"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
prefix = Some(value.to_string());
|
||||||
|
}
|
||||||
|
"--addr" => {
|
||||||
|
if addr.is_some() {
|
||||||
|
return Err("duplicate flag '--addr'".to_string());
|
||||||
|
}
|
||||||
|
if value.trim().is_empty() {
|
||||||
|
return Err("empty value for flag '--addr'".to_string());
|
||||||
|
}
|
||||||
|
addr = Some(value.to_string());
|
||||||
|
}
|
||||||
|
other => return Err(format!("unknown flag '{other}' for send-ilp")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let dir = dir.ok_or_else(|| "missing required flag '--dir'".to_string())?;
|
||||||
|
let prefix = prefix.ok_or_else(|| "missing required flag '--prefix'".to_string())?;
|
||||||
|
let addr = addr.ok_or_else(|| "missing required flag '--addr'".to_string())?;
|
||||||
|
|
||||||
|
Ok(CliAction::SendIlp(SendIlpArgs { dir, prefix, addr }))
|
||||||
|
}
|
||||||
|
|
||||||
/// Parses CLI arguments (excluding `argv[0]`) into a [`CliAction`].
|
/// Parses CLI arguments (excluding `argv[0]`) into a [`CliAction`].
|
||||||
pub fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
pub fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||||
let slices: Vec<&str> = args.iter().map(String::as_str).collect();
|
let slices: Vec<&str> = args.iter().map(String::as_str).collect();
|
||||||
|
|
@ -1836,6 +1915,7 @@ pub fn parse_args(args: &[String]) -> Result<CliAction, String> {
|
||||||
["curate-bars-1m", rest @ ..] => parse_curate_bars_1m_args(rest),
|
["curate-bars-1m", rest @ ..] => parse_curate_bars_1m_args(rest),
|
||||||
["curate-fx-1m", rest @ ..] => parse_curate_fx_1m_args(rest),
|
["curate-fx-1m", rest @ ..] => parse_curate_fx_1m_args(rest),
|
||||||
["curate-posts", rest @ ..] => parse_curate_posts_args(rest),
|
["curate-posts", rest @ ..] => parse_curate_posts_args(rest),
|
||||||
|
["send-ilp", rest @ ..] => parse_send_ilp_args(rest),
|
||||||
["bench-split"] => Ok(CliAction::BenchSplit(DEFAULT_BENCH_ROWS)),
|
["bench-split"] => Ok(CliAction::BenchSplit(DEFAULT_BENCH_ROWS)),
|
||||||
["bench-split", raw] => match raw.parse::<usize>() {
|
["bench-split", raw] => match raw.parse::<usize>() {
|
||||||
Ok(n) if n > 0 => Ok(CliAction::BenchSplit(n)),
|
Ok(n) if n > 0 => Ok(CliAction::BenchSplit(n)),
|
||||||
|
|
@ -4814,4 +4894,200 @@ mod tests {
|
||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
assert!(err.contains("cannot share BSON field 'shared'"), "{err}");
|
assert!(err.contains("cannot share BSON field 'shared'"), "{err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_send_ilp_valid_space_and_equals_forms_and_all_allowed_prefixes() {
|
||||||
|
for prefix in ["bars_1m", "bars_1m_qm", "fx_1m"] {
|
||||||
|
let expected = CliAction::SendIlp(SendIlpArgs {
|
||||||
|
dir: PathBuf::from("/tmp/shards"),
|
||||||
|
prefix: prefix.to_string(),
|
||||||
|
addr: "127.0.0.1:9009".to_string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
let parsed_space = parse_args(&to_args(&[
|
||||||
|
"send-ilp",
|
||||||
|
"--dir",
|
||||||
|
"/tmp/shards",
|
||||||
|
"--prefix",
|
||||||
|
prefix,
|
||||||
|
"--addr",
|
||||||
|
"127.0.0.1:9009",
|
||||||
|
]))
|
||||||
|
.expect("valid send-ilp args in space form");
|
||||||
|
assert_eq!(parsed_space, expected);
|
||||||
|
|
||||||
|
let prefix_eq = format!("--prefix={prefix}");
|
||||||
|
let parsed_eq = parse_args(&to_args(&[
|
||||||
|
"send-ilp",
|
||||||
|
"--dir=/tmp/shards",
|
||||||
|
&prefix_eq,
|
||||||
|
"--addr=127.0.0.1:9009",
|
||||||
|
]))
|
||||||
|
.expect("valid send-ilp args in equals form");
|
||||||
|
assert_eq!(parsed_eq, expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn send_ilp_usage_mentions_command_flags_and_delivery_caveat() {
|
||||||
|
let expected_flags = ["--dir", "--prefix", "--addr"];
|
||||||
|
let usage = format_usage("curate-etl", "0.1.0");
|
||||||
|
let usage_stderr = format_usage_stderr("curate-etl");
|
||||||
|
let usage_line = usage
|
||||||
|
.lines()
|
||||||
|
.find(|line| line.trim_start().starts_with("curate-etl send-ilp "))
|
||||||
|
.expect("format_usage missing send-ilp command line");
|
||||||
|
let stderr_line = usage_stderr
|
||||||
|
.lines()
|
||||||
|
.find(|line| line.trim_start().starts_with("curate-etl send-ilp "))
|
||||||
|
.expect("format_usage_stderr missing send-ilp command line");
|
||||||
|
for flag in expected_flags {
|
||||||
|
assert!(
|
||||||
|
usage_line.contains(flag),
|
||||||
|
"format_usage send-ilp line missing {flag}: {usage_line}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
stderr_line.contains(flag),
|
||||||
|
"format_usage_stderr send-ilp line missing {flag}: {stderr_line}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert!(
|
||||||
|
usage.contains("no default address"),
|
||||||
|
"format_usage missing no-default-address note"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
usage.contains("PGWire"),
|
||||||
|
"format_usage missing PGWire verification note"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
usage.contains("10.2.0"),
|
||||||
|
"format_usage missing QuestDB 10.2.0 unverified note"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_send_ilp_rejects_missing_required_flags_with_no_default_addr() {
|
||||||
|
let required: [(&str, &str); 3] = [
|
||||||
|
("--dir", "/tmp/shards"),
|
||||||
|
("--prefix", "fx_1m"),
|
||||||
|
("--addr", "127.0.0.1:9009"),
|
||||||
|
];
|
||||||
|
|
||||||
|
for omit in 0..required.len() {
|
||||||
|
let mut argv: Vec<&str> = vec!["send-ilp"];
|
||||||
|
for (idx, &(flag, val)) in required.iter().enumerate() {
|
||||||
|
if idx != omit {
|
||||||
|
argv.push(flag);
|
||||||
|
argv.push(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let err = parse_args(&to_args(&argv)).unwrap_err();
|
||||||
|
let missing_flag = required[omit].0;
|
||||||
|
assert!(
|
||||||
|
err.contains(&format!("missing required flag '{missing_flag}'")),
|
||||||
|
"expected missing required flag '{missing_flag}', got: {err}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parse_send_ilp_rejects_duplicates_empty_missing_value_unknown_positional_and_bad_prefix() {
|
||||||
|
let base = [
|
||||||
|
"send-ilp",
|
||||||
|
"--dir",
|
||||||
|
"/tmp/shards",
|
||||||
|
"--prefix",
|
||||||
|
"bars_1m",
|
||||||
|
"--addr",
|
||||||
|
"127.0.0.1:9009",
|
||||||
|
];
|
||||||
|
|
||||||
|
// Duplicate flags.
|
||||||
|
for (flag, extra_val) in [
|
||||||
|
("--dir", "/tmp/other"),
|
||||||
|
("--prefix", "fx_1m"),
|
||||||
|
("--addr", "127.0.0.1:9010"),
|
||||||
|
] {
|
||||||
|
let mut argv = base.to_vec();
|
||||||
|
argv.push(flag);
|
||||||
|
argv.push(extra_val);
|
||||||
|
let err = parse_args(&to_args(&argv)).unwrap_err();
|
||||||
|
assert!(
|
||||||
|
err.contains(&format!("duplicate flag '{flag}'")),
|
||||||
|
"expected duplicate error for {flag}, got: {err}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty values via --flag=.
|
||||||
|
for flag in ["--dir", "--prefix", "--addr"] {
|
||||||
|
let empty_token = format!("{flag}=");
|
||||||
|
let err = parse_args(&to_args(&["send-ilp", &empty_token])).unwrap_err();
|
||||||
|
assert!(
|
||||||
|
err.contains(&format!("empty value for flag '{flag}'")),
|
||||||
|
"expected empty value error for {flag}, got: {err}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Whitespace-only --addr.
|
||||||
|
let err = parse_args(&to_args(&[
|
||||||
|
"send-ilp",
|
||||||
|
"--dir",
|
||||||
|
"/tmp/shards",
|
||||||
|
"--prefix",
|
||||||
|
"fx_1m",
|
||||||
|
"--addr",
|
||||||
|
" ",
|
||||||
|
]))
|
||||||
|
.unwrap_err();
|
||||||
|
assert!(err.contains("empty value for flag '--addr'"), "{err}");
|
||||||
|
|
||||||
|
// Missing value at end of input or followed by another flag.
|
||||||
|
let err = parse_args(&to_args(&["send-ilp", "--dir"])).unwrap_err();
|
||||||
|
assert!(err.contains("missing value for flag '--dir'"), "{err}");
|
||||||
|
let err = parse_args(&to_args(&[
|
||||||
|
"send-ilp",
|
||||||
|
"--prefix",
|
||||||
|
"--addr",
|
||||||
|
"127.0.0.1:9009",
|
||||||
|
]))
|
||||||
|
.unwrap_err();
|
||||||
|
assert!(err.contains("missing value for flag '--prefix'"), "{err}");
|
||||||
|
|
||||||
|
// Unknown flag (including --from-mongo).
|
||||||
|
for flag in ["--nope", "--from-mongo", "--timeout"] {
|
||||||
|
let mut argv = base.to_vec();
|
||||||
|
argv.push(flag);
|
||||||
|
argv.push("1");
|
||||||
|
let err = parse_args(&to_args(&argv)).unwrap_err();
|
||||||
|
assert!(
|
||||||
|
err.contains(&format!("unknown flag '{flag}' for send-ilp")),
|
||||||
|
"expected unknown flag error for {flag}, got: {err}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Positional argument.
|
||||||
|
let err = parse_args(&to_args(&["send-ilp", "positional"])).unwrap_err();
|
||||||
|
assert!(
|
||||||
|
err.contains("unexpected positional argument 'positional' for send-ilp"),
|
||||||
|
"{err}"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Unsupported non-empty prefixes must list all three allowed values.
|
||||||
|
for bad_prefix in ["bars_1d", "../x", "BARS_1M", "fx_1d", "fx_1m_extra"] {
|
||||||
|
let err = parse_args(&to_args(&[
|
||||||
|
"send-ilp",
|
||||||
|
"--dir",
|
||||||
|
"/tmp/shards",
|
||||||
|
"--prefix",
|
||||||
|
bad_prefix,
|
||||||
|
"--addr",
|
||||||
|
"127.0.0.1:9009",
|
||||||
|
]))
|
||||||
|
.unwrap_err();
|
||||||
|
assert!(
|
||||||
|
err.contains("bars_1m") && err.contains("bars_1m_qm") && err.contains("fx_1m"),
|
||||||
|
"expected allowed prefixes in error for '{bad_prefix}', got: {err}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -825,6 +825,26 @@ pub fn tcp_ilp_connector(
|
||||||
tcp_ilp_connector_for_addrs(resolved, options)
|
tcp_ilp_connector_for_addrs(resolved, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Arguments for the `send-ilp` CLI subcommand and [`run_send_ilp`].
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct SendIlpArgs {
|
||||||
|
pub dir: PathBuf,
|
||||||
|
pub prefix: String,
|
||||||
|
pub addr: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Discovers published `<prefix>.shard-<digits>.ilp` files in `args.dir`, validates and resolves
|
||||||
|
/// `args.addr` via [`tcp_ilp_connector`] with [`IlpTcpOptions::default()`], and streams all shards
|
||||||
|
/// via [`send_ilp_shard_files`] with [`IlpSendOptions::default()`].
|
||||||
|
///
|
||||||
|
/// Discovery runs before address resolution or any socket connection so a bad directory or
|
||||||
|
/// incomplete shard set never opens a socket.
|
||||||
|
pub fn run_send_ilp(args: &SendIlpArgs) -> Result<IlpSendReport, IlpSendError> {
|
||||||
|
let files = discover_ilp_shard_files(&args.dir, &args.prefix)?;
|
||||||
|
let connector = tcp_ilp_connector(&args.addr, IlpTcpOptions::default())?;
|
||||||
|
send_ilp_shard_files(&files, connector, IlpSendOptions::default())
|
||||||
|
}
|
||||||
|
|
||||||
/// Formats [`IlpSendReport`] into a deterministic machine-readable `key=value` summary in the
|
/// Formats [`IlpSendReport`] into a deterministic machine-readable `key=value` summary in the
|
||||||
/// style of the crate's `format_curate_*_report` helpers.
|
/// style of the crate's `format_curate_*_report` helpers.
|
||||||
pub fn format_ilp_send_report(report: &IlpSendReport) -> String {
|
pub fn format_ilp_send_report(report: &IlpSendReport) -> String {
|
||||||
|
|
|
||||||
|
|
@ -1300,3 +1300,246 @@ fn tcp_connector_skips_unreachable_address_then_pins_reachable_one_for_all_shard
|
||||||
payloads.iter().map(|p| p.len() as u64).sum::<u64>()
|
payloads.iter().map(|p| p.len() as u64).sum::<u64>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// `run_send_ilp` wrapper tests (`M2.3q`).
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn run_send_ilp_end_to_end_over_loopback() {
|
||||||
|
let dir = TempDirGuard::new("run-send-ilp-e2e");
|
||||||
|
let payload0: Vec<u8> = vec![
|
||||||
|
b'f', b'x', b'_', b'1', b'm', b',', b'p', b'a', b'i', b'r', b'=', b'U', b'S', b'D', b'C',
|
||||||
|
b'A', b'D', b' ', b'c', b'=', b'=', 0x10, 0x0A, 0xFF, 0xFE, 0x80, 0x00, 0x00, 0xF0, 0x3F,
|
||||||
|
b' ', b'1', b'7', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0',
|
||||||
|
b'0', b'0', b't', b'\n',
|
||||||
|
];
|
||||||
|
let payload1: Vec<u8> = Vec::new();
|
||||||
|
let payload2: Vec<u8> = vec![
|
||||||
|
b'f', b'x', b'_', b'1', b'm', b',', b'p', b'a', b'i', b'r', b'=', b'U', b'S', b'D', b'C',
|
||||||
|
b'A', b'D', b' ', b'c', b'=', b'=', 0x10, 0xC0, 0x81, 0x0A, 0x0A, 0x01, 0x02, 0xF5, 0x3F,
|
||||||
|
b' ', b'1', b'7', b'0', b'0', b'0', b'0', b'0', b'0', b'6', b'0', b'0', b'0', b'0', b'0',
|
||||||
|
b'0', b'0', b't', b'\n',
|
||||||
|
];
|
||||||
|
assert!(std::str::from_utf8(&payload0).is_err());
|
||||||
|
assert!(std::str::from_utf8(&payload2).is_err());
|
||||||
|
assert!(payload0.contains(&0x0A));
|
||||||
|
assert!(payload2.contains(&0x0A));
|
||||||
|
|
||||||
|
write_bytes(&dir.path().join("fx_1m.shard-00.ilp"), &payload0);
|
||||||
|
write_bytes(&dir.path().join("fx_1m.shard-01.ilp"), &payload1);
|
||||||
|
write_bytes(&dir.path().join("fx_1m.shard-02.ilp"), &payload2);
|
||||||
|
|
||||||
|
let listener = TcpListener::bind("127.0.0.1:0").expect("bind loopback listener");
|
||||||
|
let listen_addr = listener.local_addr().expect("local addr");
|
||||||
|
listener
|
||||||
|
.set_nonblocking(true)
|
||||||
|
.expect("set loopback listener nonblocking");
|
||||||
|
|
||||||
|
let server_handle = thread::spawn(move || {
|
||||||
|
let deadline = Instant::now() + Duration::from_secs(3);
|
||||||
|
let mut reader_handles = Vec::with_capacity(3);
|
||||||
|
for accepted in 0..3 {
|
||||||
|
let (mut stream, peer) = accept_with_deadline(&listener, deadline, accepted, 3);
|
||||||
|
stream
|
||||||
|
.set_read_timeout(Some(Duration::from_secs(3)))
|
||||||
|
.expect("set server read timeout");
|
||||||
|
reader_handles.push(thread::spawn(move || {
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
stream
|
||||||
|
.read_to_end(&mut buf)
|
||||||
|
.expect("read shard stream to EOF");
|
||||||
|
(peer, buf)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
let received: Vec<(SocketAddr, Vec<u8>)> = reader_handles
|
||||||
|
.into_iter()
|
||||||
|
.map(|h| h.join().expect("join reader thread"))
|
||||||
|
.collect();
|
||||||
|
(listener, received)
|
||||||
|
});
|
||||||
|
|
||||||
|
let report = run_send_ilp(&SendIlpArgs {
|
||||||
|
dir: dir.path().to_path_buf(),
|
||||||
|
prefix: "fx_1m".to_string(),
|
||||||
|
addr: listen_addr.to_string(),
|
||||||
|
})
|
||||||
|
.expect("run_send_ilp should succeed over loopback");
|
||||||
|
|
||||||
|
let (listener, received) = server_handle.join().expect("join server thread");
|
||||||
|
|
||||||
|
// Verify no extra 4th connection was opened.
|
||||||
|
match listener.accept() {
|
||||||
|
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
|
||||||
|
Ok((_, peer)) => panic!("unexpected extra connection from {peer}"),
|
||||||
|
Err(err) => panic!("unexpected error checking accept queue: {err}"),
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(received.len(), 3);
|
||||||
|
let distinct_peers: HashSet<SocketAddr> = received.iter().map(|(peer, _)| *peer).collect();
|
||||||
|
assert_eq!(distinct_peers.len(), 3, "expected 3 separate connections");
|
||||||
|
|
||||||
|
let mut received_payloads: Vec<Vec<u8>> = received.into_iter().map(|(_, buf)| buf).collect();
|
||||||
|
received_payloads.sort();
|
||||||
|
let mut expected_payloads = vec![payload0.clone(), payload1.clone(), payload2.clone()];
|
||||||
|
expected_payloads.sort();
|
||||||
|
assert_eq!(received_payloads, expected_payloads);
|
||||||
|
|
||||||
|
let expected_total = (payload0.len() + payload1.len() + payload2.len()) as u64;
|
||||||
|
assert_eq!(report.total_shards, 3);
|
||||||
|
assert_eq!(report.shards[0].shard, 0);
|
||||||
|
assert_eq!(report.shards[0].bytes_sent, payload0.len() as u64);
|
||||||
|
assert_eq!(report.shards[1].shard, 1);
|
||||||
|
assert_eq!(report.shards[1].bytes_sent, 0);
|
||||||
|
assert_eq!(report.shards[2].shard, 2);
|
||||||
|
assert_eq!(report.shards[2].bytes_sent, payload2.len() as u64);
|
||||||
|
assert_eq!(report.total_bytes_sent, expected_total);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
format_ilp_send_report(&report),
|
||||||
|
format!(
|
||||||
|
"curate-etl ilp-send\n ilp_send: shards=3 total_bytes_sent={expected_total} per_shard_bytes=00={},01=0,02={}",
|
||||||
|
payload0.len(),
|
||||||
|
payload2.len()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn run_send_ilp_fails_closed_on_discovery_and_address_errors_with_zero_connections() {
|
||||||
|
let listener = TcpListener::bind("127.0.0.1:0").expect("bind loopback listener");
|
||||||
|
let listen_addr = listener.local_addr().expect("local addr");
|
||||||
|
listener
|
||||||
|
.set_nonblocking(true)
|
||||||
|
.expect("set listener nonblocking");
|
||||||
|
|
||||||
|
let assert_zero_accepts = |label: &str| match listener.accept() {
|
||||||
|
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
|
||||||
|
Ok((_, peer)) => panic!("{label}: unexpectedly accepted connection from {peer}"),
|
||||||
|
Err(err) => panic!("{label}: unexpected accept error: {err}"),
|
||||||
|
};
|
||||||
|
|
||||||
|
// (a) Missing directory -> ReadDir(NotFound), zero connections.
|
||||||
|
let base = TempDirGuard::new("run-send-ilp-fail-closed");
|
||||||
|
let missing_dir = base.path().join("does-not-exist");
|
||||||
|
let err = run_send_ilp(&SendIlpArgs {
|
||||||
|
dir: missing_dir.clone(),
|
||||||
|
prefix: "fx_1m".to_string(),
|
||||||
|
addr: listen_addr.to_string(),
|
||||||
|
})
|
||||||
|
.unwrap_err();
|
||||||
|
assert!(
|
||||||
|
matches!(err, IlpSendError::ReadDir { ref source, .. } if source.kind() == io::ErrorKind::NotFound),
|
||||||
|
"expected ReadDir(NotFound), got {err:?}"
|
||||||
|
);
|
||||||
|
assert_zero_accepts("missing directory");
|
||||||
|
|
||||||
|
// (b) Empty directory -> NoShardFiles, zero connections.
|
||||||
|
let empty_dir = TempDirGuard::new("run-send-ilp-empty");
|
||||||
|
let err = run_send_ilp(&SendIlpArgs {
|
||||||
|
dir: empty_dir.path().to_path_buf(),
|
||||||
|
prefix: "fx_1m".to_string(),
|
||||||
|
addr: listen_addr.to_string(),
|
||||||
|
})
|
||||||
|
.unwrap_err();
|
||||||
|
assert!(
|
||||||
|
matches!(err, IlpSendError::NoShardFiles { .. }),
|
||||||
|
"expected NoShardFiles, got {err:?}"
|
||||||
|
);
|
||||||
|
assert_zero_accepts("empty directory");
|
||||||
|
|
||||||
|
// (c) Discovery failure paired with malformed address -> discovery error takes precedence.
|
||||||
|
let err = run_send_ilp(&SendIlpArgs {
|
||||||
|
dir: empty_dir.path().to_path_buf(),
|
||||||
|
prefix: "fx_1m".to_string(),
|
||||||
|
addr: "not-an-addr".to_string(),
|
||||||
|
})
|
||||||
|
.unwrap_err();
|
||||||
|
assert!(
|
||||||
|
matches!(err, IlpSendError::NoShardFiles { .. }),
|
||||||
|
"expected discovery error before address validation, got {err:?}"
|
||||||
|
);
|
||||||
|
assert_zero_accepts("empty directory with malformed address");
|
||||||
|
|
||||||
|
// (d) Shard gap (00 + 02) -> MissingShardIndex, zero connections.
|
||||||
|
let gap_dir = TempDirGuard::new("run-send-ilp-gap");
|
||||||
|
write_bytes(&gap_dir.path().join("fx_1m.shard-00.ilp"), b"a");
|
||||||
|
write_bytes(&gap_dir.path().join("fx_1m.shard-02.ilp"), b"c");
|
||||||
|
let err = run_send_ilp(&SendIlpArgs {
|
||||||
|
dir: gap_dir.path().to_path_buf(),
|
||||||
|
prefix: "fx_1m".to_string(),
|
||||||
|
addr: listen_addr.to_string(),
|
||||||
|
})
|
||||||
|
.unwrap_err();
|
||||||
|
assert!(
|
||||||
|
matches!(
|
||||||
|
err,
|
||||||
|
IlpSendError::MissingShardIndex {
|
||||||
|
expected: 1,
|
||||||
|
found: 2,
|
||||||
|
..
|
||||||
|
}
|
||||||
|
),
|
||||||
|
"expected MissingShardIndex(1, 2), got {err:?}"
|
||||||
|
);
|
||||||
|
assert_zero_accepts("shard gap");
|
||||||
|
|
||||||
|
// (e) Valid shards + malformed address -> InvalidAddress before any connect.
|
||||||
|
let valid_dir = TempDirGuard::new("run-send-ilp-bad-addr");
|
||||||
|
write_bytes(&valid_dir.path().join("fx_1m.shard-00.ilp"), b"ok");
|
||||||
|
for bad_addr in ["not-an-addr", "127.0.0.1", "127.0.0.1:notaport"] {
|
||||||
|
let err = run_send_ilp(&SendIlpArgs {
|
||||||
|
dir: valid_dir.path().to_path_buf(),
|
||||||
|
prefix: "fx_1m".to_string(),
|
||||||
|
addr: bad_addr.to_string(),
|
||||||
|
})
|
||||||
|
.unwrap_err();
|
||||||
|
assert!(
|
||||||
|
matches!(err, IlpSendError::InvalidAddress { .. }),
|
||||||
|
"expected InvalidAddress for {bad_addr:?}, got {err:?}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
assert_zero_accepts("malformed address");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn run_send_ilp_refused_connection_returns_connect_error_and_zero_partial_report() {
|
||||||
|
let dir = TempDirGuard::new("run-send-ilp-refused");
|
||||||
|
let p0 = dir.path().join("fx_1m.shard-00.ilp");
|
||||||
|
let p1 = dir.path().join("fx_1m.shard-01.ilp");
|
||||||
|
let p2 = dir.path().join("fx_1m.shard-02.ilp");
|
||||||
|
write_bytes(&p0, b"shard0");
|
||||||
|
write_bytes(&p1, b"");
|
||||||
|
write_bytes(&p2, b"shard2");
|
||||||
|
|
||||||
|
let dead = refused_loopback_addr();
|
||||||
|
let err = run_send_ilp(&SendIlpArgs {
|
||||||
|
dir: dir.path().to_path_buf(),
|
||||||
|
prefix: "fx_1m".to_string(),
|
||||||
|
addr: dead.to_string(),
|
||||||
|
})
|
||||||
|
.unwrap_err();
|
||||||
|
|
||||||
|
match err {
|
||||||
|
IlpSendError::ShardIo {
|
||||||
|
op,
|
||||||
|
shard,
|
||||||
|
path,
|
||||||
|
source,
|
||||||
|
partial_report,
|
||||||
|
} => {
|
||||||
|
assert_eq!(op, IlpSendOp::Connect);
|
||||||
|
assert_eq!(shard, 0);
|
||||||
|
assert_eq!(path, p0);
|
||||||
|
assert_eq!(source.kind(), io::ErrorKind::ConnectionRefused);
|
||||||
|
assert_eq!(partial_report.total_shards, 3);
|
||||||
|
assert_eq!(partial_report.total_bytes_sent, 0);
|
||||||
|
assert_eq!(partial_report.shards.len(), 3);
|
||||||
|
for (idx, entry) in partial_report.shards.iter().enumerate() {
|
||||||
|
assert_eq!(entry.shard, idx);
|
||||||
|
assert_eq!(entry.bytes_sent, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
other => panic!("expected ShardIo(Connect), got {other:?}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -158,10 +158,10 @@ pub use ilp::{
|
||||||
FNV1A_64_PRIME, ILP_V2_DOUBLE_TYPE, TABLE_BARS_1M, TABLE_FX_1M,
|
FNV1A_64_PRIME, ILP_V2_DOUBLE_TYPE, TABLE_BARS_1M, TABLE_FX_1M,
|
||||||
};
|
};
|
||||||
pub use ilp_send::{
|
pub use ilp_send::{
|
||||||
discover_ilp_shard_files, format_ilp_send_report, send_ilp_shard_files, tcp_ilp_connector,
|
discover_ilp_shard_files, format_ilp_send_report, run_send_ilp, send_ilp_shard_files,
|
||||||
IlpSendError, IlpSendOp, IlpSendOptions, IlpSendReport, IlpShardFile, IlpShardSendReport,
|
tcp_ilp_connector, IlpSendError, IlpSendOp, IlpSendOptions, IlpSendReport, IlpShardFile,
|
||||||
IlpTcpOptions, IlpTcpSink, DEFAULT_ILP_SEND_BUFFER_BYTES, DEFAULT_ILP_TCP_CONNECT_TIMEOUT,
|
IlpShardSendReport, IlpTcpOptions, IlpTcpSink, SendIlpArgs, DEFAULT_ILP_SEND_BUFFER_BYTES,
|
||||||
DEFAULT_ILP_TCP_WRITE_TIMEOUT,
|
DEFAULT_ILP_TCP_CONNECT_TIMEOUT, DEFAULT_ILP_TCP_WRITE_TIMEOUT,
|
||||||
};
|
};
|
||||||
pub use macro_series::{
|
pub use macro_series::{
|
||||||
build_macro_rows, MacroBuild, MacroBuildStats, MacroError, MacroLagClass, MacroObservation,
|
build_macro_rows, MacroBuild, MacroBuildStats, MacroError, MacroLagClass, MacroObservation,
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ use curate_etl::bench::{
|
||||||
run_shorts_benchmark, run_split_benchmark,
|
run_shorts_benchmark, run_split_benchmark,
|
||||||
};
|
};
|
||||||
use curate_etl::cli::{format_usage, format_usage_stderr, parse_args, CliAction};
|
use curate_etl::cli::{format_usage, format_usage_stderr, parse_args, CliAction};
|
||||||
|
use curate_etl::ilp_send::{format_ilp_send_report, run_send_ilp};
|
||||||
use curate_etl::run_curate_adj::{
|
use curate_etl::run_curate_adj::{
|
||||||
format_curate_adj_report, run_curate_adj_factors, run_curate_adj_factors_fenced,
|
format_curate_adj_report, run_curate_adj_factors, run_curate_adj_factors_fenced,
|
||||||
};
|
};
|
||||||
|
|
@ -230,6 +231,19 @@ fn main() -> ExitCode {
|
||||||
ExitCode::FAILURE
|
ExitCode::FAILURE
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Ok(CliAction::SendIlp(send_args)) => match run_send_ilp(&send_args) {
|
||||||
|
Ok(report) => {
|
||||||
|
println!("{}", format_ilp_send_report(&report));
|
||||||
|
ExitCode::SUCCESS
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("error: {err}");
|
||||||
|
if let Some(partial) = err.partial_report() {
|
||||||
|
eprintln!("{}", format_ilp_send_report(partial));
|
||||||
|
}
|
||||||
|
ExitCode::FAILURE
|
||||||
|
}
|
||||||
|
},
|
||||||
Ok(CliAction::BenchSplit(rows)) => {
|
Ok(CliAction::BenchSplit(rows)) => {
|
||||||
let report = match run_split_benchmark(rows) {
|
let report = match run_split_benchmark(rows) {
|
||||||
Ok(report) => report,
|
Ok(report) => report,
|
||||||
|
|
|
||||||
|
|
@ -1742,3 +1742,133 @@ fn bench_curate_shorts_command_small_run_is_deterministic_and_reports_stages() {
|
||||||
assert_eq!(field(&text_a, "checksum="), field(&text_b, "checksum="));
|
assert_eq!(field(&text_a, "checksum="), field(&text_b, "checksum="));
|
||||||
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
assert_eq!(field(&text_a, "rows_out="), field(&text_b, "rows_out="));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn send_ilp_cli_help_missing_flag_success_and_partial_error_routing() {
|
||||||
|
use std::io::{self, Read};
|
||||||
|
use std::net::TcpListener;
|
||||||
|
use std::thread;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
// 1. --help lists send-ilp, required flags, and delivery caveat.
|
||||||
|
let help = run(&["--help"]);
|
||||||
|
assert!(help.status.success(), "{}", stderr(&help));
|
||||||
|
let help_text = stdout(&help);
|
||||||
|
assert!(help_text.contains("send-ilp"), "{help_text}");
|
||||||
|
assert!(
|
||||||
|
help_text.contains("--dir")
|
||||||
|
&& help_text.contains("--prefix")
|
||||||
|
&& help_text.contains("--addr"),
|
||||||
|
"{help_text}"
|
||||||
|
);
|
||||||
|
assert!(help_text.contains("PGWire"), "{help_text}");
|
||||||
|
assert!(help_text.contains("10.2.0"), "{help_text}");
|
||||||
|
|
||||||
|
// 2. Missing --addr exits non-zero with error + Usage on stderr and empty stdout.
|
||||||
|
let missing_addr = run(&["send-ilp", "--dir", "/tmp/shards", "--prefix", "fx_1m"]);
|
||||||
|
assert!(!missing_addr.status.success());
|
||||||
|
assert_eq!(missing_addr.status.code(), Some(1));
|
||||||
|
assert!(stdout(&missing_addr).is_empty());
|
||||||
|
let missing_err = stderr(&missing_addr);
|
||||||
|
assert!(
|
||||||
|
missing_err.contains("error: missing required flag '--addr'"),
|
||||||
|
"{missing_err}"
|
||||||
|
);
|
||||||
|
assert!(missing_err.contains("Usage:"), "{missing_err}");
|
||||||
|
assert!(missing_err.contains("send-ilp"), "{missing_err}");
|
||||||
|
|
||||||
|
// 3. Binary success path over loopback prints format_ilp_send_report to stdout.
|
||||||
|
let dir = CliTempDir::new("send-ilp-bin");
|
||||||
|
let payload0 = b"fx_1m,pair=USDCAD close=1.38 1700000000000000t\n";
|
||||||
|
let payload1 = b"";
|
||||||
|
write_file(&dir.path.join("fx_1m.shard-00.ilp"), payload0);
|
||||||
|
write_file(&dir.path.join("fx_1m.shard-01.ilp"), payload1);
|
||||||
|
|
||||||
|
let listener = TcpListener::bind("127.0.0.1:0").expect("bind loopback listener");
|
||||||
|
let listen_addr = listener.local_addr().expect("local addr");
|
||||||
|
listener
|
||||||
|
.set_nonblocking(true)
|
||||||
|
.expect("set loopback listener nonblocking");
|
||||||
|
let server = thread::spawn(move || {
|
||||||
|
let deadline = Instant::now() + Duration::from_secs(5);
|
||||||
|
let mut received = Vec::with_capacity(2);
|
||||||
|
for accepted in 0..2 {
|
||||||
|
let mut stream = loop {
|
||||||
|
match listener.accept() {
|
||||||
|
Ok((s, _)) => {
|
||||||
|
s.set_nonblocking(false).expect("set stream blocking");
|
||||||
|
break s;
|
||||||
|
}
|
||||||
|
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {
|
||||||
|
assert!(
|
||||||
|
Instant::now() < deadline,
|
||||||
|
"timed out waiting for connection {accepted}/2"
|
||||||
|
);
|
||||||
|
thread::sleep(Duration::from_millis(5));
|
||||||
|
}
|
||||||
|
Err(err) => panic!("accept failed: {err}"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
stream
|
||||||
|
.set_read_timeout(Some(Duration::from_secs(3)))
|
||||||
|
.expect("set read timeout");
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
stream.read_to_end(&mut buf).expect("read shard to EOF");
|
||||||
|
received.push(buf);
|
||||||
|
}
|
||||||
|
received
|
||||||
|
});
|
||||||
|
|
||||||
|
let ok_out = run(&[
|
||||||
|
"send-ilp",
|
||||||
|
"--dir",
|
||||||
|
dir.path.to_str().unwrap(),
|
||||||
|
"--prefix",
|
||||||
|
"fx_1m",
|
||||||
|
"--addr",
|
||||||
|
&listen_addr.to_string(),
|
||||||
|
]);
|
||||||
|
let mut received = server.join().expect("join server");
|
||||||
|
received.sort();
|
||||||
|
let mut expected_payloads = vec![payload0.to_vec(), payload1.to_vec()];
|
||||||
|
expected_payloads.sort();
|
||||||
|
assert_eq!(received, expected_payloads);
|
||||||
|
|
||||||
|
assert!(ok_out.status.success(), "{}", stderr(&ok_out));
|
||||||
|
assert!(stderr(&ok_out).is_empty(), "{}", stderr(&ok_out));
|
||||||
|
assert_eq!(
|
||||||
|
stdout(&ok_out),
|
||||||
|
format!(
|
||||||
|
"curate-etl ilp-send\n ilp_send: shards=2 total_bytes_sent={} per_shard_bytes=00={},01=0\n",
|
||||||
|
payload0.len(),
|
||||||
|
payload0.len()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 4. Runtime connect failure prints error + formatted partial report to stderr, empty stdout.
|
||||||
|
let dead_listener = TcpListener::bind("127.0.0.1:0").expect("bind ephemeral port");
|
||||||
|
let dead_addr = dead_listener.local_addr().expect("ephemeral addr");
|
||||||
|
drop(dead_listener);
|
||||||
|
|
||||||
|
let fail_out = run(&[
|
||||||
|
"send-ilp",
|
||||||
|
"--dir",
|
||||||
|
dir.path.to_str().unwrap(),
|
||||||
|
"--prefix",
|
||||||
|
"fx_1m",
|
||||||
|
"--addr",
|
||||||
|
&dead_addr.to_string(),
|
||||||
|
]);
|
||||||
|
assert!(!fail_out.status.success());
|
||||||
|
assert_eq!(fail_out.status.code(), Some(1));
|
||||||
|
assert!(stdout(&fail_out).is_empty());
|
||||||
|
let fail_err = stderr(&fail_out);
|
||||||
|
assert!(fail_err.contains("error: ILP shard 0"), "{fail_err}");
|
||||||
|
assert!(
|
||||||
|
fail_err.contains(
|
||||||
|
"curate-etl ilp-send\n ilp_send: shards=2 total_bytes_sent=0 per_shard_bytes=00=0,01=0"
|
||||||
|
),
|
||||||
|
"{fail_err}"
|
||||||
|
);
|
||||||
|
assert!(!fail_err.contains("Usage:"), "{fail_err}");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue