Search in sources :

Example 1 with Journal

use of com.questdb.store.Journal 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)

Example 2 with Journal

use of com.questdb.store.Journal in project questdb by bluestreak01.

the class PlainTextLexerTest method testImport.

@Test
public void testImport() throws Exception {
    String file = this.getClass().getResource("/csv/test-import.csv").getFile();
    ImportManager.importFile(getFactory(), file, PlainTextDelimiter.CSV, null, false);
    String location = "test-import.csv";
    Assert.assertEquals(JournalConfiguration.EXISTS, getFactory().getConfiguration().exists(location));
    try (Journal r = getFactory().reader(location)) {
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(10, m.getColumnCount());
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(0).type);
        Assert.assertEquals(ColumnType.INT, m.getColumnQuick(1).type);
        Assert.assertEquals(ColumnType.INT, m.getColumnQuick(2).type);
        Assert.assertEquals(ColumnType.DOUBLE, m.getColumnQuick(3).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(4).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(5).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(6).type);
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(7).type);
        Assert.assertEquals(ColumnType.BOOLEAN, m.getColumnQuick(8).type);
        Assert.assertEquals(ColumnType.LONG, m.getColumnQuick(9).type);
    }
    File actual = new File(getFactory().getConfiguration().getJournalBase(), "exp.csv");
    File expected = new File(this.getClass().getResource("/csv/test-export-expected.csv").getFile());
    try (RecordSource rs = compile("'" + location + "'")) {
        ExportManager.export(rs, getFactory(), actual, PlainTextDelimiter.CSV);
        TestUtils.assertEquals(expected, actual);
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) RecordSource(com.questdb.ql.RecordSource) Journal(com.questdb.store.Journal) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 3 with Journal

use of com.questdb.store.Journal in project questdb by bluestreak01.

the class PlainTextLexerTest method testImportMalformedQuote.

@Test
public void testImportMalformedQuote() throws Exception {
    String file = this.getClass().getResource("/csv/test-import-malformed.csv").getFile();
    ImportManager.importFile(getFactory(), file, PlainTextDelimiter.CSV, null, false);
    String location = "test-import-malformed.csv";
    Assert.assertEquals(JournalConfiguration.EXISTS, factoryContainer.getConfiguration().exists(location));
    try (Journal r = getFactory().reader(location)) {
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(10, m.getColumnCount());
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(0).type);
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(1).type);
        Assert.assertEquals(ColumnType.INT, m.getColumnQuick(2).type);
        Assert.assertEquals(ColumnType.DOUBLE, m.getColumnQuick(3).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(4).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(5).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(6).type);
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(7).type);
        Assert.assertEquals(ColumnType.BOOLEAN, m.getColumnQuick(8).type);
        Assert.assertEquals(ColumnType.LONG, m.getColumnQuick(9).type);
    }
    File actual = new File(factoryContainer.getConfiguration().getJournalBase(), "exp.csv");
    File expected = new File(this.getClass().getResource("/csv/test-import-malformed-expected.csv").getFile());
    try (RecordSource rs = compile("'" + location + "'")) {
        ExportManager.export(rs, getFactory(), actual, PlainTextDelimiter.CSV);
        TestUtils.assertEquals(expected, actual);
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) RecordSource(com.questdb.ql.RecordSource) Journal(com.questdb.store.Journal) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 4 with Journal

use of com.questdb.store.Journal in project questdb by bluestreak01.

the class JournalServerAgent method close.

public void close() {
    server.getBridge().removeAgentSequence(eventProcessor.getSequence());
    journalClientStateConsumer.free();
    commandConsumer.free();
    setKeyRequestConsumer.free();
    intResponseConsumer.free();
    byteArrayResponseConsumer.free();
    commandProducer.free();
    stringResponseProducer.free();
    intResponseProducer.free();
    for (int i = 0, n = readers.size(); i < n; i++) {
        Journal r = readers.getQuick(i);
        if (r != null) {
            r.close();
        }
    }
    for (int i = 0, k = producers.size(); i < k; i++) {
        producers.getQuick(i).free();
    }
}
Also used : Journal(com.questdb.store.Journal)

Example 5 with Journal

use of com.questdb.store.Journal in project questdb by bluestreak01.

the class DDLTests method testCreateDefaultPartitionBy.

@Test
public void testCreateDefaultPartitionBy() throws Exception {
    exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40, l LONG index buckets 500) record hint 100");
    // validate journal
    try (Journal r = getFactory().reader("x")) {
        Assert.assertNotNull(r);
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(5, m.getColumnCount());
        Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
        Assert.assertTrue(m.getColumn("a").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(1, m.getColumn("a").getBucketCount());
        Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
        Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
        Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
        Assert.assertTrue(m.getColumn("z").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(63, m.getColumn("z").getBucketCount());
        Assert.assertEquals(ColumnType.LONG, m.getColumn("l").getType());
        Assert.assertTrue(m.getColumn("l").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(511, m.getColumn("l").getBucketCount());
        Assert.assertEquals(-1, m.getTimestampIndex());
        Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy());
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) Journal(com.questdb.store.Journal) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

Journal (com.questdb.store.Journal)27 Test (org.junit.Test)24 AbstractTest (com.questdb.test.tools.AbstractTest)23 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)14 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)9 RetryLockException (com.questdb.ex.RetryLockException)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 FactoryFullException (com.questdb.ex.FactoryFullException)4 JournalLockedException (com.questdb.ex.JournalLockedException)4 JournalException (com.questdb.std.ex.JournalException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 JournalDeltaProducer (com.questdb.net.ha.producer.JournalDeltaProducer)2 RecordSource (com.questdb.ql.RecordSource)2 Rnd (com.questdb.std.Rnd)2 File (java.io.File)2 BootstrapEnv (com.questdb.BootstrapEnv)1 ServerConfiguration (com.questdb.ServerConfiguration)1 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1