Search in sources :

Example 41 with Quote

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

the class QueryTest method testIterate.

@Test
public void testIterate() {
    int count = 0;
    long timestamp = 0;
    for (Quote a : q.all().bufferedIterator()) {
        count++;
        Assert.assertTrue(timestamp <= a.getTimestamp());
        timestamp = a.getTimestamp();
    }
    Assert.assertEquals(1000, count);
}
Also used : Quote(com.questdb.model.Quote) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 42 with Quote

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

the class QueryTest method testParallelIteratorInterval.

@Test
public void testParallelIteratorInterval() throws Exception {
    Interval interval = new Interval("2013-05-04T06:40:00.000Z", "2013-05-05T17:23:20.000Z");
    try (Journal<Quote> r = getFactory().reader(Quote.class)) {
        Query<Quote> q2 = r.query();
        JournalIterator<Quote> expected = q.all().iterator(interval);
        try (ConcurrentIterator<Quote> actual = q2.all().concurrentIterator(interval)) {
            TestUtils.assertEquals(expected, actual);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 43 with Quote

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

the class QueryTest method testLatestByKeyValueOverInterval.

@Test
public void testLatestByKeyValueOverInterval() throws JournalException {
    Quote Quote = q.head().withKeys("RRS.L").limit(new Interval(ts2, ts1)).asResultSet().readFirst();
    Assert.assertNotNull(Quote);
    Assert.assertEquals(0.5590262812936236, Quote.getBid(), 0.00000000001);
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 44 with Quote

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

the class TimestampTest method testLagOnEmptyJournal.

@Test
public void testLagOnEmptyJournal() throws JournalException, NumericException {
    Quote quote21 = new Quote().setSym("123").setTimestamp(DateFormatUtils.parseDateTime("2011-09-10T10:00:00.000Z"));
    Quote quote22 = new Quote().setSym("345").setTimestamp(DateFormatUtils.parseDateTime("2011-09-11T10:00:00.000Z"));
    List<Quote> data = new ArrayList<>();
    data.add(quote21);
    data.add(quote22);
    try (JournalWriter<Quote> journal = getFactory().writer(Quote.class)) {
        journal.mergeAppend(data);
        journal.mergeAppend(data);
    }
}
Also used : Quote(com.questdb.model.Quote) ArrayList(java.util.ArrayList) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 45 with Quote

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

the class TimestampTest method testHardAndSoftTimestamps.

@Test
public void testHardAndSoftTimestamps() throws JournalException, NumericException {
    try (JournalWriter<Quote> journal = getFactory().writer(Quote.class)) {
        // make sure initial timestamp is zero
        // also, prime cache with values if there is caching going on
        Assert.assertEquals(0, journal.getAppendTimestampLo());
        Assert.assertEquals(0, journal.getMaxTimestamp());
        Quote quote21 = new Quote().setSym("123").setTimestamp(DateFormatUtils.parseDateTime("2011-09-10T10:00:00.000Z"));
        Quote quote22 = new Quote().setSym("345").setTimestamp(DateFormatUtils.parseDateTime("2011-09-11T10:00:00.000Z"));
        journal.append(quote21, quote22);
        journal.commit();
        // make sure both hard and soft timestamps are the same
        // because we are not touching lag partition
        // and also both timestamps equal to max of two timestamps we inserted
        Assert.assertEquals(DateFormatUtils.parseDateTime("2011-09-11T10:00:00.000Z"), journal.getAppendTimestampLo());
        Assert.assertEquals(journal.getMaxTimestamp(), journal.getAppendTimestampLo());
    }
    List<Quote> data = new ArrayList<>();
    // open journal again and check that timestamps are ok
    try (JournalWriter<Quote> journal = getFactory().writer(Quote.class)) {
        Assert.assertEquals(DateFormatUtils.parseDateTime("2011-09-11T10:00:00.000Z"), journal.getAppendTimestampLo());
        Assert.assertEquals(journal.getMaxTimestamp(), journal.getAppendTimestampLo());
        // utc add some more data, which goes into new partition
        Quote quote23 = new Quote().setSym("333").setTimestamp(DateFormatUtils.parseDateTime("2012-08-11T10:00:00.000Z"));
        journal.append(quote23);
        // make sure timestamps moved on
        Assert.assertEquals(DateFormatUtils.parseDateTime("2012-08-11T10:00:00.000Z"), journal.getAppendTimestampLo());
        Assert.assertEquals(journal.getMaxTimestamp(), journal.getAppendTimestampLo());
        // populate lag (lag is configured to 48 hours)
        Quote quote24 = new Quote().setSym("444").setTimestamp(DateFormatUtils.parseDateTime("2012-08-11T15:00:00.000Z"));
        data.add(quote24);
        journal.mergeAppend(data);
        journal.commit();
        // check that hard timestamp hasn't changed
        Assert.assertEquals(DateFormatUtils.parseDateTime("2012-08-11T10:00:00.000Z"), journal.getAppendTimestampLo());
        // check that soft timestamp has changed
        Assert.assertEquals(DateFormatUtils.parseDateTime("2012-08-11T15:00:00.000Z"), journal.getMaxTimestamp());
    }
    // reopen journal and check timestamps
    try (JournalWriter<Quote> journal = getFactory().writer(Quote.class)) {
        Assert.assertEquals(DateFormatUtils.parseDateTime("2012-08-11T10:00:00.000Z"), journal.getAppendTimestampLo());
        Assert.assertEquals(DateFormatUtils.parseDateTime("2012-08-11T15:00:00.000Z"), journal.getMaxTimestamp());
        // append timestamp that would make lag shift
        Quote quote25 = new Quote().setSym("555").setTimestamp(DateFormatUtils.parseDateTime("2012-08-12T16:00:00.000Z"));
        data.clear();
        data.add(quote25);
        journal.mergeAppend(data);
        Assert.assertEquals("2012-08-11T10:00:00.000Z", Dates.toString(journal.getAppendTimestampLo()));
        Assert.assertEquals("2012-08-12T16:00:00.000Z", Dates.toString(journal.getMaxTimestamp()));
        // create new empty partition
        journal.getAppendPartition(DateFormatUtils.parseDateTime("2013-08-12T16:00:00.000Z"));
        // check timestamps again
        Assert.assertEquals("2012-08-11T10:00:00.000Z", Dates.toString(journal.getAppendTimestampLo()));
        Assert.assertEquals("2012-08-12T16:00:00.000Z", Dates.toString(journal.getMaxTimestamp()));
    }
}
Also used : Quote(com.questdb.model.Quote) ArrayList(java.util.ArrayList) 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