use of java.util.concurrent.TimeUnit in project elasticsearch by elastic.
the class TimeZoneRoundingTests method testIntervalRoundingRandom.
/**
* randomized test on {@link TimeIntervalRounding} with random interval and time zone offsets
*/
public void testIntervalRoundingRandom() {
for (int i = 0; i < 1000; i++) {
TimeUnit unit = randomFrom(new TimeUnit[] { TimeUnit.MINUTES, TimeUnit.HOURS, TimeUnit.DAYS });
long interval = unit.toMillis(randomIntBetween(1, 365));
DateTimeZone tz = randomDateTimeZone();
Rounding rounding = new Rounding.TimeIntervalRounding(interval, tz);
// 1970-01-01T00:00:00Z - 2033-05-18T05:33:20.000+02:00
long mainDate = Math.abs(randomLong() % (2 * (long) 10e11));
if (randomBoolean()) {
mainDate = nastyDate(mainDate, tz, interval);
}
// check two intervals around date
long previousRoundedValue = Long.MIN_VALUE;
for (long date = mainDate - 2 * interval; date < mainDate + 2 * interval; date += interval / 2) {
try {
final long roundedDate = rounding.round(date);
final long nextRoundingValue = rounding.nextRoundingValue(roundedDate);
assertThat("Rounding should be idempotent", roundedDate, equalTo(rounding.round(roundedDate)));
assertThat("Rounded value smaller or equal than unrounded", roundedDate, lessThanOrEqualTo(date));
assertThat("Values smaller than rounded value should round further down", rounding.round(roundedDate - 1), lessThan(roundedDate));
assertThat("Rounding should be >= previous rounding value", roundedDate, greaterThanOrEqualTo(previousRoundedValue));
if (tz.isFixed()) {
assertThat("NextRounding value should be greater than date", nextRoundingValue, greaterThan(roundedDate));
assertThat("NextRounding value should be interval from rounded value", nextRoundingValue - roundedDate, equalTo(interval));
assertThat("NextRounding value should be a rounded date", nextRoundingValue, equalTo(rounding.round(nextRoundingValue)));
}
previousRoundedValue = roundedDate;
} catch (AssertionError e) {
logger.error("Rounding error at {}, timezone {}, interval: {},", new DateTime(date, tz), tz, interval);
throw e;
}
}
}
}
use of java.util.concurrent.TimeUnit in project elasticsearch by elastic.
the class TimeValueTests method testCompareValue.
public void testCompareValue() {
long firstRandom = randomNonNegativeLong();
long secondRandom = randomValueOtherThan(firstRandom, ESTestCase::randomNonNegativeLong);
TimeUnit unit = randomFrom(TimeUnit.values());
TimeValue firstValue = new TimeValue(firstRandom, unit);
TimeValue secondValue = new TimeValue(secondRandom, unit);
assertEquals(firstRandom > secondRandom, firstValue.compareTo(secondValue) > 0);
assertEquals(secondRandom > firstRandom, secondValue.compareTo(firstValue) > 0);
}
use of java.util.concurrent.TimeUnit in project elasticsearch by elastic.
the class RecoverySettingsDynamicUpdateTests method testInternalLongActionTimeout.
public void testInternalLongActionTimeout() {
long duration = between(1, 1000);
TimeUnit timeUnit = randomFrom(TimeUnit.MILLISECONDS, TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS);
clusterSettings.applySettings(Settings.builder().put(RecoverySettings.INDICES_RECOVERY_INTERNAL_LONG_ACTION_TIMEOUT_SETTING.getKey(), duration, timeUnit).build());
assertEquals(new TimeValue(duration, timeUnit), recoverySettings.internalActionLongTimeout());
}
use of java.util.concurrent.TimeUnit in project elasticsearch by elastic.
the class RecoverySettingsDynamicUpdateTests method testRetryDelayNetwork.
public void testRetryDelayNetwork() {
long duration = between(1, 1000);
TimeUnit timeUnit = randomFrom(TimeUnit.MILLISECONDS, TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS);
clusterSettings.applySettings(Settings.builder().put(RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK_SETTING.getKey(), duration, timeUnit).build());
assertEquals(new TimeValue(duration, timeUnit), recoverySettings.retryDelayNetwork());
}
use of java.util.concurrent.TimeUnit in project elasticsearch by elastic.
the class WorkingBulkByScrollTaskTests method testDelayNeverNegative.
public void testDelayNeverNegative() throws IOException {
// Thread pool that returns a ScheduledFuture that claims to have a negative delay
ThreadPool threadPool = new TestThreadPool("test") {
public ScheduledFuture<?> schedule(TimeValue delay, String name, Runnable command) {
return new ScheduledFuture<Void>() {
@Override
public long getDelay(TimeUnit unit) {
return -1;
}
@Override
public int compareTo(Delayed o) {
throw new UnsupportedOperationException();
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
throw new UnsupportedOperationException();
}
@Override
public boolean isCancelled() {
throw new UnsupportedOperationException();
}
@Override
public boolean isDone() {
throw new UnsupportedOperationException();
}
@Override
public Void get() throws InterruptedException, ExecutionException {
throw new UnsupportedOperationException();
}
@Override
public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
throw new UnsupportedOperationException();
}
};
}
};
try {
// Have the task use the thread pool to delay a task that does nothing
task.delayPrepareBulkRequest(threadPool, timeValueSeconds(0), 1, new AbstractRunnable() {
@Override
protected void doRun() throws Exception {
}
@Override
public void onFailure(Exception e) {
throw new UnsupportedOperationException();
}
});
// Even though the future returns a negative delay we just return 0 because the time is up.
assertEquals(timeValueSeconds(0), task.getStatus().getThrottledUntil());
} finally {
threadPool.shutdown();
}
}
Aggregations