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);
}
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);
}
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;
}
}
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);
}
}
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);
}
Aggregations