()
| 814 | |
| 815 | #[test] |
| 816 | fn test_basic_usage() { |
| 817 | // @NOTE: Not really using multiple threads here. This test |
| 818 | // just ensures that read/write using multiple cursors work in |
| 819 | // a single thread |
| 820 | |
| 821 | let mut file = tempfile().unwrap(); |
| 822 | file.write_all(&456_u32.to_le_bytes()).unwrap(); |
| 823 | let bufman = BufferManager::new(file, BUFFER_SIZE).unwrap(); |
| 824 | |
| 825 | let cursor1 = bufman.open_cursor().unwrap(); |
| 826 | let cursor2 = bufman.open_cursor().unwrap(); |
| 827 | |
| 828 | // Thread 1: Read from the beginning of file |
| 829 | bufman.seek_with_cursor(cursor1, 0).unwrap(); |
| 830 | let value1 = bufman.read_u32_with_cursor(cursor1).unwrap(); |
| 831 | assert_eq!(456_u32, value1); |
| 832 | |
| 833 | // Thread 2: Write to the end of file |
| 834 | bufman |
| 835 | .write_with_cursor(cursor2, &789_u32.to_le_bytes(), true) |
| 836 | .unwrap(); |
| 837 | |
| 838 | // Thread 1: Continue reading |
| 839 | let value2 = bufman.read_u32_with_cursor(cursor1).unwrap(); |
| 840 | assert_eq!(789_u32, value2); |
| 841 | |
| 842 | // Thread 2: Again write to end of file |
| 843 | bufman |
| 844 | .write_with_cursor(cursor2, &12345_u32.to_le_bytes(), true) |
| 845 | .unwrap(); |
| 846 | |
| 847 | // Thread 1: Continue reading |
| 848 | let value3 = bufman.read_u32_with_cursor(cursor1).unwrap(); |
| 849 | assert_eq!(12345_u32, value3); |
| 850 | |
| 851 | bufman.close_cursor(cursor1).unwrap(); |
| 852 | bufman.close_cursor(cursor1).unwrap(); |
| 853 | } |
| 854 | |
| 855 | /// Test util function to create a temp file of size calculated |
| 856 | /// from `num_regions` and `extra` bytes after that. |
nothing calls this directly
no test coverage detected