| 361 | |
| 362 | #[test] |
| 363 | fn replay_after_close() { |
| 364 | let dir = tempfile::tempdir().unwrap(); |
| 365 | let wal_dir = dir.path().join("wal"); |
| 366 | |
| 367 | // Write records. |
| 368 | { |
| 369 | let mut wal = SegmentedWal::open(test_config(&wal_dir)).unwrap(); |
| 370 | wal.append(RecordType::Put as u32, 1, 0, 0, b"first") |
| 371 | .unwrap(); |
| 372 | wal.append(RecordType::Delete as u32, 2, 1, 0, b"second") |
| 373 | .unwrap(); |
| 374 | wal.append(RecordType::Put as u32, 1, 0, 0, b"third") |
| 375 | .unwrap(); |
| 376 | wal.sync().unwrap(); |
| 377 | } |
| 378 | |
| 379 | // Reopen and replay. |
| 380 | let wal = SegmentedWal::open(test_config(&wal_dir)).unwrap(); |
| 381 | let records = wal.replay().unwrap(); |
| 382 | assert_eq!(records.len(), 3); |
| 383 | assert_eq!(records[0].payload, b"first"); |
| 384 | assert_eq!(records[1].payload, b"second"); |
| 385 | assert_eq!(records[2].payload, b"third"); |
| 386 | assert_eq!(wal.next_lsn(), 4); |
| 387 | } |
| 388 | |
| 389 | #[test] |
| 390 | fn automatic_segment_rollover() { |