use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.
the class SampleByTest method testSampleFillLinearFail.
@Test
public void testSampleFillLinearFail() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table x as " + "(" + "select" + " rnd_double(0)*100 a," + " rnd_symbol(5,4,4,1) b," + " timestamp_sequence(172800000000, 3600000000) k" + " from" + " long_sequence(20000000)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
FilesFacade ff = new FilesFacadeImpl() {
int count = 10;
@Override
public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
if (count-- > 0) {
return super.mmap(fd, len, offset, flags, memoryTag);
}
return -1;
}
};
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
};
try (CairoEngine engine = new CairoEngine(configuration)) {
try (SqlCompiler compiler = new SqlCompiler(engine)) {
try {
try (RecordCursorFactory factory = compiler.compile("select b, sum(a), k from x sample by 3h fill(linear)", sqlExecutionContext).getRecordCursorFactory()) {
// with mmap count = 5 we should get failure in cursor
factory.getCursor(sqlExecutionContext);
}
Assert.fail();
} catch (CairoException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "could not mmap"));
}
Assert.assertEquals(0, engine.getBusyReaderCount());
Assert.assertEquals(0, engine.getBusyWriterCount());
}
}
});
}
use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.
the class SampleByTest method testGroupByFail.
@Test
public void testGroupByFail() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table x as " + "(" + "select" + " x," + " rnd_double(0) d," + " rnd_symbol('XY','ZP', null, 'UU') c" + " from" + " long_sequence(1000000)" + ")", sqlExecutionContext);
engine.clear();
final FilesFacade ff = new FilesFacadeImpl() {
int count = 10;
@Override
public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
if (count-- > 0) {
return super.mmap(fd, len, offset, flags, memoryTag);
}
return -1;
}
};
final CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
};
try (CairoEngine engine = new CairoEngine(configuration)) {
try (SqlCompiler compiler = new SqlCompiler(engine)) {
try {
try (RecordCursorFactory factory = compiler.compile("select c, sum_t(d) from x", sqlExecutionContext).getRecordCursorFactory()) {
factory.getCursor(sqlExecutionContext);
}
Assert.fail();
} catch (CairoException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "could not mmap");
}
Assert.assertEquals(0, engine.getBusyReaderCount());
Assert.assertEquals(0, engine.getBusyWriterCount());
}
engine.clear();
}
});
}
use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.
the class MimeTypesCacheTest method testWrongFileSize2.
@Test()
public void testWrongFileSize2() throws Exception {
AtomicInteger closeCount = new AtomicInteger(0);
testFailure(new FilesFacadeImpl() {
@Override
public long length(long fd) {
return -1;
}
@Override
public long openRO(LPSZ name) {
return 123L;
}
@Override
public boolean close(long fd) {
closeCount.incrementAndGet();
return true;
}
}, "wrong file size");
Assert.assertEquals(1, closeCount.get());
}
use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.
the class LineTcpConnectionContextTest method testCairoExceptionOnCreateTable.
@Test
public void testCairoExceptionOnCreateTable() throws Exception {
String table = "cairoEx";
runInContext(new FilesFacadeImpl() {
@Override
public long openRW(LPSZ name) {
if (Chars.endsWith(name, "broken.d")) {
return -1;
}
return super.openRW(name);
}
}, () -> {
recvBuffer = table + ",location=us-eastcoast temperature=81,broken=23 1465839830101400200\n" + table + ",location=us-midwest temperature=82 1465839830100400200\n" + table + ",location=us-midwest temperature=83 1465839830100500200\n" + table + ",location=us-midwest temperature=85 1465839830102300200\n" + table + ",location=us-eastcoast temperature=89 1465839830102400200\n" + table + ",location=us-eastcoast temperature=80 1465839830102400200\n" + table + ",location=us-westcost temperature=82 1465839830102500200\n";
do {
handleContextIO();
Assert.assertFalse(disconnected);
} while (recvBuffer.length() > 0);
closeContext();
String expected = "location\ttemperature\tbroken\ttimestamp\n";
assertTable(expected, table);
}, null, null);
}
use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.
the class TxnScoreboardTest method testCleanFailsNoResourceLeak.
@Test
public void testCleanFailsNoResourceLeak() throws Exception {
TestUtils.assertMemoryLeak(() -> {
FilesFacade ff = new FilesFacadeImpl() {
@Override
public long openCleanRW(LPSZ name, long fd) {
return -1;
}
};
assertMemoryLeak(() -> {
try (final Path shmPath = new Path()) {
try (TxnScoreboard ignored = new TxnScoreboard(ff, shmPath.of(root), 2048)) {
Assert.fail();
} catch (CairoException ex) {
TestUtils.assertContains(ex.getFlyweightMessage(), "could not open read-write with clean allocation");
}
}
});
});
}
Aggregations