| 67 | import static io.questdb.test.tools.TestUtils.assertMemoryLeak; |
| 68 | |
| 69 | public class FilesTest { |
| 70 | private static final String EOL = System.lineSeparator(); |
| 71 | private static final Log LOG = LogFactory.getLog(FilesTest.class); |
| 72 | @Rule |
| 73 | public final TemporaryFolder temporaryFolder = new TemporaryFolder(); |
| 74 | |
| 75 | @Test |
| 76 | public void testAllocate() throws Exception { |
| 77 | assertMemoryLeak(() -> { |
| 78 | File temp = temporaryFolder.newFile(); |
| 79 | TestUtils.writeStringToFile(temp, "abcde"); |
| 80 | try (Path path = new Path().of(temp.getAbsolutePath())) { |
| 81 | Assert.assertTrue(Files.exists(path.$())); |
| 82 | Assert.assertEquals(5, Files.length(path.$())); |
| 83 | |
| 84 | long fd = Files.openRW(path.$()); |
| 85 | try { |
| 86 | Files.allocate(fd, 10); |
| 87 | Assert.assertEquals(10, Files.length(path.$())); |
| 88 | Files.allocate(fd, 120); |
| 89 | Assert.assertEquals(120, Files.length(path.$())); |
| 90 | } finally { |
| 91 | Files.close(fd); |
| 92 | } |
| 93 | } |
| 94 | }); |
| 95 | } |
| 96 | |
| 97 | @Test |
| 98 | public void testAllocateConcurrent() throws IOException, InterruptedException { |
| 99 | // This test allocates (but doesn't write to) potentially very large files |
| 100 | // size of which will depend on free disk space of the host OS. |
| 101 | // I found that on OSX (m1) with large disk allocate() call is painfully slow and |
| 102 | // for that reason (until we understood the problem better) we won't run this test |
| 103 | // on OSX |
| 104 | Assume.assumeTrue(Os.type != Os.DARWIN); |
| 105 | FilesFacade ff = TestFilesFacadeImpl.INSTANCE; |
| 106 | |
| 107 | String tmpFolder = temporaryFolder.newFolder("allocate").getAbsolutePath(); |
| 108 | assumeIsNotTmpFs(tmpFolder); |
| 109 | AtomicInteger errors = new AtomicInteger(); |
| 110 | |
| 111 | for (int i = 0; i < 10; i++) { |
| 112 | Thread th1 = new Thread(() -> testAllocateConcurrent0(ff, tmpFolder, 1, errors)); |
| 113 | Thread th2 = new Thread(() -> testAllocateConcurrent0(ff, tmpFolder, 2, errors)); |
| 114 | th1.start(); |
| 115 | th2.start(); |
| 116 | th1.join(); |
| 117 | th2.join(); |
| 118 | Assert.assertEquals(0, errors.get()); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | @Test |
| 123 | public void testAllocateLoop() throws Exception { |
| 124 | assertMemoryLeak(() -> { |
| 125 | File temp = temporaryFolder.newFile(); |
| 126 | TestUtils.writeStringToFile(temp, "abcde"); |
nothing calls this directly
no test coverage detected
searching dependent graphs…