Search in sources :

Example 1 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 2 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 3 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)

Example 4 with TimeUnit

use of java.util.concurrent.TimeUnit in project hive by apache.

the class HouseKeeperServiceBase method start.

@Override
public void start(HiveConf hiveConf) throws Exception {
    this.hiveConf = hiveConf;
    HiveTxnManager mgr = TxnManagerFactory.getTxnManagerFactory().getTxnManager(hiveConf);
    if (!mgr.supportsAcid()) {
        LOG.info(this.getClass().getName() + " not started since " + mgr.getClass().getName() + " does not support Acid.");
        //there are no transactions in this case
        return;
    }
    pool = Executors.newScheduledThreadPool(1, new ThreadFactory() {

        private final AtomicInteger threadCounter = new AtomicInteger();

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, HouseKeeperServiceBase.this.getClass().getName() + "-" + threadCounter.getAndIncrement());
        }
    });
    TimeUnit tu = TimeUnit.MILLISECONDS;
    pool.scheduleAtFixedRate(getScheduedAction(hiveConf, isAliveCounter), getStartDelayMs(), getIntervalMs(), tu);
    LOG.info("Started " + this.getClass().getName() + " with delay/interval = " + getStartDelayMs() + "/" + getIntervalMs() + " " + tu);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HiveTxnManager(org.apache.hadoop.hive.ql.lockmgr.HiveTxnManager) TimeUnit(java.util.concurrent.TimeUnit)

Example 5 with TimeUnit

use of java.util.concurrent.TimeUnit in project buck by facebook.

the class NetworkStatsKeeper method scheduleDownloadSpeedCalculation.

private void scheduleDownloadSpeedCalculation() {
    long calculationInterval = DOWNLOAD_SPEED_CALCULATION_INTERVAL.toMillis();
    TimeUnit timeUnit = TimeUnit.MILLISECONDS;
    @SuppressWarnings("unused") ScheduledFuture<?> unused = scheduler.scheduleAtFixedRate(this::calculateDownloadSpeedInLastInterval, /* initialDelay */
    calculationInterval, /* period */
    calculationInterval, timeUnit);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)474 Test (org.junit.jupiter.api.Test)71 Test (org.junit.Test)69 Timeout (io.vertx.junit5.Timeout)56 VertxTestContext (io.vertx.junit5.VertxTestContext)56 Truth.assertThat (com.google.common.truth.Truth.assertThat)54 Map (java.util.Map)47 IntegrationTestSupport (org.eclipse.hono.tests.IntegrationTestSupport)46 List (java.util.List)45 Future (io.vertx.core.Future)44 HttpURLConnection (java.net.HttpURLConnection)42 Handler (io.vertx.core.Handler)38 Promise (io.vertx.core.Promise)38 BeforeEach (org.junit.jupiter.api.BeforeEach)38 Buffer (io.vertx.core.buffer.Buffer)37 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)36 CountDownLatch (java.util.concurrent.CountDownLatch)35 JsonObject (io.vertx.core.json.JsonObject)34 Stream (java.util.stream.Stream)34 Collections (java.util.Collections)33