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