Search in sources :

Example 41 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class BinarySearchTest method testFindForwardTwoValues.

@Test
public void testFindForwardTwoValues() {
    try (Path path = new Path()) {
        path.of(root).concat("binsearch.d").$();
        try (MemoryMA appendMem = Vm.getSmallCMARWInstance(FilesFacadeImpl.INSTANCE, path, MemoryTag.MMAP_DEFAULT)) {
            appendMem.putLong(1);
            appendMem.putLong(3);
            try (MemoryMR mem = Vm.getMRInstance(FilesFacadeImpl.INSTANCE, path, 400 * Long.BYTES, MemoryTag.MMAP_DEFAULT)) {
                Assert.assertEquals(0, BinarySearch.find(mem, 2, 0, 1, BinarySearch.SCAN_DOWN));
            }
        }
    }
}
Also used : Path(io.questdb.std.str.Path) MemoryMA(io.questdb.cairo.vm.api.MemoryMA) MemoryMR(io.questdb.cairo.vm.api.MemoryMR) Test(org.junit.Test)

Example 42 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class TelemetryTest method testTelemetryDisabledByDefault.

@Test
public void testTelemetryDisabledByDefault() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (Path path = new Path()) {
            Assert.assertEquals(TableUtils.TABLE_DOES_NOT_EXIST, TableUtils.exists(FF, path, root, "telemetry"));
            Assert.assertEquals(TableUtils.TABLE_DOES_NOT_EXIST, TableUtils.exists(FF, path, root, "telemetry_config"));
        }
    });
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 43 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class FilesTest method testCopyBigFile.

@Test
public void testCopyBigFile() throws Exception {
    File temp = temporaryFolder.newFile();
    // in MB
    int fileSize = 2 * 1024 * 1024;
    byte[] page = new byte[1024 * 64];
    Rnd rnd = new Rnd();
    for (int i = 0; i < page.length; i++) {
        page[i] = rnd.nextByte();
    }
    try (FileOutputStream fos = new FileOutputStream(temp)) {
        for (int i = 0; i < fileSize / page.length; i++) {
            fos.write(page);
        }
    }
    try (Path path = new Path().of(temp.getAbsolutePath()).$()) {
        Assert.assertTrue(Files.exists(path));
        try (Path copyPath = new Path().of(temp.getAbsolutePath()).put("-copy").$()) {
            Files.copy(path, copyPath);
            Assert.assertEquals(fileSize, Files.length(copyPath));
            TestUtils.assertFileContentsEquals(path, copyPath);
        }
    }
}
Also used : Path(io.questdb.std.str.Path) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.Test)

Example 44 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class FilesTest method testFailsToAllocateWhenNotEnoughSpace.

@Test
public void testFailsToAllocateWhenNotEnoughSpace() throws Exception {
    File temp = temporaryFolder.newFile();
    TestUtils.writeStringToFile(temp, "abcde");
    try (Path path = new Path().of(temp.getAbsolutePath()).$()) {
        Assert.assertTrue(Files.exists(path));
        long fd = Files.openRW(path);
        Assert.assertEquals(5, Files.length(path));
        try {
            // 10TB
            long tb10 = 1024L * 1024L * 1024L * 1024L * 10;
            boolean success = Files.allocate(fd, tb10);
            Assert.assertFalse("Allocation should fail on reasonable hard disk size", success);
        } finally {
            Files.close(fd);
        }
    }
}
Also used : Path(io.questdb.std.str.Path) File(java.io.File) Test(org.junit.Test)

Example 45 with Path

use of io.questdb.std.str.Path in project questdb by bluestreak01.

the class FilesTest method testRemove.

@Test
public void testRemove() throws Exception {
    try (Path path = new Path().of(temporaryFolder.newFile().getAbsolutePath()).$()) {
        Assert.assertTrue(Files.touch(path));
        Assert.assertTrue(Files.exists(path));
        Assert.assertTrue(Files.remove(path));
        Assert.assertFalse(Files.exists(path));
    }
}
Also used : Path(io.questdb.std.str.Path) Test(org.junit.Test)

Aggregations

Path (io.questdb.std.str.Path)141 Test (org.junit.Test)89 File (java.io.File)14 FilesFacade (io.questdb.std.FilesFacade)13 MemoryCMARW (io.questdb.cairo.vm.api.MemoryCMARW)10 MemoryMR (io.questdb.cairo.vm.api.MemoryMR)10 Rnd (io.questdb.std.Rnd)10 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)7 MemoryMA (io.questdb.cairo.vm.api.MemoryMA)7 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)6 NativeLPSZ (io.questdb.std.str.NativeLPSZ)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)5 LPSZ (io.questdb.std.str.LPSZ)5 RecordCursor (io.questdb.cairo.sql.RecordCursor)4 RowCursor (io.questdb.cairo.sql.RowCursor)4 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)4 RingQueue (io.questdb.mp.RingQueue)4