Search in sources :

Example 6 with ServerConfiguration

use of com.questdb.ServerConfiguration in project questdb by bluestreak01.

the class HttpServerTest method testImportAppend.

@Test
public void testImportAppend() throws Exception {
    final AtomicInteger errors = new AtomicInteger();
    getFactory().setEventListener((factoryType, thread, name, event, segment, position) -> {
        if (event == FactoryEventListener.EV_UNEXPECTED_CLOSE) {
            errors.incrementAndGet();
        }
        return true;
    });
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration();
    env.factory = getFactory();
    env.typeProbeCollection = TYPE_PROBE_COLLECTION;
    env.matcher = new SimpleUrlMatcher() {

        {
            put("/imp", new ImportHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?fmt=json", null, null));
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", null, null));
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        printer.print(qc.compile(getFactory(), "select count(StrSym), count(IntSym), count(IntCol), count(long), count() from 'test-import.csv'"), getFactory());
        TestUtils.assertEquals("252\t252\t256\t258\t258\n", sink);
    } finally {
        server.halt();
    }
    Assert.assertEquals(0, errors.get());
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerConfiguration(com.questdb.ServerConfiguration) RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) ImportHandler(com.questdb.net.http.handlers.ImportHandler) StringSink(com.questdb.std.str.StringSink) QueryCompiler(com.questdb.parser.sql.QueryCompiler) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 7 with ServerConfiguration

use of com.questdb.ServerConfiguration in project questdb by bluestreak01.

the class HttpServerTest method testIdleTimeout.

@Test
public void testIdleTimeout() throws Exception {
    final BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf"));
    // 500ms timeout
    env.configuration.setHttpTimeout(500);
    env.configuration.getSslConfig().setSecure(false);
    env.matcher = new SimpleUrlMatcher() {

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        Socket socket = new Socket("127.0.0.1", 9000);
        OutputStream os = socket.getOutputStream();
        Thread.sleep(600);
        try {
            os.write(request.getBytes());
            for (int i = 0; i < 4096; i++) {
                os.write('c');
            }
            os.flush();
            Assert.fail("Expected exception due to connection timeout");
        } catch (SocketException ignored) {
        }
    } finally {
        server.halt();
    }
}
Also used : SocketException(java.net.SocketException) BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) Socket(java.net.Socket) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 8 with ServerConfiguration

use of com.questdb.ServerConfiguration in project questdb by bluestreak01.

the class HttpServerTest method testStartStop.

@Test
public void testStartStop() {
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration();
    env.matcher = new SimpleUrlMatcher();
    HttpServer server = new HttpServer(env);
    server.start();
    server.halt();
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) ServerConfiguration(com.questdb.ServerConfiguration) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 9 with ServerConfiguration

use of com.questdb.ServerConfiguration in project questdb by bluestreak01.

the class HttpServerTest method testImportWrongTypeStrictAtomicity.

@Test
public void testImportWrongTypeStrictAtomicity() throws Exception {
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration();
    env.factory = getFactory();
    env.typeProbeCollection = TYPE_PROBE_COLLECTION;
    env.matcher = new SimpleUrlMatcher() {

        {
            put("/imp", new ImportHandler(env));
        }
    };
    env.dateLocaleFactory = DateLocaleFactory.INSTANCE;
    env.dateFormatFactory = DATE_FORMAT_FACTORY;
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        Assert.assertEquals(400, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?atomicity=strict", "[{\"name\":\"IsoDate\", \"type\":\"DATE\"}, {\"name\":\"IntCol\", \"type\":\"DATE\"}]", null));
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        RecordSource src1 = qc.compile(env.factory, "select count() from 'test-import.csv'");
        try {
            printer.print(src1, env.factory);
            TestUtils.assertEquals("0\n", sink);
        } finally {
            Misc.free(src1);
        }
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) RecordSource(com.questdb.ql.RecordSource) ServerConfiguration(com.questdb.ServerConfiguration) RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) ImportHandler(com.questdb.net.http.handlers.ImportHandler) StringSink(com.questdb.std.str.StringSink) QueryCompiler(com.questdb.parser.sql.QueryCompiler) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 10 with ServerConfiguration

use of com.questdb.ServerConfiguration in project questdb by bluestreak01.

the class HttpServerTest method testCompressedDownload.

@Test
public void testCompressedDownload() throws Exception {
    final ServerConfiguration configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf"));
    configuration.getSslConfig().setSecure(true);
    configuration.getSslConfig().setKeyStore(new FileInputStream(resourceFile("/keystore/singlekey.ks")), "changeit");
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = configuration;
    env.matcher = new SimpleUrlMatcher() {

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        HttpTestUtils.download(clientBuilder(true), "https://localhost:9000/upload.html", new File(temp.getRoot(), "upload.html"));
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Aggregations

ServerConfiguration (com.questdb.ServerConfiguration)38 Test (org.junit.Test)34 BootstrapEnv (com.questdb.BootstrapEnv)33 AbstractJournalTest (com.questdb.net.ha.AbstractJournalTest)29 ImportHandler (com.questdb.net.http.handlers.ImportHandler)13 StringSink (com.questdb.std.str.StringSink)11 StaticContentHandler (com.questdb.net.http.handlers.StaticContentHandler)9 QueryCompiler (com.questdb.parser.sql.QueryCompiler)9 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)9 JournalWriter (com.questdb.store.JournalWriter)4 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)4 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)3 RecordSource (com.questdb.ql.RecordSource)3 JournalEntryWriter (com.questdb.store.JournalEntryWriter)3 SocketException (java.net.SocketException)3 ResponseContentBufferTooSmallException (com.questdb.ex.ResponseContentBufferTooSmallException)2 HttpServer (com.questdb.net.http.HttpServer)2 IOContext (com.questdb.net.http.IOContext)2 SimpleUrlMatcher (com.questdb.net.http.SimpleUrlMatcher)2 UploadHandler (com.questdb.net.http.handlers.UploadHandler)2