()
| 991 | } |
| 992 | |
| 993 | @Test |
| 994 | public void testReadFails() throws Exception { |
| 995 | assertMemoryLeak(() -> { |
| 996 | File temp = temporaryFolder.newFile(); |
| 997 | |
| 998 | try (Path path = new Path().of(temp.getAbsolutePath())) { |
| 999 | long fd1 = Files.openRW(path.$()); |
| 1000 | long fileSize = 4096; |
| 1001 | long mem = Unsafe.malloc(fileSize, MemoryTag.NATIVE_DEFAULT); |
| 1002 | |
| 1003 | long testValue = 0x1234567890ABCDEFL; |
| 1004 | Unsafe.putLong(mem, testValue); |
| 1005 | |
| 1006 | try { |
| 1007 | Files.truncate(fd1, fileSize); |
| 1008 | |
| 1009 | Assert.assertEquals(8L, Files.read(fd1, mem, 8L, 0)); |
| 1010 | Assert.assertTrue(Files.read(fd1, mem, fileSize, -1) < 0); |
| 1011 | Assert.assertEquals(0, Files.read(fd1, mem, fileSize, fileSize)); |
| 1012 | Assert.assertEquals(0, Files.read(fd1, mem, fileSize + 8, fileSize)); |
| 1013 | |
| 1014 | } finally { |
| 1015 | // Release mem, fd |
| 1016 | Files.close(fd1); |
| 1017 | Unsafe.free(mem, fileSize, MemoryTag.NATIVE_DEFAULT); |
| 1018 | |
| 1019 | // Delete files |
| 1020 | TestUtils.remove(path.$()); |
| 1021 | } |
| 1022 | } |
| 1023 | }); |
| 1024 | } |
| 1025 | |
| 1026 | @Test |
| 1027 | public void testReadOver2GB() throws Exception { |
nothing calls this directly
no test coverage detected