Search in sources :

Example 31 with ServerConfiguration

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

the class HttpServerTest method testFragmentedUrl.

@Test
public void testFragmentedUrl() throws Exception {
    final long tick = DateFormatUtils.parseDateTime("2015-12-05T13:30:00.000Z");
    final BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration();
    env.matcher = new SimpleUrlMatcher();
    HttpServer server = new HttpServer(env);
    server.setClock(() -> tick);
    server.start();
    try (SocketChannel channel = openChannel()) {
        ByteBuffer buf = ByteBuffer.allocate(1024);
        ByteBuffer out = ByteBuffer.allocate(1024);
        int n = 5;
        for (int i = 0; i < n; i++) {
            buf.put((byte) request.charAt(i));
        }
        buf.flip();
        ByteBuffers.copy(buf, channel);
        buf.clear();
        for (int i = n; i < request.length(); i++) {
            buf.put((byte) request.charAt(i));
        }
        buf.flip();
        ByteBuffers.copy(buf, channel);
        channel.configureBlocking(false);
        ByteBuffers.copyGreedyNonBlocking(channel, out, 100000);
        final String expected = "HTTP/1.1 404 Not Found\r\n" + "Server: questDB/1.0\r\n" + "Date: Sat, 5 Dec 2015 13:30:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: text/html; charset=utf-8\r\n" + "\r\n" + "b\r\n" + "Not Found\r\n" + "\r\n" + "0\r\n" + "\r\n";
        Assert.assertEquals(expected.length(), out.remaining());
        for (int i = 0, k = expected.length(); i < k; i++) {
            Assert.assertEquals(expected.charAt(i), out.get());
        }
    } finally {
        server.halt();
    }
}
Also used : SocketChannel(java.nio.channels.SocketChannel) BootstrapEnv(com.questdb.BootstrapEnv) ServerConfiguration(com.questdb.ServerConfiguration) ByteBuffer(java.nio.ByteBuffer) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 32 with ServerConfiguration

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

the class HttpServerTest method testDefaultDirIndex.

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

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        HttpTestUtils.download(clientBuilder(false), "http://localhost:9000/", new File(temp.getRoot(), "index.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)

Example 33 with ServerConfiguration

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

the class HttpServerTest method testImportNumberPrefixedColumn.

@Test
public void testImportNumberPrefixedColumn() throws Exception {
    final ServerConfiguration configuration = new ServerConfiguration();
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = configuration;
    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-num-prefix.csv", "http://localhost:9000/imp?fmt=json", null, null));
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        try (RecordSource rs = qc.compile(env.factory, "select count(StrSym), count(IntSym), count(_1IntCol), count(long), count() from 'test-import-num-prefix.csv'")) {
            printer.print(rs, env.factory);
        }
        TestUtils.assertEquals("126\t126\t128\t129\t129\n", sink);
    } 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 34 with ServerConfiguration

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

the class HttpServerTest method testImportIntoBusyJournal2.

@Test
public void testImportIntoBusyJournal2() throws Exception {
    WriterFactory f = getFactory();
    try (JournalWriter w = f.writer(new JournalStructure("small.csv").$int("X").$int("Y").$())) {
        JournalEntryWriter ew = w.entryWriter();
        ew.putInt(0, 3);
        ew.putInt(1, 30);
        ew.append();
        w.commit();
        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();
        StringBuilder response = new StringBuilder();
        try {
            Assert.assertEquals(200, HttpTestUtils.upload("/csv/small.csv", "http://localhost:9000/imp?fmt=json", null, response));
            Assert.assertTrue(Chars.startsWith(response, "{\"status\":\"com.questdb.ex.WriterBusyException\"}"));
        } catch (IOException e) {
            Assert.assertTrue(e.getMessage().contains("Connection reset"));
        } finally {
            server.halt();
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) BootstrapEnv(com.questdb.BootstrapEnv) WriterFactory(com.questdb.store.factory.WriterFactory) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) ServerConfiguration(com.questdb.ServerConfiguration) ImportHandler(com.questdb.net.http.handlers.ImportHandler) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 35 with ServerConfiguration

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

the class HttpServerTest method testNativeConcurrentDownload.

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

        {
            setDefaultHandler(new StaticContentHandler(env));
        }
    };
    final MimeTypes mimeTypes = new MimeTypes(env.configuration.getMimeTypes());
    HttpServer server = new HttpServer(env);
    server.start();
    assertConcurrentDownload(mimeTypes, server, "http");
}
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