use noxu_log::LogEntryType;
use noxu_rep::vlsn::VlsnIndex;
#[test]
fn test_typed_registration_advances_sync_and_commit() {
let index = VlsnIndex::new(10);
index.put_with_type(1, 0, 100, LogEntryType::InsertLN);
let r = index.get_range();
assert_eq!(r.get_last(), 1);
assert_eq!(r.get_sync_vlsn(), 0, "InsertLN is not a sync point");
assert_eq!(r.get_commit_vlsn(), 0, "InsertLN is not a commit/abort");
index.put_with_type(2, 0, 200, LogEntryType::Matchpoint);
let r = index.get_range();
assert_eq!(r.get_sync_vlsn(), 2, "matchpoint must advance sync_vlsn");
assert_eq!(
r.get_commit_vlsn(),
0,
"matchpoint is not a txn end -> commit_vlsn unchanged"
);
index.put_with_type(3, 0, 300, LogEntryType::TxnCommit);
let r = index.get_range();
assert_eq!(r.get_commit_vlsn(), 3, "commit must advance commit_vlsn");
assert_eq!(r.get_sync_vlsn(), 3, "commit is a sync point -> sync_vlsn");
let extend_only = VlsnIndex::new(10);
extend_only.put(1, 0, 100);
extend_only.put(2, 0, 200);
extend_only.put(3, 0, 300);
let er = extend_only.get_range();
assert_eq!(er.get_last(), 3, "extend-only still tracks first/last");
assert_eq!(
er.get_sync_vlsn(),
0,
"extend-only NEVER advances sync_vlsn (the bug)"
);
assert_eq!(
er.get_commit_vlsn(),
0,
"extend-only NEVER advances commit_vlsn (the bug)"
);
}
#[test]
fn test_sync_runs_ahead_of_txn_end() {
let index = VlsnIndex::new(10);
index.put_with_type(1, 0, 10, LogEntryType::TxnCommit);
index.put_with_type(2, 0, 20, LogEntryType::Matchpoint);
let r = index.get_range();
assert_eq!(r.get_commit_vlsn(), 1, "commit at vlsn 1");
assert_eq!(r.get_sync_vlsn(), 2, "matchpoint runs sync ahead to vlsn 2");
}