Search in sources :

Example 76 with TimeUnit

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

the class WaitUntilParallelGatewaySenderFlushedCoordinatorJUnitTest method testWaitUntilParallelGatewaySenderFlushedUnsuccessfulInitiator.

@Test
public void testWaitUntilParallelGatewaySenderFlushedUnsuccessfulInitiator() throws Throwable {
    long timeout = 5000;
    TimeUnit unit = TimeUnit.MILLISECONDS;
    WaitUntilParallelGatewaySenderFlushedCoordinator coordinator = new WaitUntilParallelGatewaySenderFlushedCoordinator(this.sender, timeout, unit, true);
    WaitUntilParallelGatewaySenderFlushedCoordinator coordinatorSpy = spy(coordinator);
    doReturn(getLocalBucketRegions()).when(coordinatorSpy).getLocalBucketRegions(any());
    doReturn(getCallableResult(false)).when(coordinatorSpy).createWaitUntilBucketRegionQueueFlushedCallable(any(), anyLong(), any());
    boolean result = coordinatorSpy.waitUntilFlushed();
    assertFalse(result);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test) WaitUntilGatewaySenderFlushedCoordinatorJUnitTest(org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 77 with TimeUnit

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

the class SerializableTimeoutTest method canBeSerialized.

@Test
public void canBeSerialized() throws Exception {
    long timeout = 2;
    TimeUnit timeUnit = TimeUnit.SECONDS;
    boolean lookingForStuckThread = true;
    SerializableTimeout instance = SerializableTimeout.builder().withTimeout(timeout, timeUnit).withLookingForStuckThread(lookingForStuckThread).build();
    assertThat(readField(Timeout.class, instance, FIELD_TIMEOUT)).isEqualTo(timeout);
    assertThat(readField(Timeout.class, instance, FIELD_TIME_UNIT)).isEqualTo(timeUnit);
    assertThat(readField(Timeout.class, instance, FIELD_LOOK_FOR_STUCK_THREAD)).isEqualTo(lookingForStuckThread);
    SerializableTimeout cloned = (SerializableTimeout) SerializationUtils.clone(instance);
    assertThat(readField(Timeout.class, cloned, FIELD_TIMEOUT)).isEqualTo(timeout);
    assertThat(readField(Timeout.class, cloned, FIELD_TIME_UNIT)).isEqualTo(timeUnit);
    assertThat(readField(Timeout.class, cloned, FIELD_LOOK_FOR_STUCK_THREAD)).isEqualTo(lookingForStuckThread);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 78 with TimeUnit

use of java.util.concurrent.TimeUnit in project logging-log4j2 by apache.

the class IdlePurgePolicy method createPurgePolicy.

/**
     * Create the PurgePolicy
     *
     * @param timeToLive    the number of increments of timeUnit before the Appender should be purged.
     * @param checkInterval when all appenders purged, the number of increments of timeUnit to check if any appenders appeared  
     * @param timeUnit      the unit of time the timeToLive and the checkInterval is expressed in.
     * @return The Routes container.
     */
@PluginFactory
public static PurgePolicy createPurgePolicy(@PluginAttribute("timeToLive") final String timeToLive, @PluginAttribute("checkInterval") final String checkInterval, @PluginAttribute("timeUnit") final String timeUnit, @PluginConfiguration final Configuration configuration) {
    if (timeToLive == null) {
        LOGGER.error("A timeToLive value is required");
        return null;
    }
    TimeUnit units;
    if (timeUnit == null) {
        units = TimeUnit.MINUTES;
    } else {
        try {
            units = TimeUnit.valueOf(timeUnit.toUpperCase());
        } catch (final Exception ex) {
            LOGGER.error("Invalid timeUnit value {}. timeUnit set to MINUTES", timeUnit, ex);
            units = TimeUnit.MINUTES;
        }
    }
    long ttl = units.toMillis(Long.parseLong(timeToLive));
    if (ttl < 0) {
        LOGGER.error("timeToLive must be positive. timeToLive set to 0");
        ttl = 0;
    }
    long ci;
    if (checkInterval == null) {
        ci = ttl;
    } else {
        ci = units.toMillis(Long.parseLong(checkInterval));
        if (ci < 0) {
            LOGGER.error("checkInterval must be positive. checkInterval set equal to timeToLive = {}", ttl);
            ci = ttl;
        }
    }
    return new IdlePurgePolicy(ttl, ci, configuration.getScheduler());
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) PluginFactory(org.apache.logging.log4j.core.config.plugins.PluginFactory)

Example 79 with TimeUnit

use of java.util.concurrent.TimeUnit in project logging-log4j2 by apache.

the class Log4jServletContextListener method contextDestroyed.

@Override
public void contextDestroyed(final ServletContextEvent event) {
    if (this.servletContext == null || this.initializer == null) {
        LOGGER.warn("Context destroyed before it was initialized.");
        return;
    }
    LOGGER.debug("Log4jServletContextListener ensuring that Log4j shuts down properly.");
    // the application is finished
    this.initializer.clearLoggerContext();
    // shutting down now
    if (initializer instanceof LifeCycle2) {
        final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
        final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT : Long.parseLong(stopTimeoutStr);
        final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
        final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT : TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
        ((LifeCycle2) this.initializer).stop(stopTimeout, timeoutTimeUnit);
    } else {
        this.initializer.stop();
    }
}
Also used : LifeCycle2(org.apache.logging.log4j.core.LifeCycle2) TimeUnit(java.util.concurrent.TimeUnit)

Example 80 with TimeUnit

use of java.util.concurrent.TimeUnit in project lucene-solr by apache.

the class ZkStateReader method waitForState.

/**
   * Block until a CollectionStatePredicate returns true, or the wait times out
   *
   * Note that the predicate may be called again even after it has returned true, so
   * implementors should avoid changing state within the predicate call itself.
   *
   * @param collection the collection to watch
   * @param wait       how long to wait
   * @param unit       the units of the wait parameter
   * @param predicate  the predicate to call on state changes
   * @throws InterruptedException on interrupt
   * @throws TimeoutException on timeout
   */
public void waitForState(final String collection, long wait, TimeUnit unit, CollectionStatePredicate predicate) throws InterruptedException, TimeoutException {
    final CountDownLatch latch = new CountDownLatch(1);
    CollectionStateWatcher watcher = (n, c) -> {
        boolean matches = predicate.matches(n, c);
        if (matches)
            latch.countDown();
        return matches;
    };
    registerCollectionStateWatcher(collection, watcher);
    try {
        // wait for the watcher predicate to return true, or time out
        if (!latch.await(wait, unit))
            throw new TimeoutException();
    } finally {
        removeCollectionStateWatcher(collection, watcher);
    }
}
Also used : URLDecoder(java.net.URLDecoder) Utils(org.apache.solr.common.util.Utils) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Stat(org.apache.zookeeper.data.Stat) AtomicReference(java.util.concurrent.atomic.AtomicReference) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SolrException(org.apache.solr.common.SolrException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) EMPTY_MAP(java.util.Collections.EMPTY_MAP) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Pair(org.apache.solr.common.util.Pair) ErrorCode(org.apache.solr.common.SolrException.ErrorCode) ExecutorUtil(org.apache.solr.common.util.ExecutorUtil) EnumSet(java.util.EnumSet) ExecutorService(java.util.concurrent.ExecutorService) Callable(org.apache.solr.common.Callable) CoreAdminParams(org.apache.solr.common.params.CoreAdminParams) Collections.emptyMap(java.util.Collections.emptyMap) Logger(org.slf4j.Logger) KeeperException(org.apache.zookeeper.KeeperException) Collections.emptySet(java.util.Collections.emptySet) Watcher(org.apache.zookeeper.Watcher) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) WatchedEvent(org.apache.zookeeper.WatchedEvent) Collectors(java.util.stream.Collectors) Utils.fromJSON(org.apache.solr.common.util.Utils.fromJSON) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) Closeable(java.io.Closeable) Entry(java.util.Map.Entry) EventType(org.apache.zookeeper.Watcher.Event.EventType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Collections(java.util.Collections) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException)

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