use of com.questdb.std.ObjList in project questdb by bluestreak01.
the class IteratorTest method testMergePeeking.
@Test
public void testMergePeeking() throws Exception {
populateQuotes();
ObjList<Journal<Quote>> journals = new ObjList<Journal<Quote>>() {
{
add(getFactory().reader(Quote.class, "quote-0"));
add(getFactory().reader(Quote.class, "quote-1"));
add(getFactory().reader(Quote.class, "quote-2"));
add(getFactory().reader(Quote.class, "quote-3"));
add(getFactory().reader(Quote.class, "quote-4"));
}
};
try {
List<JournalPeekingIterator<Quote>> list = new ArrayList<>();
for (int i = 0; i < journals.size(); i++) {
list.add(JournalIterators.bufferedIterator(journals.get(i)));
}
long ts = 0;
for (Quote q : MergingPeekingIterator.mergePeek(list, comparator)) {
Assert.assertTrue(ts <= q.getTimestamp());
ts = q.getTimestamp();
}
} finally {
for (int i = 0, n = journals.size(); i < n; i++) {
journals.getQuick(i).close();
}
}
}
use of com.questdb.std.ObjList in project questdb by bluestreak01.
the class SymbolMapTest method testLookupPerformance.
// @Test
// public void testLookupPerformanceOld() throws JournalException {
// int N = 100000000;
// int symbolCount = 1024;
// ObjList<String> symbols = new ObjList<>();
// MMappedSymbolTable tab = new MMappedSymbolTable(symbolCount, 256, 1, new File(configuration.getRoot().toString()), "x", JournalMode.APPEND, 0, 0, false, true);
// Rnd rnd = new Rnd();
// long prev = -1L;
// for (int i = 0; i < symbolCount; i++) {
// CharSequence cs = rnd.nextChars(10);
// long key = tab.put(cs);
// symbols.add(cs.toString());
// Assert.assertEquals(prev + 1, key);
// prev = key;
// }
//
// long t = System.nanoTime();
// for (int i = 0; i < N; i++) {
// int key = rnd.nextPositiveInt() % symbolCount;
// Assert.assertEquals(key, tab.put(symbols.getQuick(key)));
// }
// System.out.println(System.nanoTime() - t);
// }
@Test
public void testLookupPerformance() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 10000000;
int symbolCount = 1024;
ObjList<String> symbols = new ObjList<>();
try (Path path = new Path().of(configuration.getRoot())) {
create(path, "x", symbolCount, true);
try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0)) {
Rnd rnd = new Rnd();
long prev = -1L;
for (int i = 0; i < symbolCount; i++) {
CharSequence cs = rnd.nextChars(10);
long key = writer.put(cs);
symbols.add(cs.toString());
Assert.assertEquals(prev + 1, key);
prev = key;
}
long t = System.nanoTime();
for (int i = 0; i < N; i++) {
int key = rnd.nextPositiveInt() % symbolCount;
Assert.assertEquals(key, writer.put(symbols.getQuick(key)));
}
System.out.println("SymbolMapWriter lookup performance [10M <500ms]: " + (System.nanoTime() - t) / 1000000);
}
}
});
}
use of com.questdb.std.ObjList in project questdb by bluestreak01.
the class ObjListTest method testAdd.
@Test
public void testAdd() {
Rnd rnd = new Rnd();
ObjList<String> list = new ObjList<>();
for (int i = 0; i < 100; i++) {
list.add(rnd.nextString(10));
}
Assert.assertEquals(100, list.size());
rnd.reset();
for (int i = 0; i < list.size(); i++) {
Assert.assertEquals(rnd.nextString(10), list.getQuick(i));
}
}
use of com.questdb.std.ObjList in project questdb by bluestreak01.
the class CachingReaderFactoryTest method testGetReadersBeforeFailure.
@SuppressWarnings("InfiniteLoopStatement")
@Test
public void testGetReadersBeforeFailure() throws Exception {
// create journal
final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
((WriterFactory) getFactory()).writer(m).close();
try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
ObjList<Journal> readers = new ObjList<>();
try {
do {
readers.add(rf.reader(m));
} while (true);
} catch (FactoryFullException e) {
Assert.assertEquals(rf.getMaxEntries(), readers.size());
} finally {
for (int i = 0, n = readers.size(); i < n; i++) {
readers.getQuick(i).close();
}
}
}
}
use of com.questdb.std.ObjList in project questdb by bluestreak01.
the class SymbolNullQueryTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
int tradeCount = 100;
int quoteCount = 300;
JournalWriter trades = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("trades").$int("quoteId").$sym("tag1").$double("amount").recordCountHint(tradeCount).$ts());
JournalWriter quotes = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("quotes").$int("quoteId").$sym("tag").$double("rate").recordCountHint(quoteCount).$ts());
int tsIncrementMax = 10000;
long timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z");
Rnd rnd = new Rnd();
ObjList<String> tags = new ObjList<>();
for (int i = 0; i < 500; i++) {
tags.add(rnd.nextBoolean() ? rnd.nextString(rnd.nextInt() & 15) : null);
}
for (int i = 0; i < quoteCount; i++) {
JournalEntryWriter w = quotes.entryWriter();
w.putInt(0, i);
w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size()));
w.putDouble(2, rnd.nextDouble());
w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax);
w.append();
}
quotes.commit();
timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z");
for (int i = 0; i < tradeCount; i++) {
JournalEntryWriter w = trades.entryWriter();
w.putInt(0, rnd.nextPositiveInt() % quoteCount);
w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size()));
w.putDouble(2, rnd.nextDouble());
w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax);
w.append();
}
quotes.close();
trades.close();
}
Aggregations