use of com.questdb.model.Quote in project questdb by bluestreak01.
the class JournalRecoveryTest method testLagRecovery.
@Test
public void testLagRecovery() throws Exception {
try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, "origin")) {
TestUtils.generateQuoteData(origin, 100000, new Interval("2013-01-01T00:00:00.000Z", "2013-05-30T12:55:00.000Z"));
try (Journal<Quote> r = getFactory().reader(Quote.class, "origin")) {
Assert.assertEquals(100000, r.size());
}
long ts;
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
w.disableCommitOnClose();
w.append(origin.query().all().asResultSet().subset(0, 15000));
w.mergeAppend(origin.query().all().asResultSet().subset(15000, 17000));
w.commit();
ts = w.getMaxTimestamp();
w.mergeAppend(origin.query().all().asResultSet().subset(16000, 27000));
w.mergeAppend(origin.query().all().asResultSet().subset(23000, 37000));
Assert.assertTrue(ts < w.getMaxTimestamp());
Assert.assertEquals(37672, w.size());
}
// make sure journal is closed in pool
getFactory().lock(Quote.class.getName());
getFactory().unlock(Quote.class.getName());
try (Journal<Quote> w = getFactory().reader(Quote.class)) {
Assert.assertEquals(ts, w.getMaxTimestamp());
Assert.assertEquals(17000, w.size());
}
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
Assert.assertEquals(ts, w.getMaxTimestamp());
Assert.assertEquals(17000, w.size());
}
}
}
use of com.questdb.model.Quote in project questdb by bluestreak01.
the class JournalRecoveryTest method testRecovery.
@Test
public void testRecovery() throws Exception {
long ts;
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
w.disableCommitOnClose();
Assert.assertFalse(w.isCommitOnClose());
TestUtils.generateQuoteData(w, 10000, new Interval("2013-01-01T00:00:00.000Z", "2013-02-28T12:55:00.000Z"));
ts = w.getMaxTimestamp();
TestUtils.generateQuoteData(w, 10000, new Interval("2013-03-01T00:00:00.000Z", "2013-05-30T12:55:00.000Z"), false);
Assert.assertTrue(w.getMaxTimestamp() > ts);
}
// make sure journal is closed in pool
getFactory().lock(Quote.class.getName());
getFactory().unlock(Quote.class.getName());
try (Journal<Quote> w = getFactory().reader(Quote.class)) {
Assert.assertEquals(ts, w.getMaxTimestamp());
Assert.assertEquals(10000, w.size());
}
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
w.disableCommitOnClose();
Assert.assertEquals(ts, w.getMaxTimestamp());
Assert.assertEquals(10000, w.size());
}
}
use of com.questdb.model.Quote in project questdb by bluestreak01.
the class JournalRefreshTest method testReadConsistency.
@Test
public void testReadConsistency() throws JournalException {
Quote q1 = new Quote().setSym("ABC").setEx("LN");
Quote q2 = new Quote().setSym("EFG").setEx("SK");
rw.append(q1);
rw.close();
rw = getFactory().writer(Quote.class);
try (Journal<Quote> r = getFactory().reader(Quote.class)) {
for (Quote v : r) {
Assert.assertEquals(q1, v);
}
rw.append(q2);
for (Quote v : r) {
Assert.assertEquals(q1, v);
}
}
}
use of com.questdb.model.Quote in project questdb by bluestreak01.
the class JournalTest method testSingleWriterModel.
@Test
public void testSingleWriterModel() throws Exception {
try (JournalWriter<Quote> writer = getFactory().writer(Quote.class)) {
Assert.assertTrue(writer != null);
final CountDownLatch finished = new CountDownLatch(1);
final AtomicInteger errors = new AtomicInteger();
new Thread(() -> {
try {
getFactory().writer(Quote.class);
errors.incrementAndGet();
} catch (JournalException e) {
// ignore
}
finished.countDown();
}).start();
Assert.assertTrue(finished.await(1, TimeUnit.SECONDS));
Assert.assertEquals(0, errors.get());
// check if we can open a reader
try (Journal<Quote> r = getFactory().reader(Quote.class)) {
Assert.assertTrue(r != null);
}
// check if we can open writer in alt location
try (JournalWriter w = getFactory().writer(Quote.class, "test-Quote")) {
Assert.assertTrue(w != null);
}
}
}
use of com.questdb.model.Quote in project questdb by bluestreak01.
the class JournalTest method testOfflinePartition.
@Test
public void testOfflinePartition() throws Exception {
int SIZE = 50000;
File location;
final String name = "origin";
try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, name, SIZE)) {
TestUtils.generateQuoteData(origin, SIZE, DateFormatUtils.parseDateTime("2014-01-30T00:11:00.000Z"), 100000);
origin.commit();
location = new File(origin.getLocation(), "2014-03");
}
getFactory().lock(name);
try {
Files.deleteOrException(location);
} finally {
getFactory().unlock(name);
}
try (JournalWriter<Quote> origin = getFactory().writer(Quote.class, name)) {
Assert.assertEquals(25914, origin.size());
TestUtils.generateQuoteData(origin, 3000, DateFormatUtils.parseDateTime("2014-03-30T00:11:00.000Z"), 10000);
Assert.assertEquals(28914, origin.size());
origin.rollback();
Assert.assertEquals(25914, origin.size());
}
}
Aggregations