Search in sources :

Example 1 with TelemetryJob

use of io.questdb.TelemetryJob 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);
                }
            }
        }
    });
}
Also used : TelemetryJob(io.questdb.TelemetryJob) WorkerPool(io.questdb.mp.WorkerPool) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoEngine(io.questdb.cairo.CairoEngine) WorkerPoolConfiguration(io.questdb.mp.WorkerPoolConfiguration) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration)

Aggregations

TelemetryJob (io.questdb.TelemetryJob)1 CairoConfiguration (io.questdb.cairo.CairoConfiguration)1 CairoEngine (io.questdb.cairo.CairoEngine)1 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)1 WorkerPool (io.questdb.mp.WorkerPool)1 WorkerPoolConfiguration (io.questdb.mp.WorkerPoolConfiguration)1