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);
}
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);
}
}
}
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);
}
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);
}
}
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()));
}
}
Aggregations