use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableWriterTest method testSkipOverSpuriousDir.
@Test
public void testSkipOverSpuriousDir() throws Exception {
TestUtils.assertMemoryLeak(() -> {
create(FF, PartitionBy.DAY, 10);
try (Path path = new Path()) {
// create random directory
path.of(configuration.getRoot()).concat(PRODUCT).concat("somethingortheother").put(Files.SEPARATOR).$();
Assert.assertTrue(0 == configuration.getFilesFacade().mkdirs(path, configuration.getMkDirMode()));
new TableWriter(configuration, PRODUCT).close();
Assert.assertFalse(configuration.getFilesFacade().exists(path));
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableWriterTest method testIncorrectTodoCode.
@Test
public void testIncorrectTodoCode() throws Exception {
TestUtils.assertMemoryLeak(() -> {
CairoTestUtils.createAllTable(configuration, PartitionBy.NONE);
long buf = Unsafe.malloc(8);
try {
Unsafe.getUnsafe().putLong(buf, 89808823424L);
try (Path path = new Path().of(root).concat("all").concat(TableUtils.TODO_FILE_NAME).$()) {
long fd = Files.openRW(path);
Assert.assertTrue(fd != -1);
Assert.assertEquals(8, Files.write(fd, buf, 8, 0));
Files.close(fd);
}
} finally {
Unsafe.free(buf, 8);
}
try (TableWriter writer = new TableWriter(configuration, "all")) {
Assert.assertNotNull(writer);
Assert.assertTrue(writer.isOpen());
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableWriterTest method testRemoveColumn.
private void testRemoveColumn(TableModel model) throws Exception {
TestUtils.assertMemoryLeak(() -> {
CairoTestUtils.create(model);
long ts = DateFormatUtils.parseDateTime("2013-03-04T00:00:00.000Z");
Rnd rnd = new Rnd();
try (TableWriter writer = new TableWriter(configuration, model.getName())) {
// optional
writer.warmUp();
ts = append10KProducts(ts, rnd, writer);
writer.removeColumn("supplier");
final NativeLPSZ lpsz = new NativeLPSZ();
try (Path path = new Path()) {
path.of(root).concat(model.getName());
final int plen = path.length();
FF.iterateDir(path.$(), (file, type) -> {
lpsz.of(file);
if (type == Files.DT_DIR && !Chars.equals(lpsz, '.') && !Chars.equals(lpsz, "..")) {
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.i").$()));
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.d").$()));
Assert.assertFalse(FF.exists(path.trimTo(plen).concat(lpsz).concat("supplier.top").$()));
}
});
}
ts = append10KNoSupplier(ts, rnd, writer);
writer.commit();
Assert.assertEquals(20000, writer.size());
}
try (TableWriter writer = new TableWriter(configuration, model.getName())) {
append10KNoSupplier(ts, rnd, writer);
writer.commit();
Assert.assertEquals(30000, writer.size());
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class CairoLineProtoParserTest method testCannotCreateTable.
@Test
public void testCannotCreateTable() throws Exception {
TestFilesFacade ff = new TestFilesFacade() {
boolean called = false;
@Override
public int mkdirs(LPSZ path, int mode) {
if (Chars.endsWith(path, "x" + Files.SEPARATOR)) {
called = true;
return -1;
}
return super.mkdirs(path, mode);
}
@Override
public boolean wasCalled() {
return called;
}
};
final String expected = "sym\tdouble\tint\tbool\tstr\ttimestamp\n" + "zzz\t1.300000000000\t11\tfalse\tnice\t2017-10-03T10:00:00.000Z\n";
String lines = "x,sym2=xyz double=1.6,int=15i,bool=true,str=\"string1\"\n" + "x,sym1=abc double=1.3,int=11i,bool=false,str=\"string2\"\n" + "y,sym=zzz double=1.3,int=11i,bool=false,str=\"nice\"\n";
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
@Override
public MicrosecondClock getClock() {
try {
return new TestMicroClock(DateFormatUtils.parseDateTime("2017-10-03T10:00:00.000Z"), 10);
} catch (NumericException e) {
throw new RuntimeException(e);
}
}
};
assertThat(expected, lines, "y", configuration);
Assert.assertTrue(ff.wasCalled());
try (Path path = new Path()) {
Assert.assertEquals(TableUtils.TABLE_DOES_NOT_EXIST, TableUtils.exists(ff, path, root, "all"));
}
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class SqlLexerOptimiserTest method assertSyntaxError.
private static void assertSyntaxError(SqlLexerOptimiser parser, CairoEngine engine, String query, int position, String contains, TableModel... tableModels) {
try {
for (int i = 0, n = tableModels.length; i < n; i++) {
CairoTestUtils.create(tableModels[i]);
}
parser.parse(query);
Assert.fail("Exception expected");
} catch (ParserException e) {
Assert.assertEquals(position, e.getPosition());
TestUtils.assertContains(e.getMessage(), contains);
} finally {
Assert.assertTrue(engine.releaseAllReaders());
for (int i = 0, n = tableModels.length; i < n; i++) {
TableModel tableModel = tableModels[i];
Path path = tableModel.getPath().of(tableModel.getCairoCfg().getRoot()).concat(tableModel.getName()).put(Files.SEPARATOR).$();
Assert.assertTrue(configuration.getFilesFacade().rmdir(path));
tableModel.close();
}
}
}
Aggregations