MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / test_reinsert_change

Function test_reinsert_change

atomic-core/src/pristine/txn/write/tests.rs:509–550  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

507
508 #[test]
509 fn test_reinsert_change() {
510 let dir = tempdir().unwrap();
511 let db_path = dir.path().join("pristine");
512 let pristine = Pristine::open(&db_path).unwrap();
513
514 let mut txn = pristine.write_txn().unwrap();
515
516 // Create a view with 2 changes
517 let mut view = txn.open_or_create_view("test").unwrap();
518
519 let hash1 = Hash::of(b"change 1");
520 let hash2 = Hash::of(b"change 2");
521 let hash3 = Hash::of(b"change 3");
522
523 let id1 = txn.register_change(&hash1).unwrap();
524 let id2 = txn.register_change(&hash2).unwrap();
525 let id3 = txn.register_change(&hash3).unwrap();
526
527 txn.put_change(&mut view, id1, &hash1).unwrap();
528 txn.put_change(&mut view, id2, &hash2).unwrap();
529 txn.update_view(&view).unwrap();
530
531 assert_eq!(view.change_count, 2);
532
533 // Insert change 3 at position 1 (between change 1 and 2)
534 txn.reinsert_change(&mut view, id3, &hash3, 1).unwrap();
535
536 // View should now have 3 changes
537 assert_eq!(view.change_count, 3);
538
539 // Verify order: 1, 3, 2
540 assert_eq!(txn.get_change_at_seq(&view, 0).unwrap(), Some(id1));
541 assert_eq!(txn.get_change_at_seq(&view, 1).unwrap(), Some(id3));
542 assert_eq!(txn.get_change_at_seq(&view, 2).unwrap(), Some(id2));
543
544 // Merkle state should be recomputed
545 let expected_state = Merkle::ZERO.next(&hash1).next(&hash3).next(&hash2);
546 assert_eq!(view.state, expected_state);
547
548 txn.update_view(&view).unwrap();
549 txn.commit().unwrap();
550 }
551
552 #[test]
553 fn test_reinsert_change_at_end() {

Callers

nothing calls this directly

Calls 11

openFunction · 0.85
write_txnMethod · 0.80
open_or_create_viewMethod · 0.80
register_changeMethod · 0.80
put_changeMethod · 0.80
update_viewMethod · 0.80
unwrapMethod · 0.45
pathMethod · 0.45
reinsert_changeMethod · 0.45
nextMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected