Search in sources :

Example 36 with Quote

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

the class JournalTest method testSizeAfterCompaction.

@Test
public void testSizeAfterCompaction() throws JournalException, NumericException {
    long sizeAfterCompaction;
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class, "quote", 1000000)) {
        TestData.appendQuoteData2(w);
    }
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class, "quote")) {
        File f = new File(w.getLocation(), "2013-03/sym.d");
        long size = f.length();
        w.compact();
        sizeAfterCompaction = f.length();
        Assert.assertTrue(sizeAfterCompaction < size);
    }
    try (Journal<Quote> r = getFactory().reader(Quote.class, "quote")) {
        Assert.assertEquals(1000, r.query().all().size());
        File f = new File(r.getLocation(), "2013-03/sym.d");
        Assert.assertEquals(sizeAfterCompaction, f.length());
    }
}
Also used : Quote(com.questdb.model.Quote) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 37 with Quote

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

the class JournalTest method testTxLagTumbleDrier.

@Test
public void testTxLagTumbleDrier() 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());
                    w.mergeAppend(originRs.subset(i, d));
                    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 38 with Quote

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

the class LagTest method testLagAppendScenarios.

@Test
public void testLagAppendScenarios() throws JournalException {
    // initial data
    List<Quote> data1 = new ArrayList<>();
    data1.add(new Quote().setSym("S1").setTimestamp(Dates.toMillis(2013, 1, 10, 10, 0)));
    data1.add(new Quote().setSym("S2").setTimestamp(Dates.toMillis(2013, 1, 10, 14, 0)));
    rw.mergeAppend(data1);
    rw.commit();
    File loc;
    try (Journal<Quote> reader = getFactory().reader(Quote.class)) {
        reader.query().all().asResultSet().read();
        loc = reader.getLocation();
        // simple append scenario
        List<Quote> data2 = new ArrayList<>();
        data2.add(new Quote().setSym("S3").setTimestamp(Dates.toMillis(2013, 1, 10, 15, 0)));
        data2.add(new Quote().setSym("S4").setTimestamp(Dates.toMillis(2013, 1, 10, 16, 0)));
        rw.mergeAppend(data2);
        // simple append + lag split (30 days increment)
        List<Quote> data3 = new ArrayList<>();
        data3.add(new Quote().setSym("S8").setTimestamp(Dates.toMillis(2013, 2, 10, 15, 0)));
        data3.add(new Quote().setSym("S9").setTimestamp(Dates.toMillis(2013, 2, 10, 16, 0)));
        rw.mergeAppend(data3);
        // data on fully above lag
        List<Quote> data4 = new ArrayList<>();
        data4.add(new Quote().setSym("S6").setTimestamp(Dates.toMillis(2013, 2, 10, 10, 0)));
        data4.add(new Quote().setSym("S7").setTimestamp(Dates.toMillis(2013, 2, 10, 11, 0)));
        rw.mergeAppend(data4);
        // lag is fully inside data
        List<Quote> data5 = new ArrayList<>();
        data5.add(new Quote().setSym("S5").setTimestamp(Dates.toMillis(2013, 2, 10, 9, 0)));
        data5.add(new Quote().setSym("S10").setTimestamp(Dates.toMillis(2013, 2, 10, 17, 0)));
        rw.mergeAppend(data5);
        // lag and data have equal boundaries
        List<Quote> data6 = new ArrayList<>();
        data6.add(new Quote().setSym("near-S5").setTimestamp(Dates.toMillis(2013, 2, 10, 9, 0)));
        data6.add(new Quote().setSym("near-S10").setTimestamp(Dates.toMillis(2013, 2, 10, 17, 0)));
        rw.mergeAppend(data6);
        // bottom part of data overlaps top part of lag
        List<Quote> data7 = new ArrayList<>();
        data7.add(new Quote().setSym("after-S4").setTimestamp(Dates.toMillis(2013, 2, 9, 9, 0)));
        data7.add(new Quote().setSym("after-S9").setTimestamp(Dates.toMillis(2013, 2, 10, 16, 30)));
        rw.mergeAppend(data7);
        // top part of data overlaps bottom part of lag
        List<Quote> data8 = new ArrayList<>();
        data8.add(new Quote().setSym("after-S8").setTimestamp(Dates.toMillis(2013, 2, 10, 15, 30)));
        data8.add(new Quote().setSym("after-S10").setTimestamp(Dates.toMillis(2013, 2, 10, 18, 30)));
        rw.mergeAppend(data8);
        // data is fully inside of lag
        List<Quote> data9 = new ArrayList<>();
        data9.add(new Quote().setSym("after-S6").setTimestamp(Dates.toMillis(2013, 2, 10, 10, 30)));
        data9.add(new Quote().setSym("before-S10").setTimestamp(Dates.toMillis(2013, 2, 10, 16, 45)));
        rw.mergeAppend(data9);
        // full discard
        List<Quote> data10 = new ArrayList<>();
        data10.add(new Quote().setSym("discard-S1").setTimestamp(Dates.toMillis(2013, 1, 1, 10, 30)));
        data10.add(new Quote().setSym("discard-S2").setTimestamp(Dates.toMillis(2013, 1, 1, 16, 45)));
        rw.mergeAppend(data10);
        // full discard
        List<Quote> data11 = new ArrayList<>();
        data11.add(new Quote().setSym("discard-S3").setTimestamp(Dates.toMillis(2013, 1, 1, 10, 30)));
        data11.add(new Quote().setSym("before-S6").setTimestamp(Dates.toMillis(2013, 2, 10, 9, 45)));
        rw.mergeAppend(data11);
        String[] expected = { "S1", "S2", "S3", "S4", "after-S4", "S5", "near-S5", "before-S6", "S6", "after-S6", "S7", "S8", "after-S8", "S9", "after-S9", "before-S10", "S10", "near-S10", "after-S10" };
        int i = 0;
        for (Quote p : rw) {
            Assert.assertEquals("Order incorrect", expected[i++], p.getSym());
        }
        rw.commit();
        Assert.assertEquals("Journal size mismatch", 19L, rw.size());
        Assert.assertEquals("Partition count mismatch", 3, rw.getPartitionCount());
        Assert.assertEquals("Lag size mismatch", 14L, rw.openOrCreateLagPartition().size());
        rw.close();
        reader.refresh();
        reader.query().all().asResultSet().read();
    }
    getFactory().lock(Quote.class.getName());
    String[] tempDirs = loc.list((dir, name) -> name.startsWith("temp") && !name.endsWith(".lock"));
    Assert.assertNotNull(tempDirs);
    Assert.assertEquals(1, tempDirs.length);
}
Also used : Quote(com.questdb.model.Quote) ArrayList(java.util.ArrayList) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 39 with Quote

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

the class PartitionTest method testIndexOf.

@Test
public void testIndexOf() throws JournalException, NumericException {
    try (JournalWriter<Quote> journal = getFactory().writer(Quote.class)) {
        long ts1 = DateFormatUtils.parseDateTime("2012-06-05T00:00:00.000Z");
        long ts2 = DateFormatUtils.parseDateTime("2012-07-03T00:00:00.000Z");
        long ts3 = DateFormatUtils.parseDateTime("2012-06-04T00:00:00.000Z");
        long ts4 = DateFormatUtils.parseDateTime("2012-06-06T00:00:00.000Z");
        Quote q9 = new Quote().setSym("S5").setTimestamp(ts3);
        Quote q10 = new Quote().setSym("S5").setTimestamp(ts4);
        Quote q1 = new Quote().setSym("S1").setTimestamp(ts1);
        Quote q2 = new Quote().setSym("S2").setTimestamp(ts1);
        Quote q3 = new Quote().setSym("S3").setTimestamp(ts1);
        Quote q4 = new Quote().setSym("S4").setTimestamp(ts1);
        Quote q5 = new Quote().setSym("S1").setTimestamp(ts2);
        Quote q6 = new Quote().setSym("S2").setTimestamp(ts2);
        Quote q7 = new Quote().setSym("S3").setTimestamp(ts2);
        Quote q8 = new Quote().setSym("S4").setTimestamp(ts2);
        journal.append(q9);
        journal.append(q1);
        journal.append(q2);
        journal.append(q3);
        journal.append(q4);
        journal.append(q10);
        journal.append(q5);
        journal.append(q6);
        journal.append(q7);
        journal.append(q8);
        Assert.assertEquals(2, journal.getPartitionCount());
        long tsA = DateFormatUtils.parseDateTime("2012-06-15T00:00:00.000Z");
        Partition<Quote> partition1 = getPartitionForTimestamp(journal, tsA).open();
        Assert.assertNotNull("getPartition(timestamp) failed", partition1);
        Assert.assertEquals(-2, partition1.indexOf(tsA, BSearchType.NEWER_OR_SAME));
        Assert.assertEquals(-1, partition1.indexOf(DateFormatUtils.parseDateTime("2012-06-03T00:00:00.000Z"), BSearchType.OLDER_OR_SAME));
        Assert.assertEquals(0, partition1.indexOf(DateFormatUtils.parseDateTime("2012-06-03T00:00:00.000Z"), BSearchType.NEWER_OR_SAME));
        Assert.assertEquals(4, partition1.indexOf(ts1, BSearchType.OLDER_OR_SAME));
        Assert.assertEquals(1, partition1.indexOf(ts1, BSearchType.NEWER_OR_SAME));
        Partition<Quote> p = journal.openOrCreateLagPartition();
        long result = p.indexOf(DateFormatUtils.parseDateTime("2012-06-15T00:00:00.000Z"), BSearchType.OLDER_OR_SAME);
        Assert.assertEquals(-1, result);
    }
}
Also used : Quote(com.questdb.model.Quote) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 40 with Quote

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

the class QueryTest method testLatestByKeyWithinMonths.

@Test
public void testLatestByKeyWithinMonths() throws Exception {
    long max = w.getAppendTimestampLo();
    long inc = System.currentTimeMillis() - max;
    try (JournalWriter<Quote> w2 = getFactory().writer(Quote.class, "w2")) {
        for (Quote a : JournalIterators.bufferedIterator(q.getJournal())) {
            a.setTimestamp(a.getTimestamp() + inc);
            w2.append(a);
        }
        Query<Quote> q = w2.query();
        long millis;
        Interval interval = new Interval(Dates.addMonths(millis = System.currentTimeMillis(), -1), millis);
        UnorderedResultSet<Quote> rs = q.getJournal().query().head().withKeys().limit(interval).asResultSet();
        Assert.assertEquals(10, rs.size());
    }
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) 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