Search in sources :

Example 1 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class $TabsRecordSource method sumSizes.

private static long sumSizes(LPSZ path) {
    long total = 0;
    long find = Files.findFirst(path);
    if (find == 0) {
        return 0;
    }
    try (Path cp = new Path()) {
        NativeLPSZ file = tlNativeLpsz.get();
        try {
            do {
                file.of(Files.findName(find));
                if (Files.isDots(file)) {
                    continue;
                }
                LPSZ n = cp.of(path).concat(file).$();
                if (Files.findType(find) == Files.DT_DIR) {
                    total += sumSizes(n);
                } else {
                    total += Files.length(n);
                }
            } while (Files.findNext(find) > 0);
        } finally {
            Files.findClose(find);
        }
    }
    return total;
}
Also used : Path(com.questdb.std.str.Path) NativeLPSZ(com.questdb.std.str.NativeLPSZ) LPSZ(com.questdb.std.str.LPSZ) NativeLPSZ(com.questdb.std.str.NativeLPSZ)

Example 2 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class SqlLexerOptimiserTest method testTableNameCannotOpen.

@Test
public void testTableNameCannotOpen() {
    final FilesFacade ff = new FilesFacadeImpl() {

        @Override
        public long openRO(LPSZ name) {
            if (Chars.endsWith(name, TableUtils.META_FILE_NAME)) {
                return -1;
            }
            return super.openRO(name);
        }
    };
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public FilesFacade getFilesFacade() {
            return ff;
        }
    };
    CairoEngine engine = new Engine(configuration);
    SqlLexerOptimiser lexer = new SqlLexerOptimiser(engine, configuration);
    assertSyntaxError(lexer, engine, "select * from tab", 14, "Cannot open file", modelOf("tab").col("x", ColumnType.INT));
}
Also used : FilesFacade(com.questdb.std.FilesFacade) LPSZ(com.questdb.std.str.LPSZ) FilesFacadeImpl(com.questdb.std.FilesFacadeImpl) CairoEngine(com.questdb.cairo.sql.CairoEngine) CairoEngine(com.questdb.cairo.sql.CairoEngine) Test(org.junit.Test)

Example 3 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class CairoMemoryTest method testAppendCannotOpenFile.

@Test
public void testAppendCannotOpenFile() {
    long used = Unsafe.getMemUsed();
    class X extends FilesFacadeImpl {

        @Override
        public long openRW(LPSZ name) {
            int n = name.length();
            if (n > 5 && Chars.equals(".fail", name, n - 5, n)) {
                return -1;
            }
            return super.openRW(name);
        }
    }
    X ff = new X();
    long openFileCount = ff.getOpenFileCount();
    int successCount = 0;
    int failCount = 0;
    try (Path path = new Path()) {
        path.of(temp.getRoot().getAbsolutePath());
        int prefixLen = path.length();
        try (AppendMemory mem = new AppendMemory()) {
            Rnd rnd = new Rnd();
            for (int k = 0; k < 10; k++) {
                path.trimTo(prefixLen).concat(rnd.nextString(10));
                boolean fail = rnd.nextBoolean();
                if (fail) {
                    path.put(".fail").$();
                    failCount++;
                } else {
                    path.put(".data").$();
                    successCount++;
                }
                if (fail) {
                    try {
                        mem.of(ff, path, 2 * ff.getPageSize());
                        Assert.fail();
                    } catch (CairoException ignored) {
                    }
                } else {
                    mem.of(ff, path, 2 * ff.getPageSize());
                    for (int i = 0; i < N; i++) {
                        mem.putLong(i);
                    }
                    Assert.assertEquals(N * 8, mem.getAppendOffset());
                }
            }
        }
    }
    Assert.assertEquals(used, Unsafe.getMemUsed());
    Assert.assertEquals(openFileCount, ff.getOpenFileCount());
    Assert.assertTrue(failCount > 0);
    Assert.assertTrue(successCount > 0);
}
Also used : Path(com.questdb.std.str.Path) LPSZ(com.questdb.std.str.LPSZ) Test(org.junit.Test)

Example 4 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class CairoMemoryTest method testReadWriteCannotOpenFile.

@Test
public void testReadWriteCannotOpenFile() {
    long used = Unsafe.getMemUsed();
    class X extends FilesFacadeImpl {

        @Override
        public long openRW(LPSZ name) {
            int n = name.length();
            if (n > 5) {
                if (Chars.equals(".fail", name, n - 5, n)) {
                    return -1;
                }
            }
            return super.openRW(name);
        }
    }
    X ff = new X();
    long openFileCount = ff.getOpenFileCount();
    int successCount = 0;
    int failCount = 0;
    try (Path path = new Path()) {
        path.of(temp.getRoot().getAbsolutePath());
        int prefixLen = path.length();
        try (ReadWriteMemory mem = new ReadWriteMemory()) {
            Rnd rnd = new Rnd();
            for (int k = 0; k < 10; k++) {
                path.trimTo(prefixLen).concat(rnd.nextString(10));
                boolean fail = rnd.nextBoolean();
                if (fail) {
                    path.put(".fail").$();
                    failCount++;
                } else {
                    path.put(".data").$();
                    successCount++;
                }
                if (fail) {
                    try {
                        mem.of(ff, path, 2 * ff.getPageSize());
                        Assert.fail();
                    } catch (CairoException ignored) {
                    }
                } else {
                    mem.of(ff, path, 2 * ff.getPageSize());
                    for (int i = 0; i < N; i++) {
                        mem.putLong(i);
                    }
                    Assert.assertEquals(N * 8, mem.getAppendOffset());
                }
            }
        }
    }
    Assert.assertEquals(used, Unsafe.getMemUsed());
    Assert.assertEquals(openFileCount, ff.getOpenFileCount());
    Assert.assertTrue(failCount > 0);
    Assert.assertTrue(successCount > 0);
}
Also used : Path(com.questdb.std.str.Path) LPSZ(com.questdb.std.str.LPSZ) Test(org.junit.Test)

Example 5 with LPSZ

use of com.questdb.std.str.LPSZ in project questdb by bluestreak01.

the class TableReadFailTest method testTxnFileCannotOpenConstructor.

@Test
public void testTxnFileCannotOpenConstructor() throws Exception {
    FilesFacade ff = new FilesFacadeImpl() {

        @Override
        public long openRO(LPSZ name) {
            if (Chars.endsWith(name, TableUtils.TXN_FILE_NAME)) {
                return -1;
            }
            return super.openRO(name);
        }
    };
    assertConstructorFail(ff);
}
Also used : FilesFacade(com.questdb.std.FilesFacade) LPSZ(com.questdb.std.str.LPSZ) FilesFacadeImpl(com.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Aggregations

LPSZ (com.questdb.std.str.LPSZ)13 Test (org.junit.Test)11 FilesFacadeImpl (com.questdb.std.FilesFacadeImpl)7 FilesFacade (com.questdb.std.FilesFacade)6 Path (com.questdb.std.str.Path)6 CairoEngine (com.questdb.cairo.sql.CairoEngine)1 NumericException (com.questdb.common.NumericException)1 NativeLPSZ (com.questdb.std.str.NativeLPSZ)1 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)1 TestMicroClock (com.questdb.test.tools.TestMicroClock)1 CountDownLatch (java.util.concurrent.CountDownLatch)1