Search in sources :

Example 16 with Journal

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

the class CachingReaderFactoryTest method testLockUnlock.

@Test
public void testLockUnlock() throws Exception {
    // create journals
    final JournalMetadata<?> m1 = new JournalStructure("x").$date("ts").$().build();
    ((WriterFactory) getFactory()).writer(m1).close();
    final JournalMetadata<?> m2 = new JournalStructure("y").$date("ts").$().build();
    ((WriterFactory) getFactory()).writer(m2).close();
    Journal x, y;
    try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
        x = rf.reader(m1);
        Assert.assertNotNull(x);
        y = rf.reader(m2);
        Assert.assertNotNull(y);
        // expect lock to fail because we have "x" open
        try {
            rf.lock(m1.getName());
            Assert.fail();
        } catch (RetryLockException ignore) {
        }
        x.close();
        // expect lock to succeed after we closed "x"
        rf.lock(m1.getName());
        // expect "x" to be physically closed
        Assert.assertFalse(x.isOpen());
        // "x" is locked, expect this to fail
        try {
            Assert.assertNull(rf.reader(m1));
        } catch (JournalLockedException ignored) {
        }
        rf.unlock(m1.getName());
        x = rf.reader(m1);
        Assert.assertNotNull(x);
        x.close();
        Assert.assertTrue(x.isOpen());
    }
    Assert.assertTrue(y.isOpen());
    y.close();
    Assert.assertFalse(y.isOpen());
    // "x" was not busy and should be closed by factory
    Assert.assertFalse(x.isOpen());
}
Also used : JournalLockedException(com.questdb.ex.JournalLockedException) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Journal(com.questdb.store.Journal) RetryLockException(com.questdb.ex.RetryLockException) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 17 with Journal

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

the class PlainTextLexerTest method testImportSchema.

@Test
public void testImportSchema() throws Exception {
    String file = this.getClass().getResource("/csv/test-import.csv").getFile();
    String schema = "[{\"name\":\"IntSym\", \"type\":\"SYMBOL\"}, {\"name\":\"Fmt2Date\", \"type\":\"STRING\"}]";
    ImportManager.importFile(getFactory(), file, PlainTextDelimiter.CSV, schema, 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(ColumnType.SYMBOL, m.getColumnQuick(1).type);
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(6).type);
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) Journal(com.questdb.store.Journal) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 18 with Journal

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

the class DDLTests method testCreateIndexedSymbol.

@Test
public void testCreateIndexedSymbol() throws Exception {
    exec("create table x (a INT index buckets 25, b BYTE, t DATE, x SYMBOL index) timestamp(t) partition by MONTH");
    // validate journal
    try (Journal r = getFactory().reader("x")) {
        Assert.assertNotNull(r);
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(4, m.getColumnCount());
        Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
        Assert.assertTrue(m.getColumn("a").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(31, m.getColumn("a").getBucketCount());
        Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
        Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
        Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
        Assert.assertTrue(m.getColumn("x").isIndexed());
        Assert.assertEquals(2, m.getTimestampIndex());
        Assert.assertEquals(PartitionBy.MONTH, 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)

Example 19 with Journal

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

the class DDLTests method testCreateIndexWithSuffix.

@Test
public void testCreateIndexWithSuffix() throws Exception {
    exec("create table x (a INT, b BYTE, t DATE, x SYMBOL), index(a buckets 25), index(x) timestamp(t) partition by YEAR record hint 100");
    // validate journal
    try (Journal r = getFactory().reader("x")) {
        Assert.assertNotNull(r);
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(4, m.getColumnCount());
        Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
        Assert.assertTrue(m.getColumn("a").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(31, m.getColumn("a").getBucketCount());
        Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
        Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
        Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
        Assert.assertTrue(m.getColumn("x").isIndexed());
        Assert.assertEquals(2, m.getTimestampIndex());
        Assert.assertEquals(PartitionBy.YEAR, 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)

Example 20 with Journal

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

the class DDLTests method testCreateAllFieldTypes.

@Test
public void testCreateAllFieldTypes() throws Exception {
    exec("create table x (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING, y BOOLEAN) timestamp(t) partition by MONTH record hint 100");
    // validate journal
    try (Journal r = getFactory().reader("x")) {
        Assert.assertNotNull(r);
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(12, m.getColumnCount());
        Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
        Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
        Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType());
        Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType());
        Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType());
        Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType());
        Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType());
        Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType());
        Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
        Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
        Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
        Assert.assertEquals(ColumnType.BOOLEAN, m.getColumn("y").getType());
        Assert.assertEquals(8, m.getTimestampIndex());
        Assert.assertEquals(PartitionBy.MONTH, 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