Search in sources :

Example 76 with JournalWriter

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

the class GenericBinaryTest method testUnclosedOutputOutput.

@Test
public void testUnclosedOutputOutput() throws Exception {
    try (JournalWriter writer = getGenericWriter()) {
        List<byte[]> expected = getBytes();
        for (int i = 0; i < expected.size(); i++) {
            JournalEntryWriter w = writer.entryWriter();
            w.putBin(0).write(expected.get(i));
            w.append();
        }
        writer.commit();
        assertEquals(expected, readOutputStream());
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 77 with JournalWriter

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

the class GenericBinaryTest method testInputOutput.

@Test
public void testInputOutput() throws Exception {
    try (JournalWriter writer = getGenericWriter()) {
        List<byte[]> expected = getBytes();
        writeInputStream(writer, expected);
        assertEquals(expected, readOutputStream());
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 78 with JournalWriter

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

the class GenericInteropTest method testPartialObjectReader.

@Test
public void testPartialObjectReader() throws Exception {
    try (JournalWriter writer = makeGenericWriter()) {
        JournalEntryWriter w = writer.entryWriter();
        w.putSym(0, "EURUSD");
        w.putDate(1, 19999);
        w.putDouble(2, 1.24);
        w.putDouble(3, 1.25);
        w.putInt(4, 10000);
        w.putInt(5, 12000);
        w.putInt(6, 1);
        w.putStr(7, "OK");
        w.putStr(8, "system");
        w.putStr(9, "EURUSD:GLOBAL");
        w.putBool(10, true);
        w.putNull(11);
        w.putLong(12, 13141516);
        w.putShort(13, (short) 25000);
        w.append();
        writer.commit();
    }
    try (Journal<Partial> reader = getFactory().reader(Partial.class, "test")) {
        String expected = "Partial{sym='EURUSD', created=19999, bid=1.24, ask=1.25, bidSize=10000, askSize=12000}";
        StringBuilder builder = new StringBuilder();
        for (Partial p : JournalIterators.bufferedIterator(reader)) {
            builder.append(p);
        }
        TestUtils.assertEquals(expected, builder);
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 79 with JournalWriter

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

the class GenericInteropTest method testInvalidColumnName.

@Test
public void testInvalidColumnName() throws Exception {
    File location = null;
    try (JournalWriter w = getFactory().writer(new JournalStructure("test") {

        {
            $int("id").index();
            $str("status?\0x");
        }
    })) {
        location = w.getLocation();
        w.entryWriter();
    } catch (JournalException ignore) {
    // ignore
    }
    Assert.assertNotNull(location);
    Files.deleteOrException(location);
    try (JournalWriter w = getFactory().writer(new JournalStructure("test") {

        {
            $int("id").index();
            $str("status");
        }
    })) {
        w.entryWriter();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalException(com.questdb.std.ex.JournalException) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 80 with JournalWriter

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

the class GenericInteropTest method testGenericStructureMismatch.

@Test
public void testGenericStructureMismatch() throws Exception {
    try (JournalWriter writer = makeGenericWriter()) {
        JournalEntryWriter w = writer.entryWriter();
        w.putSym(0, "EURUSD");
        w.putDate(1, 19999);
        w.putDouble(2, 1.24);
        w.putDouble(3, 1.25);
        w.putInt(4, 10000);
        w.putInt(5, 12000);
        w.putInt(6, 1);
        w.putStr(7, "OK");
        w.putStr(8, "system");
        w.putStr(9, "EURUSD:GLOBAL");
        w.putBool(10, true);
        w.putNull(11);
        w.putLong(12, 13141516);
        w.putShort(13, (short) 25000);
        w.append();
        writer.commit();
        writer.close();
    }
    try {
        getFactory().writer(new JournalStructure("test") {

            {
                $str("sym");
                $date("created");
            }
        });
        Assert.fail("Expected exception");
    } catch (JournalMetadataException ignore) {
    // expected
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) JournalMetadataException(com.questdb.ex.JournalMetadataException) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

JournalWriter (com.questdb.store.JournalWriter)93 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)60 JournalEntryWriter (com.questdb.store.JournalEntryWriter)59 AbstractTest (com.questdb.test.tools.AbstractTest)54 Test (org.junit.Test)52 Rnd (com.questdb.std.Rnd)42 BeforeClass (org.junit.BeforeClass)12 CountDownLatch (java.util.concurrent.CountDownLatch)9 RecordCursor (com.questdb.common.RecordCursor)6 JournalException (com.questdb.std.ex.JournalException)6 Record (com.questdb.common.Record)5 RecordSource (com.questdb.ql.RecordSource)5 Factory (com.questdb.store.factory.Factory)5 BootstrapEnv (com.questdb.BootstrapEnv)4 ServerConfiguration (com.questdb.ServerConfiguration)4 JournalLockedException (com.questdb.ex.JournalLockedException)4 ClientConfig (com.questdb.net.ha.config.ClientConfig)4 ServerConfig (com.questdb.net.ha.config.ServerConfig)4 ServerNode (com.questdb.net.ha.config.ServerNode)4 StringSink (com.questdb.std.str.StringSink)4