| 298 | |
| 299 | #[test] |
| 300 | fn test_multiple_consecutive_ops() { |
| 301 | let dir = tempdir().unwrap(); |
| 302 | let version = 0; |
| 303 | |
| 304 | let entries: Vec<VectorOp> = (0..10) |
| 305 | .map(|i| { |
| 306 | if i % 2 == 0 { |
| 307 | VectorOp::Upsert(vec![random_vector()]) |
| 308 | } else { |
| 309 | VectorOp::Delete(VectorId::from(random_string(8))) |
| 310 | } |
| 311 | }) |
| 312 | .collect(); |
| 313 | |
| 314 | let mut wal = DurableWALFile::new(dir.path(), VersionNumber::from(version)).unwrap(); |
| 315 | for op in &entries { |
| 316 | wal.append(op.clone()).unwrap(); |
| 317 | } |
| 318 | wal.flush().unwrap(); |
| 319 | |
| 320 | let wal = WALFile::from_existing(dir.path(), VersionNumber::from(version)).unwrap(); |
| 321 | let mut ops = Vec::new(); |
| 322 | while let Some(op) = wal.read().unwrap() { |
| 323 | ops.push(op); |
| 324 | } |
| 325 | assert_eq!(ops.len(), entries.len()); |
| 326 | |
| 327 | for (expected, actual) in entries.iter().zip(ops.iter()) { |
| 328 | match (expected, actual) { |
| 329 | (VectorOp::Upsert(ev), VectorOp::Upsert(rv)) => assert_eq!(ev[0].id, rv[0].id), |
| 330 | (VectorOp::Delete(eid), VectorOp::Delete(rid)) => assert_eq!(eid, rid), |
| 331 | _ => panic!("Mismatched operation types"), |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | #[test] |
| 337 | fn test_durability() { |