| 537 | |
| 538 | #[test] |
| 539 | fn segment_index_basic() { |
| 540 | use super::super::segment_index::SegmentIndex; |
| 541 | use nodedb_types::timeseries::{SegmentKind, SegmentRef, TimeRange}; |
| 542 | |
| 543 | let mut idx = SegmentIndex::new(); |
| 544 | idx.add( |
| 545 | 1, |
| 546 | SegmentRef { |
| 547 | path: "seg1.bin".into(), |
| 548 | min_ts: 1000, |
| 549 | max_ts: 2000, |
| 550 | kind: SegmentKind::Metric, |
| 551 | size_bytes: 4096, |
| 552 | created_at_ms: 0, |
| 553 | }, |
| 554 | ); |
| 555 | idx.add( |
| 556 | 1, |
| 557 | SegmentRef { |
| 558 | path: "seg2.bin".into(), |
| 559 | min_ts: 3000, |
| 560 | max_ts: 4000, |
| 561 | kind: SegmentKind::Metric, |
| 562 | size_bytes: 8192, |
| 563 | created_at_ms: 0, |
| 564 | }, |
| 565 | ); |
| 566 | |
| 567 | let hits = idx.query(1, &TimeRange::new(1500, 2500)); |
| 568 | assert_eq!(hits.len(), 1); |
| 569 | assert_eq!(hits[0].path, "seg1.bin"); |
| 570 | |
| 571 | let all = idx.query(1, &TimeRange::new(0, 5000)); |
| 572 | assert_eq!(all.len(), 2); |
| 573 | |
| 574 | assert_eq!(idx.total_segments(), 2); |
| 575 | assert_eq!(idx.total_bytes(), 4096 + 8192); |
| 576 | } |
| 577 | } |