Search in sources :

Example 1 with BootstrapEnv

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

the class HttpServerTest method testMaxConnections.

@Test
public void testMaxConnections() throws Exception {
    final ServerConfiguration configuration = new ServerConfiguration(new File(resourceFile("/site"), "conf/questdb.conf"));
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = configuration;
    env.configuration.setHttpMaxConnections(1);
    env.matcher = new SimpleUrlMatcher() {

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        Assert.assertNotNull(clientBuilder(true).build().execute(new HttpGet("https://localhost:9000/upload.html")));
        try {
            clientBuilder(true).build().execute(new HttpGet("https://localhost:9000/upload.html"));
            Assert.fail("Expected server to reject connection");
        } catch (Exception ignored) {
        }
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) StaticContentHandler(com.questdb.net.http.handlers.StaticContentHandler) ServerConfiguration(com.questdb.ServerConfiguration) HttpGet(org.apache.http.client.methods.HttpGet) ResponseContentBufferTooSmallException(com.questdb.ex.ResponseContentBufferTooSmallException) SocketException(java.net.SocketException) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 2 with BootstrapEnv

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

the class HttpServerTest method testUpload.

@Test
public void testUpload() throws Exception {
    final File dir = temp.newFolder();
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration();
    env.matcher = new SimpleUrlMatcher() {

        {
            put("/upload", new UploadHandler(dir));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    File expected = resourceFile("/csv/test-import.csv");
    File actual = new File(dir, "test-import.csv");
    upload(expected);
    TestUtils.assertEquals(expected, actual);
    server.halt();
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) ServerConfiguration(com.questdb.ServerConfiguration) UploadHandler(com.questdb.net.http.handlers.UploadHandler) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 3 with BootstrapEnv

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

the class HttpServerTest method testNativeNotModified.

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

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    assertNotModified(env.configuration, server);
}
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)

Example 4 with BootstrapEnv

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

the class HttpServerTest method testImportNumericHeader.

@Test
public void testImportNumericHeader() 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));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-numeric-headers.csv", "http://localhost:9000/imp?name=test-import.csv&overwrite=true&durable=true&forceHeader=true", null, null));
        printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory());
        // expect first line to be treated as header
        TestUtils.assertEquals("2\n", sink);
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) 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 5 with BootstrapEnv

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

the class HttpServerTest method downloadChunked.

private File downloadChunked(ServerConfiguration conf, final int count, final int sz, boolean ssl, final boolean compressed) throws Exception {
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = conf;
    env.matcher = new SimpleUrlMatcher() {

        {
            put("/test", new ContextHandler() {

                private int counter = -1;

                @Override
                public void handle(IOContext context) throws IOException {
                    ChunkedResponse r = context.chunkedResponse();
                    r.setCompressed(compressed);
                    r.status(200, "text/plain; charset=utf-8");
                    r.sendHeader();
                    counter = -1;
                    resume(context);
                }

                @Override
                public void resume(IOContext context) throws IOException {
                    ChunkedResponse r = context.chunkedResponse();
                    for (int i = counter + 1; i < count; i++) {
                        counter = i;
                        try {
                            for (int k = 0; k < sz; k++) {
                                Numbers.append(r, i);
                            }
                            r.put(Misc.EOL);
                        } catch (ResponseContentBufferTooSmallException ignore) {
                            // ignore, send as much as we can in one chunk
                            LOG.error().$("Response content buffer is too small").$();
                        }
                        r.sendChunk();
                    }
                    r.done();
                }

                @Override
                public void setupThread() {
                }
            });
        }
    };
    HttpServer server = new HttpServer(env);
    File out = temp.newFile();
    server.start();
    try {
        HttpTestUtils.download(clientBuilder(ssl), (ssl ? "https" : "http") + "://localhost:9000/test", out);
    } finally {
        server.halt();
    }
    return out;
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) ResponseContentBufferTooSmallException(com.questdb.ex.ResponseContentBufferTooSmallException)

Aggregations

BootstrapEnv (com.questdb.BootstrapEnv)36 ServerConfiguration (com.questdb.ServerConfiguration)33 Test (org.junit.Test)30 AbstractJournalTest (com.questdb.net.ha.AbstractJournalTest)25 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 ResponseContentBufferTooSmallException (com.questdb.ex.ResponseContentBufferTooSmallException)3 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)3 RecordSource (com.questdb.ql.RecordSource)3 JournalEntryWriter (com.questdb.store.JournalEntryWriter)3 SocketException (java.net.SocketException)3 HttpServer (com.questdb.net.http.HttpServer)2 SimpleUrlMatcher (com.questdb.net.http.SimpleUrlMatcher)2 UploadHandler (com.questdb.net.http.handlers.UploadHandler)2 DoubleRecordSourceColumn (com.questdb.ql.ops.col.DoubleRecordSourceColumn)2