Search in sources :

Example 1 with Duration

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

the class ASpinWaitTest method testMaxWait.

// CHECKSTYLE:ON
@Test
public void testMaxWait() throws IOException {
    final ASpinWait waitingSpinWait = new ASpinWait() {

        @Override
        protected boolean isConditionFulfilled() {
            return false;
        }
    };
    final Duration maxWait = Duration.ONE_SECOND;
    final Instant waitingSince = new Instant();
    waitingSpinWait.awaitFulfill(waitingSince, maxWait);
    Assertions.assertThat(waitingSince.toDuration()).isGreaterThanOrEqualTo(maxWait);
}
Also used : Instant(de.invesdwin.util.time.Instant) Duration(de.invesdwin.util.time.duration.Duration) ATest(de.invesdwin.context.test.ATest) Test(org.junit.Test)

Example 2 with Duration

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

the class ChannelPerformanceTest method printProgress.

private void printProgress(final String action, final Instant start, final int count, final int maxCount) {
    final Duration duration = start.toDuration();
    log.info("%s: %s/%s (%s) %s during %s", action, count, maxCount, new Percent(count, maxCount).toString(PercentScale.PERCENT), new ProcessedEventsRateString(count, duration), duration);
}
Also used : ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) Percent(de.invesdwin.util.math.decimal.scaled.Percent) Duration(de.invesdwin.util.time.duration.Duration)

Example 3 with Duration

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

the class ConfiguredCPDataSource method createDelegate.

@Override
protected DataSource createDelegate() {
    final ComboPooledDataSource ds = new ComboPooledDataSource();
    try {
        ds.setDriverClass(context.getConnectionDriver());
    } catch (final PropertyVetoException e1) {
        throw Err.process(e1);
    }
    ds.setJdbcUrl(context.getConnectionUrl());
    ds.setUser(context.getConnectionUser());
    ds.setPassword(context.getConnectionPassword());
    ds.setMaxStatements(5000);
    ds.setMaxStatementsPerConnection(50);
    // fix apparent deadlocks
    ds.setStatementCacheNumDeferredCloseThreads(1);
    ds.setMaxPoolSize(100);
    ds.setMinPoolSize(1);
    ds.setMaxIdleTime(new Duration(1, FTimeUnit.MINUTES).intValue(FTimeUnit.SECONDS));
    ds.setTestConnectionOnCheckout(true);
    ds.setAutoCommitOnClose(true);
    Assertions.assertThat(this.closeableDs).isNull();
    this.closeableDs = ds;
    if (logging) {
        try {
            final ConnectionPoolDataSourceProxy proxy = new ConnectionPoolDataSourceProxy();
            proxy.setTargetDSDirect(ds);
            return proxy;
        } catch (final JdbcDsLogRuntimeException e) {
            throw new RuntimeException(e);
        }
    } else {
        return ds;
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) JdbcDsLogRuntimeException(org.jdbcdslog.JdbcDsLogRuntimeException) Duration(de.invesdwin.util.time.duration.Duration) ConnectionPoolDataSourceProxy(org.jdbcdslog.ConnectionPoolDataSourceProxy) JdbcDsLogRuntimeException(org.jdbcdslog.JdbcDsLogRuntimeException)

Example 4 with Duration

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

the class ALiveSegmentedTimeSeriesDBWithNoCacheTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    final AHistoricalCache<TimeRange> segmentFinder = PeriodicalSegmentFinder.newCache(new Duration(2, FTimeUnit.YEARS), false);
    table = new ALiveSegmentedTimeSeriesDB<String, FDate>(getClass().getSimpleName()) {

        private FDate curTime = null;

        @Override
        public AHistoricalCache<TimeRange> getSegmentFinder(final String key) {
            return segmentFinder;
        }

        @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 File getBaseDirectory() {
            return ContextProperties.TEMP_DIRECTORY;
        }

        @Override
        protected ICloseableIterable<? extends FDate> downloadSegmentElements(final SegmentedKey<String> segmentedKey) {
            return new ASkippingIterable<FDate>(WrapperCloseableIterable.maybeWrap(entities)) {

                private final FDate from = segmentedKey.getSegment().getFrom();

                private final FDate to = segmentedKey.getSegment().getTo();

                @Override
                protected boolean skip(final FDate element) {
                    return element.isBefore(from) || element.isAfter(to);
                }
            };
        }

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

        @Override
        public FDate getFirstAvailableHistoricalSegmentFrom(final String key) {
            if (entities.isEmpty() || curTime == null) {
                return null;
            }
            final FDate firstTime = FDates.min(curTime, entities.get(0));
            final TimeRange firstSegment = segmentFinder.query().getValue(firstTime);
            if (firstSegment.getTo().isBeforeOrEqualTo(curTime)) {
                return firstSegment.getFrom();
            } else {
                return segmentFinder.query().getValue(firstSegment.getFrom().addMilliseconds(-1)).getFrom();
            }
        }

        @Override
        public FDate getLastAvailableHistoricalSegmentTo(final String key, final FDate updateTo) {
            if (entities.isEmpty() || curTime == null) {
                return null;
            }
            final TimeRange lastSegment = segmentFinder.query().getValue(curTime);
            if (lastSegment.getTo().isBeforeOrEqualTo(curTime)) {
                return lastSegment.getTo();
            } else {
                return segmentFinder.query().getValue(lastSegment.getFrom().addMilliseconds(-1)).getTo();
            }
        }

        @Override
        public void putNextLiveValue(final String key, final FDate nextLiveValue) {
            curTime = nextLiveValue;
            super.putNextLiveValue(key, nextLiveValue);
        }

        @Override
        protected String getElementsName() {
            return "values";
        }
    };
    for (final FDate entity : entities) {
        table.putNextLiveValue(KEY, entity);
    }
}
Also used : ICloseableIterable(de.invesdwin.util.collections.iterable.ICloseableIterable) Duration(de.invesdwin.util.time.duration.Duration) ISerde(de.invesdwin.util.marshallers.serde.ISerde) AHistoricalCache(de.invesdwin.util.collections.loadingcache.historical.AHistoricalCache) FDate(de.invesdwin.util.time.date.FDate) TimeRange(de.invesdwin.util.time.range.TimeRange) File(java.io.File)

Example 5 with Duration

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

the class ADatabasePerformanceTest method printProgress.

protected void printProgress(final String action, final Instant start, final long count, final int maxCount) {
    final Duration duration = start.toDuration();
    log.info("%s: %s/%s (%s) %s during %s", action, count, maxCount, new Percent(count, maxCount).toString(PercentScale.PERCENT), new ProcessedEventsRateString(count, duration), duration);
}
Also used : ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) Percent(de.invesdwin.util.math.decimal.scaled.Percent) Duration(de.invesdwin.util.time.duration.Duration)

Aggregations

Duration (de.invesdwin.util.time.duration.Duration)34 ProcessedEventsRateString (de.invesdwin.util.lang.ProcessedEventsRateString)16 Percent (de.invesdwin.util.math.decimal.scaled.Percent)14 FDate (de.invesdwin.util.time.date.FDate)13 ICloseableIterable (de.invesdwin.util.collections.iterable.ICloseableIterable)12 AHistoricalCache (de.invesdwin.util.collections.loadingcache.historical.AHistoricalCache)12 ISerde (de.invesdwin.util.marshallers.serde.ISerde)12 TimeRange (de.invesdwin.util.time.range.TimeRange)12 File (java.io.File)12 Instant (de.invesdwin.util.time.Instant)4 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)2 ATest (de.invesdwin.context.test.ATest)2 IEvaluateGenericFDate (de.invesdwin.util.math.expression.lambda.IEvaluateGenericFDate)2 IFDateProvider (de.invesdwin.util.time.date.IFDateProvider)2 PropertyVetoException (java.beans.PropertyVetoException)2 ExecutorService (java.util.concurrent.ExecutorService)2 Test (org.junit.Test)2 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 IncompleteUpdateFoundException (de.invesdwin.context.persistence.timeseriesdb.IncompleteUpdateFoundException)1