Search in sources :

Example 31 with Instant

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

the class CqenginePerformanceTest method readIterator.

private void readIterator(final IndexedCollection<Content> table) throws InterruptedException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        final Iterator<Content> iterator = table.iterator();
        try {
            while (true) {
                final FDate value = iterator.next().getValue();
                // if (prevValue != null) {
                // Assertions.checkTrue(prevValue.isBefore(value));
                // }
                prevValue = value;
                count++;
            }
        } catch (final NoSuchElementException e) {
        // end reached
        }
        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 32 with Instant

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

the class CqenginePerformanceTest method readOrdered.

private void readOrdered(final IndexedCollection<Content> table) throws InterruptedException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant readsStart = new Instant();
    for (int reads = 1; reads <= READS; reads++) {
        FDate prevValue = null;
        int count = 0;
        try (ResultSet<Content> result = table.retrieve(QueryFactory.all(Content.class), QueryFactory.queryOptions(QueryFactory.orderBy(QueryFactory.ascending(Content.KEY))))) {
            final Iterator<Content> iterator = result.iterator();
            try {
                while (true) {
                    final FDate value = iterator.next().getValue();
                    if (prevValue != null) {
                        Assertions.checkTrue(prevValue.isBefore(value));
                    }
                    prevValue = value;
                    count++;
                }
            } catch (final NoSuchElementException e) {
            // end reached
            }
        }
        Assertions.checkEquals(count, VALUES);
        if (loopCheck.check()) {
            printProgress("ReadsOrdered", readsStart, VALUES * reads, VALUES * READS);
        }
    }
    printProgress("ReadsOrderedFinished", 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 33 with Instant

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

the class ChronicleMapPerformanceTest method readGet.

private void readGet(final ChronicleMap<Long, Long> 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 = new FDate(table.get(values.get(i).millisValue()));
                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 34 with Instant

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

the class ChronicleMapPerformanceTest method testChronicleMapPerformance.

@Test
public void testChronicleMapPerformance() throws IOException, InterruptedException {
    final File directory = new File(ContextProperties.getCacheDirectory(), ChronicleMapPerformanceTest.class.getSimpleName());
    Files.deleteNative(directory);
    Files.forceMkdir(directory);
    final Instant writesStart = new Instant();
    final ChronicleMapBuilder<Long, Long> mapBuilder = ChronicleMapBuilder.of(Long.class, Long.class).name("testChronicleMapPerformance").constantKeySizeBySample(FDate.MAX_DATE.millisValue()).constantValueSizeBySample(FDate.MAX_DATE.millisValue()).entries(VALUES);
    // final ChronicleMap<Long, Long> map = mapBuilder.create();
    final ChronicleMap<Long, Long> map = mapBuilder.createPersistedTo(new File(directory, "testChronicleMapPerformance"));
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    int i = 0;
    for (final FDate date : newValues()) {
        map.put(date.millisValue(), date.millisValue());
        i++;
        if (i % FLUSH_INTERVAL == 0) {
            if (loopCheck.check()) {
                printProgress("Writes", writesStart, i, VALUES);
            }
        }
    }
    printProgress("WritesFinished", writesStart, VALUES, VALUES);
    readIterator(map);
    readGet(map);
}
Also used : Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) File(java.io.File) FDate(de.invesdwin.util.time.date.FDate) Test(org.junit.jupiter.api.Test)

Example 35 with Instant

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

the class ATimeSeriesDBTest method testGetPreviousAndNext.

// CHECKSTYLE:ON
@Test
public void testGetPreviousAndNext() throws IncompleteUpdateFoundException {
    final String key = "asdf";
    final ATimeSeriesDB<String, FDate> table = new ATimeSeriesDB<String, FDate>("testGetPrevious") {

        @Override
        protected ISerde<FDate> newValueSerde() {
            return new TypeDelegateSerde<FDate>(FDate.class);
        }

        @Override
        protected Integer newValueFixedLength() {
            return null;
        }

        @Override
        protected String innerHashKeyToString(final String key) {
            return key;
        }

        @Override
        protected FDate extractEndTime(final FDate value) {
            return value;
        }

        @Override
        protected File getBaseDirectory() {
            return ContextProperties.TEMP_DIRECTORY;
        }
    };
    final List<FDate> dates = new ArrayList<>();
    for (int i = 2000; i <= 2010; i++) {
        dates.add(FDateBuilder.newDate(i));
    }
    new ATimeSeriesUpdater<String, FDate>(key, table) {

        @Override
        protected ICloseableIterable<? extends FDate> getSource(final FDate updateFrom) {
            return WrapperCloseableIterable.maybeWrap(dates);
        }

        @Override
        protected void onUpdateFinished(final Instant updateStart) {
        }

        @Override
        protected void onUpdateStart() {
        }

        @Override
        protected FDate extractEndTime(final FDate element) {
            return element;
        }

        @Override
        protected void onFlush(final int flushIndex, final ATimeSeriesUpdater<String, FDate>.UpdateProgress updateProgress) {
        }

        @Override
        public Percent getProgress() {
            return null;
        }
    }.update();
    for (int i = 1; i < dates.size(); i++) {
        final FDate value = table.getPreviousValue(key, dates.get(dates.size() - 1), i);
        final FDate expectedValue = dates.get(dates.size() - i - 1);
        Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
    }
    for (int i = 1; i < dates.size(); i++) {
        final FDate value = table.getPreviousValue(key, FDate.MAX_DATE, i);
        final FDate expectedValue = dates.get(dates.size() - i - 1);
        Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
    }
    for (int i = 1; i < dates.size(); i++) {
        final FDate value = table.getPreviousValue(key, FDate.MIN_DATE, i);
        final FDate expectedValue = dates.get(0);
        Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
    }
    for (int i = 1; i < dates.size(); i++) {
        final FDate value = table.getNextValue(key, dates.get(0), i);
        final FDate expectedValue = dates.get(i);
        Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
    }
    for (int i = 1; i < dates.size(); i++) {
        final FDate value = table.getNextValue(key, FDate.MIN_DATE, i);
        final FDate expectedValue = dates.get(i);
        Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
    }
    for (int i = 1; i < dates.size(); i++) {
        final FDate value = table.getNextValue(key, FDate.MAX_DATE, i);
        final FDate expectedValue = dates.get(dates.size() - 1);
        Assertions.checkEquals(value, expectedValue, i + ": expected [" + expectedValue + "] got [" + value + "]");
    }
}
Also used : Percent(de.invesdwin.util.math.decimal.scaled.Percent) ICloseableIterable(de.invesdwin.util.collections.iterable.ICloseableIterable) Instant(de.invesdwin.util.time.Instant) ArrayList(java.util.ArrayList) TypeDelegateSerde(de.invesdwin.util.marshallers.serde.TypeDelegateSerde) FDate(de.invesdwin.util.time.date.FDate) ATimeSeriesUpdater(de.invesdwin.context.persistence.timeseriesdb.updater.ATimeSeriesUpdater) ATest(de.invesdwin.context.test.ATest) Test(org.junit.jupiter.api.Test)

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