()
| 339 | |
| 340 | #[test] |
| 341 | fn test_rollback_order() { |
| 342 | let txn_id = TransactionId::new(); |
| 343 | let mut log = TransactionLog::new(txn_id); |
| 344 | |
| 345 | // Log operations in order: insert, update, delete |
| 346 | log.log_operation(UndoOperation::InsertNode { |
| 347 | graph_path: "/test_graph".to_string(), |
| 348 | node_id: "node1".to_string(), |
| 349 | }); |
| 350 | log.log_operation(UndoOperation::UpdateNode { |
| 351 | graph_path: "/test_graph".to_string(), |
| 352 | node_id: "node1".to_string(), |
| 353 | old_properties: HashMap::new(), |
| 354 | old_labels: vec![], |
| 355 | }); |
| 356 | log.log_operation(UndoOperation::DeleteNode { |
| 357 | graph_path: "/test_graph".to_string(), |
| 358 | node_id: "node1".to_string(), |
| 359 | deleted_node: Node { |
| 360 | id: "node1".to_string(), |
| 361 | labels: vec![], |
| 362 | properties: HashMap::new(), |
| 363 | }, |
| 364 | }); |
| 365 | |
| 366 | // Rollback should be in reverse order: delete, update, insert |
| 367 | let rollback_ops: Vec<_> = log.get_rollback_operations().collect(); |
| 368 | assert_eq!(rollback_ops.len(), 3); |
| 369 | |
| 370 | match rollback_ops[0] { |
| 371 | UndoOperation::DeleteNode { |
| 372 | graph_path, |
| 373 | node_id, |
| 374 | .. |
| 375 | } => { |
| 376 | assert_eq!(graph_path, "/test_graph"); |
| 377 | assert_eq!(node_id, "node1"); |
| 378 | } |
| 379 | _ => panic!("Expected DeleteNode operation first"), |
| 380 | } |
| 381 | match rollback_ops[1] { |
| 382 | UndoOperation::UpdateNode { |
| 383 | graph_path, |
| 384 | node_id, |
| 385 | .. |
| 386 | } => { |
| 387 | assert_eq!(graph_path, "/test_graph"); |
| 388 | assert_eq!(node_id, "node1"); |
| 389 | } |
| 390 | _ => panic!("Expected UpdateNode operation second"), |
| 391 | } |
| 392 | match rollback_ops[2] { |
| 393 | UndoOperation::InsertNode { |
| 394 | graph_path, |
| 395 | node_id, |
| 396 | } => { |
| 397 | assert_eq!(graph_path, "/test_graph"); |
| 398 | assert_eq!(node_id, "node1"); |
nothing calls this directly
no test coverage detected