Search in sources :

Example 66 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalRefreshTest method testRefreshScenarios.

@Test
public void testRefreshScenarios() throws JournalException {
    // initial data
    rw.append(new Quote().setSym("IMO-1").setTimestamp(Dates.toMillis(2013, 1, 10, 10, 0)));
    rw.append(new Quote().setSym("IMO-2").setTimestamp(Dates.toMillis(2013, 1, 10, 14, 0)));
    rw.commit();
    try (Journal<Quote> r = getFactory().reader(Quote.class)) {
        Assert.assertEquals(2, r.size());
        // append data to same partition
        rw.append(new Quote().setSym("IMO-1").setTimestamp(Dates.toMillis(2013, 1, 10, 15, 0)));
        rw.append(new Quote().setSym("IMO-2").setTimestamp(Dates.toMillis(2013, 1, 10, 16, 0)));
        rw.commit();
        // check that size didn't change before we call refresh
        Assert.assertEquals(2, r.size());
        // check that we see two more rows after refresh
        r.refresh();
        Assert.assertEquals(4, r.size());
        // append data to new partition
        rw.append(new Quote().setSym("IMO-3").setTimestamp(Dates.toMillis(2013, 2, 10, 15, 0)));
        rw.append(new Quote().setSym("IMO-4").setTimestamp(Dates.toMillis(2013, 2, 10, 16, 0)));
        // check that size didn't change before we call refresh
        Assert.assertEquals(4, r.size());
        // check that we don't see rows even if we refresh
        r.refresh();
        Assert.assertEquals(4, r.size());
        rw.commit();
        // check that we see two more rows after refresh
        r.refresh();
        Assert.assertEquals(6, r.size());
        List<Quote> data = new ArrayList<>();
        data.add(new Quote().setSym("IMO-5").setTimestamp(Dates.toMillis(2013, 3, 10, 15, 0)));
        data.add(new Quote().setSym("IMO-6").setTimestamp(Dates.toMillis(2013, 3, 10, 16, 0)));
        rw.mergeAppend(data);
        rw.commit();
        // check that size didn't change before we call refresh
        Assert.assertEquals(6, r.size());
        // check that we see two more rows after refresh
        r.refresh();
        Assert.assertEquals(8, r.size());
    }
}
Also used : Quote(com.questdb.model.Quote) ArrayList(java.util.ArrayList) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 67 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalRefreshTest method testIllegalArgExceptionInStorage.

@Test
public void testIllegalArgExceptionInStorage() throws JournalException {
    rw.append(new Quote().setMode("A").setSym("B").setEx("E1").setAsk(10).setAskSize(1000).setBid(9).setBidSize(900).setTimestamp(System.currentTimeMillis()));
    rw.compact();
    rw.commit();
    rw.close();
    try (Journal<Quote> reader = getFactory().reader(Quote.class)) {
        reader.query().all().asResultSet().read();
        try (JournalWriter<Quote> writer = getFactory().writer(Quote.class)) {
            writer.append(new Quote().setMode("A").setSym("B").setEx("E1").setAsk(10).setAskSize(1000).setBid(9).setBidSize(900).setTimestamp(System.currentTimeMillis()));
            Quote expected = new Quote().setMode("A").setSym("B22").setEx("E1").setAsk(10).setAskSize(1000).setBid(9).setBidSize(900).setTimestamp(System.currentTimeMillis());
            writer.append(expected);
            writer.commit();
            reader.refresh();
            ResultSet<Quote> rs = reader.query().all().asResultSet();
            // at this point we used to get an IllegalArgumentException because we
            // were reaching outside of buffer of compacted column
            Quote q = rs.read(rs.size() - 1);
            Assert.assertEquals(expected, q);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 68 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalTest method testTxTumbleDrier.

@Test
public void testTxTumbleDrier() throws Exception {
    int SIZE = 1000000;
    try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin", SIZE / 12)) {
        try (JournalWriter<Quote> w = getFactory().writer(Quote.class, "q", SIZE / 12)) {
            TestUtils.generateQuoteData(origin, SIZE, DateFormatUtils.parseDateTime("2014-01-30T00:11:00.000Z"), 100000);
            origin.commit();
            ResultSet<Quote> originRs = origin.query().all().asResultSet();
            int blockSize = 5130;
            Rnd rnd = new Rnd(System.currentTimeMillis(), System.nanoTime());
            try {
                for (int i = 0; i < originRs.size(); ) {
                    int d = Math.min(i + blockSize, originRs.size());
                    ResultSet<Quote> rs = originRs.subset(i, d);
                    w.append(rs);
                    if (rnd.nextBoolean()) {
                        w.commit();
                        i += blockSize;
                    } else {
                        w.rollback();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            Assert.assertFalse(w.isTxActive());
            TestUtils.assertDataEquals(origin, w);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) Rnd(com.questdb.std.Rnd) JournalException(com.questdb.std.ex.JournalException) NumericException(com.questdb.common.NumericException) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 69 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalTest method testReindex.

@Test
public void testReindex() throws JournalException, NumericException {
    File path;
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
        TestData.appendQuoteData1(w);
        path = w.getLocation();
    }
    getFactory().lock(Quote.class.getName());
    try {
        Files.deleteOrException(new File(path, "2013-02/sym.r"));
        Files.deleteOrException(new File(path, "2013-02/sym.k"));
    } finally {
        getFactory().unlock(Quote.class.getName());
    }
    try (Journal<Quote> journal = getFactory().reader(Quote.class)) {
        try {
            journal.query().head().withKeys().asResultSet().read();
            Assert.fail("Expected exception here");
        } catch (JournalException e) {
        // do nothing
        }
        try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
            w.rebuildIndexes();
        }
        Assert.assertEquals(3, journal.query().head().withKeys().asResultSet().read().length);
    }
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 70 with Quote

use of com.questdb.model.Quote in project questdb by bluestreak01.

the class JournalTest method testOpenJournalWithWrongPartitionType.

@Test
public void testOpenJournalWithWrongPartitionType() throws Exception {
    try (JournalWriter<Quote> w = getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.NONE))) {
        TestUtils.generateQuoteData(w, 1000);
    }
    try {
        getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.MONTH));
        Assert.fail("Exception expected");
    } catch (JournalException e) {
    // expect exception
    }
    try (Factory f2 = new Factory(new JournalConfigurationBuilder() {

        {
            $(Quote.class).$sym("mode");
        }
    }.build(factoryContainer.getConfiguration().getJournalBase()))) {
        f2.writer(new JournalKey<>(Quote.class, "quote"));
        Assert.fail("Exception expected");
    } catch (JournalException e) {
    // expect exception
    }
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

Quote (com.questdb.model.Quote)80 Test (org.junit.Test)64 AbstractTest (com.questdb.test.tools.AbstractTest)63 ClientConfig (com.questdb.net.ha.config.ClientConfig)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 JournalException (com.questdb.std.ex.JournalException)11 ServerConfig (com.questdb.net.ha.config.ServerConfig)10 ArrayList (java.util.ArrayList)9 Interval (com.questdb.std.time.Interval)8 InputStream (java.io.InputStream)6 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)5 File (java.io.File)5 JournalListener (com.questdb.store.JournalListener)4 ServerNode (com.questdb.net.ha.config.ServerNode)3 RecordSource (com.questdb.ql.RecordSource)3 Rnd (com.questdb.std.Rnd)3 StringSink (com.questdb.std.str.StringSink)3 Ignore (org.junit.Ignore)3 NumericException (com.questdb.common.NumericException)2