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;
}
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));
}
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);
}
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);
}
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);
}
Aggregations