| 433 | } |
| 434 | |
| 435 | fn write_test_metric_segment(dir: &Path, samples: &[(i64, f64)]) -> std::path::PathBuf { |
| 436 | let mut encoder = GorillaEncoder::new(); |
| 437 | for &(ts, val) in samples { |
| 438 | encoder.encode(ts, val); |
| 439 | } |
| 440 | let gorilla_block = encoder.finish(); |
| 441 | |
| 442 | let path = dir.join("test-metric.seg"); |
| 443 | let mut buf = make_tseg_header(); |
| 444 | buf.push(KIND_METRIC); |
| 445 | buf.extend_from_slice(&(samples.len() as u64).to_le_bytes()); |
| 446 | buf.extend_from_slice(&(gorilla_block.len() as u32).to_le_bytes()); |
| 447 | buf.extend_from_slice(&gorilla_block); |
| 448 | std::fs::write(&path, &buf).unwrap(); |
| 449 | path |
| 450 | } |
| 451 | |
| 452 | #[test] |
| 453 | fn read_metric_segment_roundtrip() { |