use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class SqlParserTest method testTableNameCannotOpen.
@Test
public void testTableNameCannotOpen() throws Exception {
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;
}
};
assertMemoryLeak(() -> {
try (CairoEngine engine = new CairoEngine(configuration);
SqlCompiler compiler = new SqlCompiler(engine)) {
TableModel[] tableModels = new TableModel[] { modelOf("tab").col("x", ColumnType.INT) };
try {
try {
for (int i = 0, n = tableModels.length; i < n; i++) {
CairoTestUtils.create(tableModels[i]);
}
compiler.compile("select * from tab", sqlExecutionContext);
Assert.fail("Exception expected");
} catch (SqlException e) {
Assert.assertEquals(14, e.getPosition());
TestUtils.assertContains(e.getFlyweightMessage(), "could not open");
}
} finally {
for (int i = 0, n = tableModels.length; i < n; i++) {
TableModel tableModel = tableModels[i];
Path path = tableModel.getPath().of(tableModel.getConfiguration().getRoot()).concat(tableModel.getName()).slash$();
Assert.assertEquals(0, configuration.getFilesFacade().rmdir(path));
tableModel.close();
}
}
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class SqlParserTest method testTableNameLocked.
@Test
public void testTableNameLocked() throws Exception {
assertMemoryLeak(() -> {
CharSequence lockedReason = engine.lock(AllowAllCairoSecurityContext.INSTANCE, "tab", "testing");
Assert.assertNull(lockedReason);
try {
TableModel[] tableModels = new TableModel[] { modelOf("tab").col("x", ColumnType.INT) };
try {
try {
for (int i = 0, n = tableModels.length; i < n; i++) {
CairoTestUtils.create(tableModels[i]);
}
compiler.compile("select * from tab", sqlExecutionContext);
Assert.fail("Exception expected");
} catch (SqlException e) {
Assert.assertEquals(14, e.getPosition());
TestUtils.assertContains(e.getFlyweightMessage(), "table is locked");
}
} finally {
for (int i = 0, n = tableModels.length; i < n; i++) {
TableModel tableModel = tableModels[i];
Path path = tableModel.getPath().of(tableModel.getConfiguration().getRoot()).concat(tableModel.getName()).slash$();
Assert.assertEquals(0, configuration.getFilesFacade().rmdir(path));
tableModel.close();
}
}
} finally {
engine.unlock(AllowAllCairoSecurityContext.INSTANCE, "tab", null, false);
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TableRepairTest method testDeletePartitionInTheMiddle.
@Test
public void testDeletePartitionInTheMiddle() throws Exception {
// this delete partition actually deletes files, simulating manual intervention
assertMemoryLeak(() -> {
compiler.compile("create table tst as (select * from (select rnd_int() a, rnd_double() b, timestamp_sequence(0, 10000000l) t from long_sequence(100000)) timestamp (t)) timestamp(t) partition by DAY", sqlExecutionContext);
engine.releaseAllWriters();
try (TableReader reader = new TableReader(configuration, "tst")) {
Assert.assertEquals(100000, reader.size());
try (Path path = new Path()) {
path.of(configuration.getRoot()).concat("tst").concat("1970-01-09").$();
Assert.assertEquals(0, Files.rmdir(path));
}
Assert.assertEquals(100000, reader.size());
// repair by opening and closing writer
new TableWriter(configuration, "tst").close();
Assert.assertTrue(reader.reload());
Assert.assertEquals(91360, reader.size());
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TableRepairTest method testDeleteActivePartition.
@Test
public void testDeleteActivePartition() throws Exception {
// this delete partition actually deletes files, simulating manual intervention
assertMemoryLeak(() -> {
compiler.compile("create table tst as (select * from (select rnd_int() a, rnd_double() b, timestamp_sequence(0, 10000000l) t from long_sequence(100000)) timestamp (t)) timestamp(t) partition by DAY", sqlExecutionContext);
engine.releaseAllWriters();
try (TableReader reader = new TableReader(configuration, "tst")) {
Assert.assertEquals(100000, reader.size());
// last and "active" partition is "1970-01-12"
try (Path path = new Path()) {
path.of(configuration.getRoot()).concat("tst").concat("1970-01-12").$();
Assert.assertEquals(0, Files.rmdir(path));
}
Assert.assertEquals(100000, reader.size());
try (TableWriter w = new TableWriter(configuration, "tst")) {
Assert.assertTrue(reader.reload());
Assert.assertEquals(95040, reader.size());
Assert.assertEquals(950390000000L, w.getMaxTimestamp());
TableWriter.Row row = w.newRow(w.getMaxTimestamp());
row.putInt(0, 150);
row.putDouble(1, 0.67);
row.append();
w.commit();
}
Assert.assertTrue(reader.reload());
Assert.assertEquals(95041, reader.size());
}
});
}
use of io.questdb.std.str.Path in project questdb by bluestreak01.
the class TxSerializerTest method removeTestPath.
public static void removeTestPath(CharSequence root) {
Path path = Path.getThreadLocal(root);
Files.rmdir(path.slash$());
}
Aggregations