Search in sources :

Example 16 with Instant

use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.

the class TestStockData method assertIteration.

private void assertIteration(final int countFDates, final FDate fromFDate, final FDate toFDate) {
    TableIterator<RangeTableRow<String, FDate, Integer>> range = table.range(MSFT, fromFDate, toFDate);
    int iteratedBars = 0;
    int prevValue = 0;
    FDate left1000FDate = null;
    FDate left900FDate = null;
    final Instant start = new Instant();
    while (range.hasNext()) {
        final RangeTableRow<String, FDate, Integer> next = range.next();
        final Integer value = next.getValue();
        // System.out.println(value);
        iteratedBars++;
        Assertions.checkTrue(prevValue < value);
        prevValue = value;
        if (iteratedBars == countFDates - 999) {
            left1000FDate = next.getRangeKey();
        }
        if (iteratedBars == countFDates - 900) {
            left900FDate = next.getRangeKey();
        }
    }
    System.out.println("took: " + start);
    Assertions.checkEquals(countFDates, iteratedBars);
    Assertions.checkEquals(1, table.getLatest(MSFT, fromFDate).getValue());
    Assertions.checkEquals(countFDates, table.getLatest(MSFT, toFDate).getValue());
    // System.out.println(left1000FDate +" -> "+left900FDate);
    range = table.range(MSFT, left1000FDate, left900FDate);
    int curLeftIt = 0;
    RangeTableRow<String, FDate, Integer> prev = null;
    while (range.hasNext()) {
        final RangeTableRow<String, FDate, Integer> next = range.next();
        curLeftIt++;
        Assertions.checkEquals(countFDates - 1000 + curLeftIt, next.getValue());
        if (prev != null) {
            final Integer nextFromPrevPlus = table.getNext(MSFT, new FDate(prev.getRangeKey().millisValue() + 1)).getValue();
            Assertions.checkEquals(next.getValue(), nextFromPrevPlus);
            final Integer prevFromNextMinus = table.getPrev(MSFT, new FDate(next.getRangeKey().millisValue() - 1)).getValue();
            Assertions.checkEquals(prev.getValue(), prevFromNextMinus);
        }
        final Integer nextFromNextIsSame = table.getNext(MSFT, new FDate(next.getRangeKey().millisValue())).getValue();
        Assertions.checkEquals(next.getValue(), nextFromNextIsSame);
        final Integer prevFromNextIsSame = table.getPrev(MSFT, new FDate(next.getRangeKey().millisValue())).getValue();
        Assertions.checkEquals(next.getValue(), prevFromNextIsSame);
        prev = next;
    }
    Assertions.checkEquals(100, curLeftIt);
}
Also used : Instant(de.invesdwin.util.time.Instant) RangeTableRow(ezdb.table.RangeTableRow) FDate(de.invesdwin.util.time.date.FDate)

Example 17 with Instant

use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.

the class PersistentEzdbPerformanceTest method readGet.

private void readGet(final APersistentMap<FDate, FDate> table) throws InterruptedException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final List<FDate> values = Lists.toList(newValues());
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        for (int i = 0; i < values.size(); i++) {
            try {
                final FDate value = table.get(values.get(i));
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
            } catch (final NoSuchElementException e) {
                break;
            }
        }
        if (loopCheck.check()) {
            printProgress("Gets", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("GetsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) NoSuchElementException(java.util.NoSuchElementException)

Example 18 with Instant

use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.

the class BasicRecordFilePerformanceTest method readIterator.

private void readIterator(final File file) throws IOException, InterruptedException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck();
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        try (BasicRecordFile<TimedDecimal> reader = new BasicRecordFile<>(file, IndeedSerializer.valueOf(TimedDecimalSerde.GET))) {
            final RecordFile.Reader<TimedDecimal> iterator = reader.reader();
            while (iterator.next()) {
                final FDate value = iterator.get().getTime();
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
                count++;
            }
            Assertions.checkEquals(count, VALUES);
            if (loopCheck.check()) {
                printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
            }
        }
    }
    printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : BasicRecordFile(com.indeed.lsmtree.recordlog.BasicRecordFile) RecordFile(com.indeed.lsmtree.recordlog.RecordFile) BasicRecordFile(com.indeed.lsmtree.recordlog.BasicRecordFile) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) TimedDecimal(de.invesdwin.util.math.decimal.TimedDecimal) FDate(de.invesdwin.util.time.date.FDate)

Example 19 with Instant

use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.

the class LsmTreePerformanceTest method readIterator.

private void readIterator(final Store<FDate, FDate> table) throws InterruptedException, IOException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        final Iterator<Store.Entry<FDate, FDate>> range = table.iterator();
        int count = 0;
        while (true) {
            try {
                final FDate value = range.next().getValue();
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
                count++;
            } catch (final NoSuchElementException e) {
                break;
            }
        }
        Assertions.checkEquals(count, VALUES);
        if (loopCheck.check()) {
            printProgress("Reads", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("ReadsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) NoSuchElementException(java.util.NoSuchElementException)

Example 20 with Instant

use of de.invesdwin.util.time.Instant in project invesdwin-context-persistence by subes.

the class LsmTreePerformanceTest method readGetLatest.

private void readGetLatest(final Store<FDate, FDate> table) throws InterruptedException, IOException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final List<FDate> values = Lists.toList(newValues());
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        for (int i = 0; i < values.size(); i++) {
            try {
                final Store.Entry<FDate, FDate> entry = table.floor(values.get(i));
                final FDate value = entry.getValue();
                if (prevValue != null) {
                    Assertions.checkTrue(prevValue.isBefore(value));
                }
                prevValue = value;
            } catch (final NoSuchElementException e) {
                break;
            }
        }
        if (loopCheck.check()) {
            printProgress("GetLatests", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("GetLatestsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : Instant(de.invesdwin.util.time.Instant) Store(com.indeed.lsmtree.core.Store) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Instant (de.invesdwin.util.time.Instant)93 FDate (de.invesdwin.util.time.date.FDate)78 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)65 NoSuchElementException (java.util.NoSuchElementException)30 Test (org.junit.jupiter.api.Test)25 File (java.io.File)16 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)15 Statement (java.sql.Statement)12 ATest (de.invesdwin.context.test.ATest)8 RecordFile (com.indeed.lsmtree.recordlog.RecordFile)6 ProcessedEventsRateString (de.invesdwin.util.lang.ProcessedEventsRateString)6 TimedDecimal (de.invesdwin.util.math.decimal.TimedDecimal)5 FDate (de.invesdwin.util.time.fdate.FDate)5 IOException (java.io.IOException)5 Connection (java.sql.Connection)5 APersistentMap (de.invesdwin.context.integration.persistentmap.APersistentMap)4 ATimeSeriesUpdater (de.invesdwin.context.persistence.timeseriesdb.updater.ATimeSeriesUpdater)4 Test (org.junit.Test)4 SnappyCodec (com.indeed.util.compress.SnappyCodec)3