| 175 | use tempfile::TempDir; |
| 176 | |
| 177 | fn setup_test_data(dir: &TempDir) -> (SegmentIndex, DictionaryRegistry) { |
| 178 | let config = BucketConfig { |
| 179 | l1_dir: dir.path().join("l1"), |
| 180 | l2_dir: dir.path().join("l2"), |
| 181 | ..Default::default() |
| 182 | }; |
| 183 | let mut mgr = BucketManager::new(config); |
| 184 | |
| 185 | // Create metric segments for series 1. |
| 186 | let mut enc1 = GorillaEncoder::new(); |
| 187 | for i in 0..50 { |
| 188 | enc1.encode(1000 + i * 100, 10.0 + i as f64 * 0.5); |
| 189 | } |
| 190 | |
| 191 | let mut enc2 = GorillaEncoder::new(); |
| 192 | for i in 0..50 { |
| 193 | enc2.encode(6000 + i * 100, 50.0 + i as f64 * 0.3); |
| 194 | } |
| 195 | |
| 196 | let flushed = vec![ |
| 197 | FlushedSeries { |
| 198 | series_id: 1, |
| 199 | kind: FlushedKind::Metric { |
| 200 | gorilla_block: enc1.finish(), |
| 201 | sample_count: 50, |
| 202 | }, |
| 203 | min_ts: 1000, |
| 204 | max_ts: 5900, |
| 205 | }, |
| 206 | FlushedSeries { |
| 207 | series_id: 1, |
| 208 | kind: FlushedKind::Metric { |
| 209 | gorilla_block: enc2.finish(), |
| 210 | sample_count: 50, |
| 211 | }, |
| 212 | min_ts: 6000, |
| 213 | max_ts: 10900, |
| 214 | }, |
| 215 | ]; |
| 216 | |
| 217 | mgr.flush_to_l1(flushed, None).unwrap(); |
| 218 | |
| 219 | // Clone the segment index (we need it after mgr is consumed). |
| 220 | let idx = { |
| 221 | let mut idx = SegmentIndex::new(); |
| 222 | // Re-read from disk to get accurate segment refs. |
| 223 | for seg in mgr.segment_index().query(1, &TimeRange::new(0, i64::MAX)) { |
| 224 | idx.add(1, seg.clone()); |
| 225 | } |
| 226 | idx |
| 227 | }; |
| 228 | |
| 229 | (idx, DictionaryRegistry::new()) |
| 230 | } |
| 231 | |
| 232 | #[test] |
| 233 | fn scan_metrics_full_range() { |