use of com.questdb.store.factory.Factory in project questdb by bluestreak01.
the class PerformanceTest method testAllBySymbolValueOverIntervalNew.
@SuppressWarnings("StatementWithEmptyBody")
@Test
public void testAllBySymbolValueOverIntervalNew() throws JournalException, ParserException, NumericException {
try (JournalWriter<Quote> w = getFactory().writer(Quote.class, "quote", TEST_DATA_SIZE)) {
TestUtils.generateQuoteData(w, TEST_DATA_SIZE, DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"), 1000);
w.commit();
}
QueryCompiler compiler = new QueryCompiler();
Factory factory = getFactory();
try (RecordSource src = compiler.compile(factory, "quote where timestamp = '2013-10-05T10:00:00.000Z;10d' and sym = 'LLOY.L'")) {
int count = 1000;
long t = 0;
for (int i = -count; i < count; i++) {
if (i == 0) {
t = System.nanoTime();
}
RecordCursor c = src.prepareCursor(factory);
try {
for (; c.hasNext(); ) {
c.next();
}
} finally {
c.releaseCursor();
}
}
LOG.info().$("NEW journal.query().all().withKeys(\"LLOY.L\").slice(interval) (query only) latency: ").$((System.nanoTime() - t) / count / 1000).$("μs").$();
}
}
use of com.questdb.store.factory.Factory in project questdb by bluestreak01.
the class RenameJournalTest method testReleaseOfJournalInPool.
@Test
public void testReleaseOfJournalInPool() throws Exception {
createX();
Factory f = getFactory();
assertJournal(f, "x");
sink.clear();
compiler.execute(f, "rename table x to y");
assertJournal(f, "y");
sink.clear();
createX();
assertJournal(f, "x");
}
use of com.questdb.store.factory.Factory in project questdb by bluestreak01.
the class RenameJournalTest method testJournalAlreadyOpenButIdle.
@Test
@SuppressWarnings("unchecked")
public void testJournalAlreadyOpenButIdle() throws Exception {
createX();
Factory factory = getFactory();
assertJournal(factory, "x");
sink.clear();
compiler.execute(factory, "rename table x to y");
assertJournal(factory, "y");
// make sure caching readerFactory doesn't return old journal
try {
factory.reader(new JournalKey("x"));
Assert.fail();
} catch (JournalException e) {
Assert.assertEquals("Journal does not exist", e.getMessage());
}
// make sure compile doesn't pick up old journal
try {
compiler.compile(factory, "x");
Assert.fail("still exists");
} catch (ParserException e) {
Assert.assertEquals(0, QueryError.getPosition());
TestUtils.assertEquals("Journal does not exist", QueryError.getMessage());
}
sink.clear();
createX();
assertJournal(factory, "x");
}
use of com.questdb.store.factory.Factory 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
}
}
use of com.questdb.store.factory.Factory in project questdb by bluestreak01.
the class AppendObjectPartitioned method main.
/**
* Appends 1 million quotes into journal partitioned by day. Journal can only be partitioned on values of timestamp column.
*
* @param args factory directory
* @throws JournalException in case of any problems with the journal.
*/
public static void main(String[] args) throws JournalException {
if (args.length != 1) {
System.out.println("Usage: " + AppendObjectPartitioned.class.getName() + " <path>");
System.exit(1);
}
String journalLocation = args[0];
try (Factory factory = new Factory(new JournalConfigurationBuilder() {
{
$(Quote.class, "quote-by-day").partitionBy(PartitionBy.DAY).$ts();
}
}.build(journalLocation), 1000, 1, 0)) {
Files.delete(new File(factory.getConfiguration().getJournalBase(), "quote-by-day"));
// you can change it in runtime and also, optionally put journal in alternative location
try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
final int count = 1000000;
final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
final Rnd r = new Rnd();
// reuse same same instance of Quote class to keep GC under control
final Quote q = new Quote();
long t = System.nanoTime();
for (int i = 0; i < count; i++) {
// prepare object for new set of data
q.clear();
// generate some data
q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
q.setAsk(Math.abs(r.nextDouble()));
q.setBid(Math.abs(r.nextDouble()));
q.setAskSize(Math.abs(r.nextInt() % 10000));
q.setBidSize(Math.abs(r.nextInt() % 10000));
q.setEx("LXE");
q.setMode("Fast trading");
q.setTimestamp(System.currentTimeMillis() + (i * 100));
writer.append(q);
}
// commit is necessary
writer.commit();
System.out.println("Journal size: " + writer.size());
System.out.println("Generated " + count + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
}
}
}
Aggregations