MCPcopy Create free account
hub / github.com/apache/datafusion / test_disk_usage_with_clones

Function test_disk_usage_with_clones

datafusion/execution/src/disk_manager.rs:653–716  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

651
652 #[test]
653 fn test_disk_usage_with_clones() -> Result<()> {
654 use std::io::Write;
655
656 let dm = Arc::new(DiskManagerBuilder::default().build()?);
657 let mut temp_file = dm.create_tmp_file("Testing")?;
658
659 // Write some data
660 temp_file.inner().as_file().write_all(b"test data")?;
661 temp_file.update_disk_usage()?;
662
663 let usage_after_write = temp_file.current_disk_usage();
664 assert!(usage_after_write > 0);
665 assert_eq!(dm.used_disk_space(), usage_after_write);
666
667 // Clone the file
668 let clone1 = temp_file.clone();
669 let clone2 = temp_file.clone();
670
671 // All clones should see the same disk usage
672 assert_eq!(clone1.current_disk_usage(), usage_after_write);
673 assert_eq!(clone2.current_disk_usage(), usage_after_write);
674
675 // Global disk usage should still be the same (not multiplied by number of clones)
676 assert_eq!(dm.used_disk_space(), usage_after_write);
677
678 // Write more data through one clone
679 clone1.inner().as_file().write_all(b" more data")?;
680 let mut mutable_clone1 = clone1;
681 mutable_clone1.update_disk_usage()?;
682
683 let new_usage = mutable_clone1.current_disk_usage();
684 assert!(new_usage > usage_after_write);
685
686 // All clones should see the updated disk usage
687 assert_eq!(temp_file.current_disk_usage(), new_usage);
688 assert_eq!(clone2.current_disk_usage(), new_usage);
689 assert_eq!(mutable_clone1.current_disk_usage(), new_usage);
690
691 // Global disk usage should reflect the new size (not multiplied)
692 assert_eq!(dm.used_disk_space(), new_usage);
693
694 // Drop one clone
695 drop(mutable_clone1);
696
697 // Disk usage should NOT change (other clones still exist)
698 assert_eq!(dm.used_disk_space(), new_usage);
699 assert_eq!(temp_file.current_disk_usage(), new_usage);
700 assert_eq!(clone2.current_disk_usage(), new_usage);
701
702 // Drop another clone
703 drop(clone2);
704
705 // Disk usage should still NOT change (original still exists)
706 assert_eq!(dm.used_disk_space(), new_usage);
707 assert_eq!(temp_file.current_disk_usage(), new_usage);
708
709 // Drop the original
710 drop(temp_file);

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
create_tmp_fileMethod · 0.80
update_disk_usageMethod · 0.80
current_disk_usageMethod · 0.80
buildMethod · 0.45
write_allMethod · 0.45
innerMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…