use of io.questdb.cairo.CairoEngine in project questdb by bluestreak01.
the class TelemetryTest method testTelemetryStoresUpAndDownEvents.
@Test
public void testTelemetryStoresUpAndDownEvents() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (CairoEngine engine = new CairoEngine(configuration)) {
TelemetryJob telemetryJob = new TelemetryJob(engine);
Misc.free(telemetryJob);
final String expectedEvent = "100\n" + "101\n";
assertColumn(expectedEvent, 1);
final String expectedOrigin = "1\n" + "1\n";
assertColumn(expectedOrigin, 2);
}
});
}
use of io.questdb.cairo.CairoEngine in project questdb by bluestreak01.
the class LatestByParallelTest method execute.
protected static void execute(@Nullable WorkerPool pool, LatestByRunnable runnable, CairoConfiguration configuration) throws Exception {
final int workerCount = pool == null ? 1 : pool.getWorkerCount();
try (final CairoEngine engine = new CairoEngine(configuration);
final SqlCompiler compiler = new SqlCompiler(engine)) {
try (final SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, workerCount)) {
try {
if (pool != null) {
pool.assignCleaner(Path.CLEANER);
pool.assign(new LatestByAllIndexedJob(engine.getMessageBus()));
pool.start(LOG);
}
runnable.run(engine, compiler, sqlExecutionContext);
Assert.assertEquals(0, engine.getBusyWriterCount());
Assert.assertEquals(0, engine.getBusyReaderCount());
} finally {
if (pool != null) {
pool.halt();
}
}
}
}
}
use of io.questdb.cairo.CairoEngine in project invesdwin-context-persistence by subes.
the class QuestDBPerformanceTest method testQuestDbPerformance.
@Test
public void testQuestDbPerformance() throws InterruptedException, SqlException, IOException {
final File directory = new File(ContextProperties.getCacheDirectory(), QuestDBPerformanceTest.class.getSimpleName());
Files.deleteNative(directory);
Files.forceMkdir(directory);
final CairoConfiguration configuration = new DefaultCairoConfiguration(directory.getAbsolutePath());
final Instant writesStart = new Instant();
int i = 0;
final CairoEngine engine = new CairoEngine(configuration);
final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("create table abc (value long, key timestamp) timestamp(key)", ctx);
try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "insert")) {
for (final FDate date : newValues()) {
final TableWriter.Row row = writer.newRow(date.millisValue());
row.putLong(0, date.millisValue());
row.append();
i++;
if (i % FLUSH_INTERVAL == 0) {
if (loopCheck.check()) {
printProgress("Writes", writesStart, i, VALUES);
}
writer.commit();
}
}
writer.commit();
}
printProgress("WritesFinished", writesStart, VALUES, VALUES);
}
readIterator(engine);
readGet(engine);
readGetLatest(engine);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("dtop table 'abc';", ctx);
}
engine.close();
Files.deleteNative(directory);
}
use of io.questdb.cairo.CairoEngine in project questdb by bluestreak01.
the class HttpMinTestBuilder method run.
public void run(HttpQueryTestBuilder.HttpClientCode code) throws Exception {
final int[] workerAffinity = new int[1];
Arrays.fill(workerAffinity, -1);
assertMemoryLeak(() -> {
final String baseDir = temp.getRoot().getAbsolutePath();
final DefaultHttpServerConfiguration httpConfiguration = new HttpServerConfigurationBuilder().withBaseDir(temp.getRoot().getAbsolutePath()).build();
final WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {
@Override
public int[] getWorkerAffinity() {
return workerAffinity;
}
@Override
public int getWorkerCount() {
return workerAffinity.length;
}
@Override
public boolean haltOnError() {
return false;
}
});
DefaultCairoConfiguration cairoConfiguration = new DefaultCairoConfiguration(baseDir);
try (CairoEngine engine = new CairoEngine(cairoConfiguration);
HttpServer httpServer = new HttpServer(httpConfiguration, workerPool, false)) {
httpServer.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new PrometheusMetricsProcessor(metrics);
}
@Override
public String getUrl() {
return "/metrics";
}
});
QueryCache.configure(httpConfiguration);
workerPool.start(LOG);
try {
code.run(engine);
} finally {
workerPool.halt();
}
}
});
}
use of io.questdb.cairo.CairoEngine in project questdb by bluestreak01.
the class HttpQueryTestBuilder method run.
public void run(CairoConfiguration configuration, HttpClientCode code) throws Exception {
final int[] workerAffinity = new int[workerCount];
Arrays.fill(workerAffinity, -1);
assertMemoryLeak(() -> {
final String baseDir = temp.getRoot().getAbsolutePath();
final DefaultHttpServerConfiguration httpConfiguration = serverConfigBuilder.withBaseDir(baseDir).build();
final WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {
@Override
public int[] getWorkerAffinity() {
return workerAffinity;
}
@Override
public int getWorkerCount() {
return workerCount;
}
@Override
public boolean haltOnError() {
return false;
}
});
if (workerCount > 1) {
workerPool.assignCleaner(Path.CLEANER);
}
CairoConfiguration cairoConfiguration = configuration;
if (cairoConfiguration == null) {
cairoConfiguration = new DefaultCairoConfiguration(baseDir);
}
try (CairoEngine engine = new CairoEngine(cairoConfiguration);
HttpServer httpServer = new HttpServer(httpConfiguration, workerPool, false)) {
TelemetryJob telemetryJob = null;
if (telemetry) {
telemetryJob = new TelemetryJob(engine);
}
httpServer.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new StaticContentProcessor(httpConfiguration);
}
@Override
public String getUrl() {
return HttpServerConfiguration.DEFAULT_PROCESSOR_URL;
}
});
httpServer.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return textImportProcessor != null ? textImportProcessor.create(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount()) : new TextImportProcessor(engine);
}
@Override
public String getUrl() {
return "/upload";
}
});
httpServer.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new JsonQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount(), Metrics.enabled());
}
@Override
public String getUrl() {
return "/query";
}
});
httpServer.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new TextQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount());
}
@Override
public String getUrl() {
return "/exp";
}
});
httpServer.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new TableStatusCheckProcessor(engine, httpConfiguration.getJsonQueryProcessorConfiguration());
}
@Override
public String getUrl() {
return "/chk";
}
});
httpServer.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new JsonQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, 1, Metrics.enabled());
}
@Override
public String getUrl() {
return "/exec";
}
});
QueryCache.configure(httpConfiguration);
workerPool.start(LOG);
try {
code.run(engine);
} finally {
workerPool.halt();
if (telemetryJob != null) {
Misc.free(telemetryJob);
}
}
}
});
}
Aggregations