noxu-rep 5.0.0

Replication and high availability for Noxu DB
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
//! VLSN range tracking.
//!
//! Tracks the range of
//! VLSNs available on this node, including the first and last VLSN in the
//! contiguous range, as well as the last committed and last synced VLSNs.

use noxu_log::LogEntryType;

/// Tracks the range of VLSNs available on this node.
///
/// All range values must be viewed together to ensure a consistent set of
/// values. A VLSN value of 0 is treated as NULL/empty (equivalent to the
/// `VLSN.NULL_VLSN`).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VlsnRange {
    /// First available VLSN (inclusive). 0 means empty.
    first: u64,
    /// Last available VLSN (inclusive). 0 means empty.
    last: u64,
    /// `lastTxnEnd` (JE VLSNRange.lastTxnEnd): the highest VLSN of a
    /// commit/abort log entry. This is the rollback safety boundary used by
    /// the syncup `verifyRollback` decision (a replica must not roll back
    /// past a transaction end it has acknowledged). NOT the same as the sync
    /// matchpoint — see `sync_vlsn`.
    commit_vlsn: u64,
    /// `lastSync` (JE VLSNRange.lastSync): the highest VLSN of a sync-point
    /// log entry. This is the initial matchpoint candidate in
    /// `ReplicaFeederSyncup.findMatchpoint`. JE notes lastSync and lastTxnEnd
    /// are currently the same value but are kept distinct because the
    /// Matchpoint log entry may make lastSync run ahead of lastTxnEnd.
    sync_vlsn: u64,
}

impl Default for VlsnRange {
    fn default() -> Self {
        Self::new()
    }
}

impl VlsnRange {
    /// Create an empty range with all fields set to 0 (NULL_VLSN).
    pub fn new() -> Self {
        VlsnRange { first: 0, last: 0, commit_vlsn: 0, sync_vlsn: 0 }
    }

    /// Create a range with the given first and last VLSNs.
    /// The commit and sync VLSNs are initialized to 0.
    pub fn with_range(first: u64, last: u64) -> Self {
        assert!(
            first == 0 || first <= last,
            "first ({}) must be <= last ({})",
            first,
            last
        );
        VlsnRange { first, last, commit_vlsn: 0, sync_vlsn: 0 }
    }

    /// Return the first available VLSN (inclusive).
    pub fn get_first(&self) -> u64 {
        self.first
    }

    /// Return the last available VLSN (inclusive).
    pub fn get_last(&self) -> u64 {
        self.last
    }

    /// Return `lastTxnEnd`: the highest commit/abort VLSN (rollback boundary).
    pub fn get_commit_vlsn(&self) -> u64 {
        self.commit_vlsn
    }

    /// JE-faithful alias for `get_commit_vlsn` (JE VLSNRange.getLastTxnEnd).
    pub fn get_last_txn_end(&self) -> u64 {
        self.commit_vlsn
    }

    /// Return `lastSync`: the highest sync-point VLSN (matchpoint candidate).
    pub fn get_sync_vlsn(&self) -> u64 {
        self.sync_vlsn
    }

    /// JE-faithful alias for `get_sync_vlsn` (JE VLSNRange.getLastSync).
    pub fn get_last_sync(&self) -> u64 {
        self.sync_vlsn
    }

    /// Alias for `get_first`  -  return the first available VLSN.
    pub fn first(&self) -> u64 {
        self.first
    }

    /// Alias for `get_last`  -  return the last available VLSN.
    pub fn last(&self) -> u64 {
        self.last
    }

    /// Return true if this range is empty (first == 0).
    pub fn is_empty(&self) -> bool {
        self.first == 0
    }

    /// Return true if this VLSN is within the range described by this struct.
    ///
    ///
    pub fn contains(&self, vlsn: u64) -> bool {
        if self.first == 0 {
            return false;
        }
        self.first <= vlsn && vlsn <= self.last
    }

    /// Return the number of VLSNs in this range.
    /// Returns 0 if the range is empty.
    pub fn len(&self) -> u64 {
        if self.first == 0 {
            return 0;
        }
        self.last - self.first + 1
    }

    /// Extend the range to include a new VLSN.
    ///
    /// If the range is empty, the VLSN becomes both first and last.
    /// Otherwise, first is updated if the new VLSN is smaller, and last
    /// is updated if the new VLSN is larger.
    ///
    ///
    ///
    /// Note: does not track per-entry-type commit/barrier VLSNs (those are
    /// managed by `VlsnIndex` at a higher level).
    pub fn extend(&mut self, vlsn: u64) {
        assert!(vlsn > 0, "Cannot extend with NULL_VLSN (0)");
        if self.first == 0 || vlsn < self.first {
            self.first = vlsn;
        }
        if vlsn > self.last {
            self.last = vlsn;
        }
    }

    /// Update `lastTxnEnd` (the commit/abort boundary).
    ///
    /// Advances forward only; a VLSN below the current value is a no-op.
    pub fn update_commit(&mut self, vlsn: u64) {
        if vlsn > self.commit_vlsn {
            self.commit_vlsn = vlsn;
        }
    }

    /// Update `lastSync` (the sync-point matchpoint candidate).
    ///
    /// Advances forward only; a VLSN below the current value is a no-op.
    pub fn update_sync(&mut self, vlsn: u64) {
        if vlsn > self.sync_vlsn {
            self.sync_vlsn = vlsn;
        }
    }

    /// JE-faithful update: extend the range for a new (vlsn, entry-type)
    /// mapping, dispatching `lastSync`/`lastTxnEnd` by entry type.
    ///
    /// Mirrors `VLSNRange.getUpdateForNewMapping` (VLSNRange.java:162-190):
    ///   - always extend `first`/`last`;
    ///   - if `entry_type.is_sync_point()` advance `lastSync` (`sync_vlsn`);
    ///   - if the entry is a commit or abort advance `lastTxnEnd`
    ///     (`commit_vlsn`).
    ///
    /// This is the canonical path that keeps `lastSync` and `lastTxnEnd`
    /// distinct as JE intends; the syncup matchpoint protocol (the consumer)
    /// is tracked separately as a parity gap.
    pub fn update_for_new_mapping(
        &mut self,
        vlsn: u64,
        entry_type: LogEntryType,
    ) {
        self.extend(vlsn);
        if entry_type.is_sync_point() && vlsn > self.sync_vlsn {
            self.sync_vlsn = vlsn;
        }
        if matches!(
            entry_type,
            LogEntryType::TxnCommit | LogEntryType::TxnAbort
        ) && vlsn > self.commit_vlsn
        {
            self.commit_vlsn = vlsn;
        }
    }

    /// Truncate VLSNs after the given value (for rollback).
    ///
    /// Sets the last VLSN to the given value. If the truncation point is
    /// before the first VLSN, the range becomes empty. The commit and sync
    /// VLSNs are clamped to the new last VLSN.
    ///
    ///
    pub fn truncate_after(&mut self, vlsn: u64) {
        if vlsn == 0 || (self.first > 0 && vlsn < self.first) {
            // Truncation point is before the range start; empty the range.
            self.first = 0;
            self.last = 0;
            self.commit_vlsn = 0;
            self.sync_vlsn = 0;
            return;
        }
        if self.first == 0 {
            // Already empty, nothing to truncate.
            return;
        }
        self.last = vlsn;
        // Clamp commit and sync to new last.
        if self.commit_vlsn > vlsn {
            self.commit_vlsn = vlsn;
        }
        if self.sync_vlsn > vlsn {
            self.sync_vlsn = vlsn;
        }
    }

    /// Merge with another range (union).
    ///
    /// The resulting range spans the union of both ranges. The commit and
    /// sync VLSNs are set to the maximum of the two ranges. NULL (0) values
    /// are handled: a non-null value always takes precedence over null.
    ///
    /// And `VLSNRange.getUpdate()`.
    pub fn merge(&mut self, other: &VlsnRange) {
        // Merge first: take the smaller non-zero value.
        self.first = match (self.first, other.first) {
            (0, b) => b,
            (a, 0) => a,
            (a, b) => a.min(b),
        };
        // Merge last: take the larger non-zero value.
        self.last = match (self.last, other.last) {
            (0, b) => b,
            (a, 0) => a,
            (a, b) => a.max(b),
        };
        // Merge commit_vlsn: take the larger non-zero value.
        self.commit_vlsn = match (self.commit_vlsn, other.commit_vlsn) {
            (0, b) => b,
            (a, 0) => a,
            (a, b) => a.max(b),
        };
        // Merge sync_vlsn: take the larger non-zero value.
        self.sync_vlsn = match (self.sync_vlsn, other.sync_vlsn) {
            (0, b) => b,
            (a, 0) => a,
            (a, b) => a.max(b),
        };
    }
}

impl std::fmt::Display for VlsnRange {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "first={} last={} commit={} sync={}",
            self.first, self.last, self.commit_vlsn, self.sync_vlsn
        )
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_update_for_new_mapping_dispatch() {
        use noxu_log::LogEntryType;
        let mut r = VlsnRange::new();
        // A non-txn insert LN: extends first/last only, leaves lastSync /
        // lastTxnEnd at 0.
        r.update_for_new_mapping(5, LogEntryType::InsertLN);
        assert_eq!(r.get_last(), 5);
        assert_eq!(r.get_last_sync(), 0, "InsertLN is not a sync point");
        assert_eq!(r.get_last_txn_end(), 0, "InsertLN is not a commit/abort");
        // A commit: advances BOTH lastTxnEnd and lastSync (commit is a sync
        // point in JE — is_sync_point() includes TxnCommit).
        r.update_for_new_mapping(8, LogEntryType::TxnCommit);
        assert_eq!(r.get_last(), 8);
        assert_eq!(r.get_last_txn_end(), 8, "commit advances lastTxnEnd");
        assert_eq!(r.get_last_sync(), 8, "commit is a sync point -> lastSync");
        // A Matchpoint at 12: a sync point but NOT a commit/abort, so lastSync
        // runs AHEAD of lastTxnEnd (the exact JE scenario the two distinct
        // fields exist for).
        r.update_for_new_mapping(12, LogEntryType::Matchpoint);
        assert_eq!(r.get_last_sync(), 12, "matchpoint advances lastSync");
        assert_eq!(
            r.get_last_txn_end(),
            8,
            "matchpoint is not a txn end -> lastTxnEnd unchanged"
        );
    }

    #[test]
    fn test_new_empty() {
        let range = VlsnRange::new();
        assert!(range.is_empty());
        assert_eq!(range.get_first(), 0);
        assert_eq!(range.get_last(), 0);
        assert_eq!(range.get_commit_vlsn(), 0);
        assert_eq!(range.get_sync_vlsn(), 0);
        assert_eq!(range.len(), 0);
    }

    #[test]
    fn test_with_range() {
        let range = VlsnRange::with_range(5, 10);
        assert!(!range.is_empty());
        assert_eq!(range.get_first(), 5);
        assert_eq!(range.get_last(), 10);
        assert_eq!(range.len(), 6);
    }

    #[test]
    fn test_with_range_single() {
        let range = VlsnRange::with_range(7, 7);
        assert!(!range.is_empty());
        assert_eq!(range.len(), 1);
    }

    #[test]
    fn test_contains() {
        let range = VlsnRange::with_range(5, 10);
        assert!(!range.contains(4));
        assert!(range.contains(5));
        assert!(range.contains(7));
        assert!(range.contains(10));
        assert!(!range.contains(11));
    }

    #[test]
    fn test_contains_empty() {
        let range = VlsnRange::new();
        assert!(!range.contains(0));
        assert!(!range.contains(1));
        assert!(!range.contains(100));
    }

    #[test]
    fn test_extend_from_empty() {
        let mut range = VlsnRange::new();
        range.extend(5);
        assert!(!range.is_empty());
        assert_eq!(range.get_first(), 5);
        assert_eq!(range.get_last(), 5);
        assert_eq!(range.len(), 1);
    }

    #[test]
    fn test_extend_forward() {
        let mut range = VlsnRange::with_range(5, 10);
        range.extend(15);
        assert_eq!(range.get_first(), 5);
        assert_eq!(range.get_last(), 15);
        assert_eq!(range.len(), 11);
    }

    #[test]
    fn test_extend_backward() {
        let mut range = VlsnRange::with_range(5, 10);
        range.extend(2);
        assert_eq!(range.get_first(), 2);
        assert_eq!(range.get_last(), 10);
    }

    #[test]
    fn test_extend_within() {
        let mut range = VlsnRange::with_range(5, 10);
        range.extend(7);
        assert_eq!(range.get_first(), 5);
        assert_eq!(range.get_last(), 10);
    }

    #[test]
    fn test_commit_vlsn() {
        let mut range = VlsnRange::with_range(1, 10);
        assert_eq!(range.get_commit_vlsn(), 0);
        range.update_commit(5);
        assert_eq!(range.get_commit_vlsn(), 5);
        range.update_commit(8);
        assert_eq!(range.get_commit_vlsn(), 8);
        // Commit VLSN should not go backwards.
        range.update_commit(3);
        assert_eq!(range.get_commit_vlsn(), 8);
    }

    #[test]
    fn test_sync_vlsn() {
        let mut range = VlsnRange::with_range(1, 10);
        assert_eq!(range.get_sync_vlsn(), 0);
        range.update_sync(4);
        assert_eq!(range.get_sync_vlsn(), 4);
        range.update_sync(9);
        assert_eq!(range.get_sync_vlsn(), 9);
        // Sync VLSN should not go backwards.
        range.update_sync(2);
        assert_eq!(range.get_sync_vlsn(), 9);
    }

    #[test]
    fn test_truncate_after_middle() {
        let mut range = VlsnRange::with_range(5, 20);
        range.update_commit(15);
        range.update_sync(18);
        range.truncate_after(12);
        assert_eq!(range.get_first(), 5);
        assert_eq!(range.get_last(), 12);
        assert_eq!(range.get_commit_vlsn(), 12);
        assert_eq!(range.get_sync_vlsn(), 12);
        assert_eq!(range.len(), 8);
    }

    #[test]
    fn test_truncate_after_before_first() {
        let mut range = VlsnRange::with_range(5, 10);
        range.truncate_after(3);
        assert!(range.is_empty());
        assert_eq!(range.len(), 0);
    }

    #[test]
    fn test_truncate_after_at_last() {
        let mut range = VlsnRange::with_range(5, 10);
        range.truncate_after(10);
        assert_eq!(range.get_first(), 5);
        assert_eq!(range.get_last(), 10);
        assert_eq!(range.len(), 6);
    }

    #[test]
    fn test_truncate_empty() {
        let mut range = VlsnRange::new();
        range.truncate_after(5);
        assert!(range.is_empty());
    }

    #[test]
    fn test_truncate_to_zero() {
        let mut range = VlsnRange::with_range(1, 10);
        range.update_commit(5);
        range.update_sync(7);
        range.truncate_after(0);
        assert!(range.is_empty());
        assert_eq!(range.get_commit_vlsn(), 0);
        assert_eq!(range.get_sync_vlsn(), 0);
    }

    #[test]
    fn test_merge_both_non_empty() {
        let mut range_a = VlsnRange::with_range(5, 10);
        range_a.update_commit(8);
        range_a.update_sync(7);

        let mut range_b = VlsnRange::with_range(8, 15);
        range_b.update_commit(12);
        range_b.update_sync(14);

        range_a.merge(&range_b);
        assert_eq!(range_a.get_first(), 5);
        assert_eq!(range_a.get_last(), 15);
        assert_eq!(range_a.get_commit_vlsn(), 12);
        assert_eq!(range_a.get_sync_vlsn(), 14);
    }

    #[test]
    fn test_merge_with_empty() {
        let mut range_a = VlsnRange::with_range(5, 10);
        range_a.update_commit(8);
        let range_b = VlsnRange::new();

        range_a.merge(&range_b);
        assert_eq!(range_a.get_first(), 5);
        assert_eq!(range_a.get_last(), 10);
        assert_eq!(range_a.get_commit_vlsn(), 8);
    }

    #[test]
    fn test_merge_empty_with_non_empty() {
        let mut range_a = VlsnRange::new();
        let mut range_b = VlsnRange::with_range(3, 7);
        range_b.update_commit(5);

        range_a.merge(&range_b);
        assert_eq!(range_a.get_first(), 3);
        assert_eq!(range_a.get_last(), 7);
        assert_eq!(range_a.get_commit_vlsn(), 5);
    }

    #[test]
    fn test_merge_disjoint_ranges() {
        let mut range_a = VlsnRange::with_range(1, 5);
        let range_b = VlsnRange::with_range(10, 15);

        range_a.merge(&range_b);
        assert_eq!(range_a.get_first(), 1);
        assert_eq!(range_a.get_last(), 15);
    }

    #[test]
    fn test_display() {
        let mut range = VlsnRange::with_range(1, 10);
        range.update_commit(5);
        range.update_sync(8);
        let s = format!("{}", range);
        assert!(s.contains("first=1"));
        assert!(s.contains("last=10"));
        assert!(s.contains("commit=5"));
        assert!(s.contains("sync=8"));
    }

    #[test]
    fn test_default() {
        let range = VlsnRange::default();
        assert!(range.is_empty());
    }

    #[test]
    fn test_clone_eq() {
        let mut range = VlsnRange::with_range(1, 10);
        range.update_commit(5);
        range.update_sync(8);
        let cloned = range.clone();
        assert_eq!(range, cloned);
    }

    // -------------------------------------------------------------------------
    // Ported from VLSNConsistencyTest.java — ordering invariants
    // -------------------------------------------------------------------------

    /// The commit VLSN must never exceed the last VLSN in the range.
    /// Ported from VLSNConsistencyTest — VLSN ordering invariant.
    #[test]
    fn test_commit_vlsn_le_last() {
        let mut range = VlsnRange::with_range(1, 20);
        range.update_commit(20);
        assert!(range.get_commit_vlsn() <= range.get_last());

        // A commit beyond last must be rejected (update_commit only advances
        // within the range semantics — but the invariant is enforced by
        // callers; here we verify that truncation clamps it).
        range.truncate_after(15);
        assert!(
            range.get_commit_vlsn() <= range.get_last(),
            "commit vlsn must be clamped after truncation"
        );
    }

    /// The sync VLSN must never exceed the last VLSN in the range.
    #[test]
    fn test_sync_vlsn_le_last() {
        let mut range = VlsnRange::with_range(1, 20);
        range.update_sync(18);
        range.truncate_after(12);
        assert!(
            range.get_sync_vlsn() <= range.get_last(),
            "sync vlsn must be clamped after truncation"
        );
    }

    /// After any number of extend() calls, first must remain <= last.
    #[test]
    fn test_extend_maintains_first_le_last() {
        let mut range = VlsnRange::new();
        for v in [10u64, 3, 20, 7, 15, 1, 25] {
            range.extend(v);
            assert!(
                range.get_first() <= range.get_last(),
                "first <= last violated after extend({})",
                v
            );
        }
        assert_eq!(range.get_first(), 1);
        assert_eq!(range.get_last(), 25);
    }

    /// Truncation to a point within the range preserves first <= last.
    #[test]
    fn test_truncate_preserves_first_le_last() {
        for last in 1u64..=20 {
            let mut range = VlsnRange::with_range(1, 20);
            range.truncate_after(last);
            if !range.is_empty() {
                assert!(
                    range.get_first() <= range.get_last(),
                    "first <= last violated when truncate_after({})",
                    last
                );
            }
        }
    }

    /// Merging two ranges always yields first <= last (if non-empty).
    #[test]
    fn test_merge_maintains_first_le_last() {
        let cases: &[(u64, u64, u64, u64)] =
            &[(1, 10, 5, 15), (5, 5, 5, 5), (1, 1, 100, 100), (3, 7, 1, 4)];
        for &(af, al, bf, bl) in cases {
            let mut a = VlsnRange::with_range(af, al);
            let b = VlsnRange::with_range(bf, bl);
            a.merge(&b);
            assert!(
                a.get_first() <= a.get_last(),
                "first <= last violated after merge ({},{}) + ({},{})",
                af,
                al,
                bf,
                bl
            );
        }
    }

    /// Commit VLSN must never move backwards (monotonically non-decreasing).
    #[test]
    fn test_commit_vlsn_monotone() {
        let mut range = VlsnRange::with_range(1, 100);
        let updates = [5u64, 10, 8, 20, 15, 30];
        let mut prev = 0u64;
        for &v in &updates {
            range.update_commit(v);
            let current = range.get_commit_vlsn();
            assert!(current >= prev, "commit vlsn must not decrease");
            prev = current;
        }
    }

    /// Sync VLSN must never move backwards.
    #[test]
    fn test_sync_vlsn_monotone() {
        let mut range = VlsnRange::with_range(1, 100);
        let updates = [3u64, 12, 7, 25, 18, 40];
        let mut prev = 0u64;
        for &v in &updates {
            range.update_sync(v);
            let current = range.get_sync_vlsn();
            assert!(current >= prev, "sync vlsn must not decrease");
            prev = current;
        }
    }

    /// An empty range contains no vlsn.
    #[test]
    fn test_empty_range_contains_nothing() {
        let range = VlsnRange::new();
        for v in [0u64, 1, 100, u64::MAX / 2] {
            assert!(!range.contains(v));
        }
    }

    /// Verify that the length formula is always correct relative to
    /// first and last.
    #[test]
    fn test_len_formula() {
        let cases: &[(u64, u64)] = &[(1, 1), (1, 10), (5, 20), (100, 100)];
        for &(f, l) in cases {
            let range = VlsnRange::with_range(f, l);
            assert_eq!(
                range.len(),
                l - f + 1,
                "len mismatch for ({},{})",
                f,
                l
            );
        }
        assert_eq!(VlsnRange::new().len(), 0);
    }
}