Search in sources :

Example 11 with TimeUnit

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;
            }
        }
    }
}
Also used : TimeIntervalRounding(org.elasticsearch.common.rounding.Rounding.TimeIntervalRounding) TimeUnit(java.util.concurrent.TimeUnit) TimeUnitRounding(org.elasticsearch.common.rounding.Rounding.TimeUnitRounding) TimeIntervalRounding(org.elasticsearch.common.rounding.Rounding.TimeIntervalRounding) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime)

Example 12 with TimeUnit

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);
}
Also used : ESTestCase(org.elasticsearch.test.ESTestCase) TimeUnit(java.util.concurrent.TimeUnit)

Example 13 with TimeUnit

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());
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 14 with TimeUnit

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());
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) TimeValue(org.elasticsearch.common.unit.TimeValue)

Example 15 with TimeUnit

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();
    }
}
Also used : AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) Delayed(java.util.concurrent.Delayed) AbstractRunnable(org.elasticsearch.common.util.concurrent.AbstractRunnable) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) TimeUnit(java.util.concurrent.TimeUnit) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) TimeValue(org.elasticsearch.common.unit.TimeValue) ScheduledFuture(java.util.concurrent.ScheduledFuture) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)190 Test (org.junit.Test)28 ExecutionException (java.util.concurrent.ExecutionException)16 IOException (java.io.IOException)11 TimeoutException (java.util.concurrent.TimeoutException)11 Future (java.util.concurrent.Future)10 HashMap (java.util.HashMap)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 ArrayList (java.util.ArrayList)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)5 File (java.io.File)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 WaitUntilGatewaySenderFlushedCoordinatorJUnitTest (org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)4 GwtIncompatible (com.google.common.annotations.GwtIncompatible)3 RestException (com.linkedin.r2.message.rest.RestException)3 Map (java.util.Map)3