Search in sources :

Example 1 with ATimeSeriesUpdater

use of de.invesdwin.context.persistence.leveldb.timeseries.ATimeSeriesUpdater 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);
}
Also used : ATimeSeriesUpdater(de.invesdwin.context.persistence.leveldb.timeseries.ATimeSeriesUpdater) ATimeSeriesDB(de.invesdwin.context.persistence.leveldb.timeseries.ATimeSeriesDB) Instant(de.invesdwin.util.time.Instant) ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) FDate(de.invesdwin.util.time.fdate.FDate) NoSuchElementException(java.util.NoSuchElementException) ATest(de.invesdwin.context.test.ATest) Test(org.junit.Test)

Aggregations

ATimeSeriesDB (de.invesdwin.context.persistence.leveldb.timeseries.ATimeSeriesDB)1 ATimeSeriesUpdater (de.invesdwin.context.persistence.leveldb.timeseries.ATimeSeriesUpdater)1 ATest (de.invesdwin.context.test.ATest)1 ProcessedEventsRateString (de.invesdwin.util.lang.ProcessedEventsRateString)1 Instant (de.invesdwin.util.time.Instant)1 FDate (de.invesdwin.util.time.fdate.FDate)1 NoSuchElementException (java.util.NoSuchElementException)1 Test (org.junit.Test)1