return localFuture.get(min(currentDelay.plus(callTimeout).toMillis(), overallTimeoutsLeft), MILLISECONDS); } catch (ConfigException e) { throw e;
/** * Make sure, time / datestamp of <code>vmOpEvent</code> is at least as long later as the * pause duration of <code>previousEvent</code>. * * @param previousEvent event just before <code>vmOpEvent</code> * @param vmOpEvent event to be adjusted */ private void adjustTimeStamp(AbstractGCEvent<?> previousEvent, VmOperationEvent vmOpEvent) { if (previousEvent.getTimestamp() + previousEvent.getPause() > vmOpEvent.getTimestamp()) { vmOpEvent.setTimestamp(previousEvent.getTimestamp() + previousEvent.getPause()); if (previousEvent.getDatestamp() != null) { Duration adjustment = Duration.ofMinutes((long) Math.rint(previousEvent.getPause() / 60)) .plus((long) Math.rint(previousEvent.getPause()), ChronoUnit.SECONDS) .plus((long) Math.rint(previousEvent.getPause() * 1000), ChronoUnit.MILLIS); ZonedDateTime adjustedDatestamp = previousEvent.getDatestamp().plus(adjustment); vmOpEvent.setDateStamp(adjustedDatestamp); } } }
maxReadMsg = config.get(LOG_READ_BATCH_SIZE); readPollingInterval = config.get(LOG_READ_INTERVAL); readLagTime = config.get(LOG_READ_LAG_TIME).plus(maxSendDelay); maxReadTime = config.get(LOG_MAX_READ_TIME);
/** * Resets the heartbeat timer. */ private void resetHeartbeatTimeout() { raft.checkThread(); if (!isRunning()) { return; } // If a timer is already set, cancel the timer. if (heartbeatTimer != null) { heartbeatTimer.cancel(); } // Set the election timeout in a semi-random fashion with the random range // being election timeout and 2 * election timeout. Duration delay = raft.getElectionTimeout().plus(Duration.ofMillis(random.nextInt((int) raft.getElectionTimeout().toMillis()))); heartbeatTimer = raft.getThreadContext().schedule(delay, () -> { heartbeatTimer = null; if (isRunning() && (raft.getFirstCommitIndex() == 0 || raft.getState() == RaftContext.State.READY)) { raft.setLeader(null); log.debug("Heartbeat timed out in {}", delay); sendPollRequests(); } }); }
maxReadMsg = config.get(LOG_READ_BATCH_SIZE); readPollingInterval = config.get(LOG_READ_INTERVAL); readLagTime = config.get(LOG_READ_LAG_TIME).plus(maxSendDelay); maxReadTime = config.get(LOG_MAX_READ_TIME);
sleepAndConvertInterrupts(idApplicationWaitMS.plus(waitGracePeriod));
Duration duration = readTimeout.get().plus(Duration.ofSeconds(1)); finalFlowable = finalFlowable.timeout( duration.toMillis(),
sleepAndConvertInterrupts(idApplicationWaitMS.plus(waitGracePeriod));
ttlCheck.ttl(heartbeatConfiguration.getInterval().plus(Duration.ofSeconds(10))); check = ttlCheck; } else {
Duration delay = raft.getElectionTimeout().plus(Duration.ofMillis(random.nextInt((int) raft.getElectionTimeout().toMillis()))); currentTimer = raft.getThreadContext().schedule(delay, () -> { if (!complete.get()) {
private void testSlowRequestRateOnMultipleFailedAttemptsWhereAttemptIsValid( int maxFailedAttempts, Duration lockDuration ) { // Given FakeClock clock = getFakeClock(); AuthenticationStrategy authStrategy = newAuthStrategy( clock, maxFailedAttempts, lockDuration ); User user = new User.Builder( "user", LegacyCredential.forPassword( "right" ) ).build(); // When we've failed max number of times for ( int i = 0; i < maxFailedAttempts; i++ ) { assertThat( authStrategy.authenticate( user, password( "wrong" ) ), equalTo( AuthenticationResult.FAILURE ) ); } // Then assertThat( authStrategy.authenticate( user, password( "right" ) ), equalTo( AuthenticationResult.TOO_MANY_ATTEMPTS )); // But when time heals all wounds clock.forward( lockDuration.plus( 1, SECONDS ) ); // Then things should be alright assertThat( authStrategy.authenticate( user, password( "right" ) ), equalTo( AuthenticationResult.SUCCESS ) ); }
private void testSlowRequestRateOnMultipleFailedAttempts( int maxFailedAttempts, Duration lockDuration ) { // Given FakeClock clock = getFakeClock(); AuthenticationStrategy authStrategy = newAuthStrategy( clock, maxFailedAttempts, lockDuration ); User user = new User.Builder( "user", LegacyCredential.forPassword( "right" ) ).build(); // When we've failed max number of times for ( int i = 0; i < maxFailedAttempts; i++ ) { assertThat( authStrategy.authenticate( user, password( "wrong" ) ), equalTo( AuthenticationResult.FAILURE ) ); } // Then assertThat( authStrategy.authenticate( user, password( "wrong" ) ), equalTo( AuthenticationResult.TOO_MANY_ATTEMPTS ) ); // But when time heals all wounds clock.forward( lockDuration.plus( 1, SECONDS ) ); // Then things should be alright assertThat( authStrategy.authenticate( user, password( "wrong" ) ), equalTo( AuthenticationResult.FAILURE ) ); }
} else if (triggerInstance.getStatus() == Status.RUNNING) { final long remainingTime = remainingTimeBeforeTimeout(triggerInstance); addToRunningListAndScheduleKill(triggerInstance, Duration.ofMillis(remainingTime).plus (CANCELLING_GRACE_PERIOD_AFTER_RESTART), CancellationCause.TIMEOUT);
private void stop() { if (!running) { throw new IllegalStateException(String .format("Cannot stop <%s>, since it is not running", id)); } final Instant stop = Instant.now(); final Duration runTime = Duration.between(start, stop); totalDuration = totalDuration.plus(runTime); final TaskInfo lastTaskInfo = new TaskInfo(currentTaskName, runTime); tasks.add(lastTaskInfo); running = false; currentTaskName = null; start = null; }
private void stop() { if (!running) { throw new IllegalStateException(String .format("Cannot stop <%s>, since it is not running", id)); } final Instant stop = Instant.now(); final Duration runTime = Duration.between(start, stop); totalDuration = totalDuration.plus(runTime); final TaskInfo lastTaskInfo = new TaskInfo(currentTaskName, runTime); tasks.add(lastTaskInfo); running = false; currentTaskName = null; start = null; }
/** * Increase a query execution duration by a given value. */ public void addExecuteRequestDuration( final Duration duration ) { executeRequestDuration = (executeRequestDuration == null) ? duration : executeRequestDuration.plus(duration); }
@Test public void withCustomizedTimeOutTest() { assertThat(assertionMessage(DEFAULT_WAITING_TIMEOUT), getPerformanceDiff(getExpectedMillis(DEFAULT_WAITING_TIMEOUT), () -> stubElements.size()), lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS)); assertThat(assertionMessage(ofSeconds(5)), getPerformanceDiff(getExpectedMillis(ofSeconds(5)), () -> stubElements2.size()), lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS)); timeOutDuration.plus(ofSeconds(10)); assertThat(assertionMessage(timeOutDuration), getPerformanceDiff(getExpectedMillis(timeOutDuration), () -> stubElements.size()), lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS)); assertThat(assertionMessage(ofSeconds(5)), getPerformanceDiff(getExpectedMillis(ofSeconds(5)), () -> stubElements2.size()), lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS)); } }
/** * Returns a copy of this duration with the specified duration added. * <p> * This instance is immutable and unaffected by this method call. * * @param duration the duration to add, positive or negative, not null * @return a {@code Duration} based on this duration with the specified duration added, not null * @throws ArithmeticException if numeric overflow occurs */ public Duration plus(Duration duration) { return plus(duration.getSeconds(), duration.getNano()); }
private TemporalAmount plus(TemporalAmount first, TemporalAmount second) { if (first instanceof Period && second instanceof Period) { return ((Period) first).plus(second); } else if (first instanceof Duration && second instanceof Duration) { return ((Duration)first).plus((Duration)second); } else { throw new DMNRuntimeException(String.format("Cannot add '%s' and '%s'", first, second)); } }
@Test public void testTimeLimited() { Duration cumulativeLimit = Duration.ofMinutes(1); Backoff backoff = Backoff.builder().withCumulativeBackoffLimit(cumulativeLimit).build(); Duration totalSoFar = Duration.ZERO; while (backoff.hasNext()) { assertThat(totalSoFar, lessThan(cumulativeLimit)); totalSoFar = totalSoFar.plus(backoff.nextBackoff()); } assertThat(totalSoFar, greaterThanOrEqualTo(cumulativeLimit)); }