Example usage for java.util.concurrent TimeUnit MILLISECONDS

List of usage examples for java.util.concurrent TimeUnit MILLISECONDS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit MILLISECONDS.

Prototype

TimeUnit MILLISECONDS

To view the source code for java.util.concurrent TimeUnit MILLISECONDS.

Click Source Link

Document

Time unit representing one thousandth of a second.

Usage

From source file:org.mule.module.http.functional.listener.HttpListenerNotificationsTestCase.java

@Test
public void receiveNotification() throws Exception {
    String listenerUrl = String.format("http://localhost:%s/%s", listenPort.getNumber(), path.getValue());

    CountDownLatch latch = new CountDownLatch(2);
    TestConnectorMessageNotificationListener listener = new TestConnectorMessageNotificationListener(latch,
            listenerUrl);/*www.j  a  v  a 2 s  . c o m*/
    muleContext.getNotificationManager().addListener(listener);

    Request.Post(listenerUrl).execute();

    latch.await(1000, TimeUnit.MILLISECONDS);

    assertThat(listener.getNotificationActionNames(),
            contains(getActionName(MESSAGE_RECEIVED), getActionName(MESSAGE_RESPONSE)));
}

From source file:org.bpmscript.integration.spring.SpringSyncChannel.java

/**
 * @see org.bpmscript.channel.reply.ISyncService#get(java.lang.String, long)
 *//*  w  w w. j ava 2s. c o  m*/
public Object get(String id, long duration) {
    BlockingQueue<Object> blockingQueue = null;
    blockingQueue = replies.get(id);
    if (blockingQueue != null) {
        try {
            if (duration > 0) {
                return blockingQueue.poll(duration, TimeUnit.MILLISECONDS);
            } else {
                return blockingQueue.take();
            }
        } catch (InterruptedException e) {
            return null;
        }
    } else {
        return null;
    }
}

From source file:com.willwinder.universalgcodesender.utils.ThreadHelperTest.java

@Test
public void waitUntilWhenChangeToTrueAfterTimeShouldReturnOk() throws TimeoutException {
    waitUntilCondition = false;/*from  ww w . j av  a 2 s .com*/

    // Start a timer that switches the condition after some time
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            waitUntilCondition = true;
        }
    }, 500);

    // Wait until the condition switches
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    ThreadHelper.waitUntil(() -> waitUntilCondition, 1000, TimeUnit.MILLISECONDS);
    stopWatch.stop();

    // Make sure it was within the time interval
    assertTrue(stopWatch.getTime() < 1000);
    assertTrue(stopWatch.getTime() >= 500);
}

From source file:org.flite.cach3.aop.LogicalCacheImpl.java

public void afterPropertiesSet() throws Exception {
    this.nanny = CacheBuilder.newBuilder().maximumSize(10000).expireAfterWrite(5, TimeUnit.MINUTES).build();

    // TODO: Refactor to use a configurable set of cache sizes.
    for (final Duration duration : DURATION_SET) {
        final Cache<String, Object> single = CacheBuilder.newBuilder().maximumSize(1000)
                .expireAfterWrite(duration.getMillis(), TimeUnit.MILLISECONDS).build();
        caches.put(duration, single);/*  w  ww  .jav a  2 s  . co m*/
    }
}

From source file:com.epam.reportportal.apache.http.impl.execchain.TestConnectionHolder.java

@Test
public void testAbortConnection() throws Exception {
    connHolder.abortConnection();/*  w  w w . j  a va2 s .  c om*/

    Assert.assertTrue(connHolder.isReleased());

    Mockito.verify(conn).shutdown();
    Mockito.verify(mgr).releaseConnection(conn, null, 0, TimeUnit.MILLISECONDS);

    connHolder.abortConnection();

    Mockito.verify(conn, Mockito.times(1)).shutdown();
    Mockito.verify(mgr, Mockito.times(1)).releaseConnection(Mockito.<HttpClientConnection>any(),
            Mockito.anyObject(), Mockito.anyLong(), Mockito.<TimeUnit>any());
}

From source file:ch.ivyteam.ivy.maven.TestIarDeployMojo.java

@Test
public void failOnEngineDeployError() throws Exception {
    IarDeployMojo mojo = rule.getMojo();
    DeploymentMarkerFiles markers = new DeploymentMarkerFiles(getTarget(mojo.deployIarFile, mojo));

    DelayedOperation mockEngineDeployThread = new DelayedOperation(500, TimeUnit.MILLISECONDS);
    Callable<Void> engineOperation = () -> {
        assertThat(markers.doDeploy()).as("deployment must be initialized").exists();
        FileUtils.write(markers.errorLog(), "validation errors");
        markers.doDeploy().delete(); //deployment finished
        return null;
    };//  w  w  w .java 2 s.co  m

    mockEngineDeployThread.execute(engineOperation);
    try {
        mojo.execute();
        failBecauseExceptionWasNotThrown(MojoExecutionException.class);
    } catch (MojoExecutionException ex) {
        assertThat(ex).hasMessageContaining("failed!");
    } finally {
        mockEngineDeployThread.failOnExecption();
    }
}

From source file:com.walmart.gatling.MonitoringConfiguration.java

public ConsoleReporter consoleReporter(MetricRegistry registry) {
    ConsoleReporter reporter = ConsoleReporter.forRegistry(registry).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).build();
    reporter.start(10, TimeUnit.SECONDS);
    return reporter;
}

From source file:org.openbaton.nse.beans.openbaton.QoSAllocator.java

public void addQos(Set<VirtualNetworkFunctionRecord> vnfrs, String nsrId) {
    logger.debug("Creating ADD Thread");

    // Check which driver to use
    if (nse_configuration.getDriver().equals("neutron")) {
        Neutron_AddQoSExecutor aqe = new Neutron_AddQoSExecutor(vnfrs, this.nfvo_configuration,
                neutron_handler);/*from  www .  j  av  a  2 s . c  o  m*/
        qtScheduler.schedule(aqe, 100, TimeUnit.MILLISECONDS);

    }
    // Else , always assume we are using the cm_agent
    else {
        AddQoSExecutor aqe = new AddQoSExecutor(handler, vnfrs, nsrId);
        qtScheduler.schedule(aqe, 100, TimeUnit.MILLISECONDS);
    }
    logger.debug("ADD Thread created and scheduled");
}

From source file:org.cfg4j.sample.ConfigBeans.java

@Bean
public ConfigurationProvider configurationProvider() {
    // Specify which files to load. Configuration from both files will be merged.
    ConfigFilesProvider configFilesProvider = () -> Collections.singletonList(Paths.get("application.yaml"));

    // Use local files as configuration store
    ConfigurationSource source = new FilesConfigurationSource(configFilesProvider);

    // Use relative paths
    Environment environment = new ImmutableEnvironment(filesPath);

    // Reload configuration every 500 milliseconds
    ReloadStrategy reloadStrategy = new PeriodicalReloadStrategy(500, TimeUnit.MILLISECONDS);

    // Create provider
    return new ConfigurationProviderBuilder().withConfigurationSource(source).withReloadStrategy(reloadStrategy)
            .withEnvironment(environment).withMetrics(metricRegistry, "firstProvider.").build();
}