Search in sources :

Example 6 with ImportHandler

use of com.questdb.net.http.handlers.ImportHandler in project questdb by bluestreak01.

the class HttpServerTest method testImportWrongType.

@Test
public void testImportWrongType() throws Exception {
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration();
    env.factory = getFactory();
    env.typeProbeCollection = TYPE_PROBE_COLLECTION;
    env.dateLocaleFactory = DateLocaleFactory.INSTANCE;
    env.dateFormatFactory = DATE_FORMAT_FACTORY;
    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", "[{\"name\":\"IsoDate\", \"type\":\"DATE\"}, {\"name\":\"IntCol\", \"type\":\"DOUBLE\"}]", null));
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", "[{\"name\":\"IsoDate\", \"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(StrSym), count(IntSym), count(IntCol), count(long), count() from 'test-import.csv'");
        try {
            printer.print(src1, env.factory);
            TestUtils.assertEquals("252\t252\t256\t258\t258\n", sink);
        } finally {
            Misc.free(src1);
        }
        RecordSource src2 = qc.compile(env.factory, "'test-import.csv'");
        try {
            Assert.assertEquals(ColumnType.DOUBLE, src2.getMetadata().getColumn("IntCol").getType());
        } finally {
            Misc.free(src2);
        }
    } 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 7 with ImportHandler

use of com.questdb.net.http.handlers.ImportHandler in project questdb by bluestreak01.

the class HttpServerTest method testImportUnknownFormat.

@Test
public void testImportUnknownFormat() {
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration();
    env.factory = getFactory();
    env.matcher = new SimpleUrlMatcher() {

        {
            put("/imp", new ImportHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    StringBuilder response = new StringBuilder();
    try {
        Assert.assertEquals(400, HttpTestUtils.upload("/com/questdb/std/AssociativeCache.class", "http://localhost:9000/imp", null, response));
        TestUtils.assertEquals("Unsupported Data Format", response);
    } catch (IOException e) {
        Assert.assertTrue(e.getMessage().contains("Connection reset"));
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) ServerConfiguration(com.questdb.ServerConfiguration) ImportHandler(com.questdb.net.http.handlers.ImportHandler) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 8 with ImportHandler

use of com.questdb.net.http.handlers.ImportHandler in project questdb by bluestreak01.

the class HttpServerTest method testImportOverwrite.

@Test
public void testImportOverwrite() 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 {
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", null, null));
        printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory());
        TestUtils.assertEquals("129\n", sink);
        sink.clear();
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-headers.csv", "http://localhost:9000/imp?name=test-import.csv&overwrite=true&durable=true", null, null));
        printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory());
        TestUtils.assertEquals("5\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 9 with ImportHandler

use of com.questdb.net.http.handlers.ImportHandler in project questdb by bluestreak01.

the class HttpServerTest method testImportForcedHeader.

@Test
public void testImportForcedHeader() 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-explicit-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 10 with ImportHandler

use of com.questdb.net.http.handlers.ImportHandler in project questdb by bluestreak01.

the class HttpServerTest method testConcurrentImport.

@Test
public void testConcurrentImport() throws Exception {
    final 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();
    final CyclicBarrier barrier = new CyclicBarrier(2);
    final CountDownLatch latch = new CountDownLatch(2);
    try {
        new Thread(() -> {
            try {
                barrier.await();
                Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", null, null));
                latch.countDown();
            } catch (Exception e) {
                Assert.fail(e.getMessage());
            }
        }).start();
        new Thread(() -> {
            try {
                barrier.await();
                Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import-nan.csv", "http://localhost:9000/imp", null, null));
                latch.countDown();
            } catch (Exception e) {
                Assert.fail(e.getMessage());
            }
        }).start();
        latch.await();
        try (Journal r = getFactory().reader("test-import.csv")) {
            Assert.assertEquals("First failed", 129, r.size());
        }
        try (Journal r = getFactory().reader("test-import-nan.csv")) {
            Assert.assertEquals("Second failed", 129, r.size());
        }
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) ServerConfiguration(com.questdb.ServerConfiguration) ImportHandler(com.questdb.net.http.handlers.ImportHandler) Journal(com.questdb.store.Journal) CountDownLatch(java.util.concurrent.CountDownLatch) ResponseContentBufferTooSmallException(com.questdb.ex.ResponseContentBufferTooSmallException) SocketException(java.net.SocketException) CyclicBarrier(java.util.concurrent.CyclicBarrier) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Aggregations

BootstrapEnv (com.questdb.BootstrapEnv)13 ServerConfiguration (com.questdb.ServerConfiguration)13 AbstractJournalTest (com.questdb.net.ha.AbstractJournalTest)13 ImportHandler (com.questdb.net.http.handlers.ImportHandler)13 Test (org.junit.Test)13 QueryCompiler (com.questdb.parser.sql.QueryCompiler)9 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)9 StringSink (com.questdb.std.str.StringSink)9 RecordSource (com.questdb.ql.RecordSource)3 JournalWriter (com.questdb.store.JournalWriter)2 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)2 ResponseContentBufferTooSmallException (com.questdb.ex.ResponseContentBufferTooSmallException)1 Journal (com.questdb.store.Journal)1 JournalEntryWriter (com.questdb.store.JournalEntryWriter)1 WriterFactory (com.questdb.store.factory.WriterFactory)1 SocketException (java.net.SocketException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1