MCPcopy Create free account
hub / github.com/cosdata/cosdata / test_write_large_file

Function test_write_large_file

src/models/buffered_io.rs:1489–1513  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1487
1488 #[test]
1489 fn test_write_large_file() {
1490 let mut rng = rand::thread_rng();
1491
1492 let file = create_tmp_file(0, 0).unwrap();
1493 let bufman = BufferManager::new(file, BUFFER_SIZE).unwrap();
1494 let cursor = bufman.open_cursor().unwrap();
1495
1496 let written_data = (0..(100 * 1024 * 1024))
1497 .map(|_| rng.gen())
1498 .collect::<Vec<_>>();
1499 bufman
1500 .write_with_cursor(cursor, &written_data, true)
1501 .unwrap();
1502 bufman.flush().unwrap();
1503
1504 let mut read_data = vec![0; 100 * 1024 * 1024];
1505
1506 let mut file = bufman.file.write().unwrap();
1507 file.seek(SeekFrom::Start(0)).unwrap();
1508 file.read_exact(&mut read_data).unwrap();
1509
1510 for (i, (r, w)) in read_data.into_iter().zip(written_data).enumerate() {
1511 assert_eq!(r, w, "mismatch at {}", i);
1512 }
1513 }
1514
1515 // Prop test for `get_or_create_region` to check that
1516 // `region.start` is a multiple of BUFFER_SIZE

Callers

nothing calls this directly

Calls 4

create_tmp_fileFunction · 0.85
open_cursorMethod · 0.80
write_with_cursorMethod · 0.80
flushMethod · 0.45

Tested by

no test coverage detected