use of de.invesdwin.context.persistence.leveldb.timeseries.ATimeSeriesDB in project invesdwin-context-persistence by subes.
the class DatabasePerformanceTest method testTimeSeriesDbPerformance.
@Test
public void testTimeSeriesDbPerformance() throws IncompleteUpdateFoundException {
final ATimeSeriesDB<String, FDate> table = new ATimeSeriesDB<String, FDate>("testTimeSeriesDbPerformance") {
@Override
protected Serde<FDate> newValueSerde() {
return FDateSerde.GET;
}
@Override
protected Integer newFixedLength() {
return FDateSerde.FIXED_LENGTH;
}
@Override
protected String hashKeyToString(final String key) {
return "testTimeSeriesDbPerformance_" + key;
}
@Override
protected FDate extractTime(final FDate value) {
return value;
}
};
final Instant writesStart = new Instant();
final ATimeSeriesUpdater<String, FDate> updater = new ATimeSeriesUpdater<String, FDate>(HASH_KEY, table) {
@Override
protected ICloseableIterable<FDate> getSource(final FDate updateFrom) {
return newValues();
}
@Override
protected void onUpdateFinished(final Instant updateStart) {
printProgress("WritesFinished", writesStart, VALUES, VALUES);
}
@Override
protected void onUpdateStart() {
}
@Override
protected FDate extractTime(final FDate element) {
return element;
}
@Override
protected FDate extractEndTime(final FDate element) {
return element;
}
@Override
protected void onFlush(final int flushIndex, final Instant flushStart, final ATimeSeriesUpdater<String, FDate>.UpdateProgress updateProgress) {
printProgress("Writes", writesStart, updateProgress.getCount() * flushIndex, VALUES);
}
};
Assertions.checkTrue(updater.update());
final Instant readsStart = new Instant();
for (int reads = 1; reads <= READS; reads++) {
FDate prevValue = null;
final ICloseableIterator<? extends FDate> range = table.rangeValues(HASH_KEY, null, null);
int count = 0;
while (true) {
try {
final FDate value = range.next();
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
} catch (final NoSuchElementException e) {
break;
}
}
Assertions.checkEquals(count, VALUES);
printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
}
printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Aggregations