Example usage for java.util.concurrent TimeUnit MINUTES

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

Introduction

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

Prototype

TimeUnit MINUTES

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

Click Source Link

Document

Time unit representing sixty seconds.

Usage

From source file:com.syncthemall.enml4j.util.Utils.java

/**
 * Convert a millisecond duration to a string format.
 * /*  w w  w. j ava 2s  .c o m*/
 * @param millis A duration to convert to a string form
 * @return A string of the form "X Days Y Hours Z Minutes A Seconds".
 */
public static String getDurationBreakdown(long millis) {
    if (millis < 0) {
        throw new IllegalArgumentException("Duration must be greater than zero!");
    }

    long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
    millis -= TimeUnit.MINUTES.toMillis(minutes);

    long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
    millis -= TimeUnit.SECONDS.toMillis(seconds);

    StringBuilder sb = new StringBuilder();
    sb.append(minutes);
    sb.append(" Minutes ");
    sb.append(seconds);
    sb.append(" Seconds ");
    sb.append(millis);
    sb.append(" Milliseconds");

    return sb.toString();
}

From source file:functionaltests.SchedulerClientTest.java

@Test(timeout = MAX_WAIT_TIME)
public void testJobResult() throws Throwable {
    ISchedulerClient client = clientInstance();
    Job job = createJobManyTasks("JobResult", SimpleJob.class, ErrorTask.class, LogTask.class,
            VariableTask.class, MetadataTask.class);
    JobId jobId = submitJob(job, client);
    JobResult result = client.waitForJob(jobId, TimeUnit.MINUTES.toMillis(3));
    // job result
    Assert.assertNotNull(result.getJobId());
    Assert.assertNotNull(result.getJobInfo());
    Assert.assertEquals(JobStatus.FINISHED, result.getJobInfo().getStatus());

    // the following check cannot work because of the way the job id is created on the client side.
    //Assert.assertEquals(job.getName(), result.getName());
    Assert.assertTrue(result.hadException());
    Assert.assertEquals(1, result.getExceptionResults().size());

    // job info// ww  w  .j a  va2  s. co  m
    checkJobInfo(result.getJobInfo());
    checkJobInfo(client.getJobInfo(jobId.value()));

    JobState jobState = client.getJobState(jobId.value());
    JobStatus status = jobState.getStatus();
    Assert.assertFalse(status.isJobAlive());
    Assert.assertEquals(JobStatus.FINISHED, status);

    checkJobInfo(jobState.getJobInfo());

    TaskState errorTaskState = findTask(getTaskNameForClass(ErrorTask.class), jobState.getHMTasks());
    Assert.assertNotNull(errorTaskState);
    TaskState simpleTaskState = findTask(getTaskNameForClass(SimpleJob.class), jobState.getHMTasks());
    Assert.assertNotNull(simpleTaskState);
    Assert.assertEquals(TaskStatus.FAULTY, errorTaskState.getStatus());
    Assert.assertEquals(TaskStatus.FINISHED, simpleTaskState.getStatus());

    // task result simple
    TaskResult tResSimple = result.getResult(getTaskNameForClass(SimpleJob.class));
    Assert.assertNotNull(tResSimple.value());
    Assert.assertEquals(new StringWrapper(TEST_JOB), tResSimple.value());

    // task result with error
    TaskResult tResError = result.getResult(getTaskNameForClass(ErrorTask.class));
    Assert.assertNotNull(tResError);
    Assert.assertTrue(tResError.hadException());
    Assert.assertNotNull(tResError.getException());
    Assert.assertTrue(tResError.getException() instanceof TaskException);

    // task result with logs
    TaskResult tResLog = result.getResult(getTaskNameForClass(LogTask.class));
    Assert.assertNotNull(tResLog);
    Assert.assertNotNull(tResLog.getOutput());
    System.err.println(tResLog.getOutput().getStdoutLogs(false));
    Assert.assertTrue(tResLog.getOutput().getStdoutLogs(false).contains(LogTask.HELLO_WORLD));

    // task result with variables
    TaskResult tResVar = result.getResult(getTaskNameForClass(VariableTask.class));
    Assert.assertNotNull(tResVar.getPropagatedVariables());
    Assert.assertTrue(tResVar.getPropagatedVariables().containsKey(VariableTask.MYVAR));

    // task result with metadata
    TaskResult tMetaVar = result.getResult(getTaskNameForClass(MetadataTask.class));
    Assert.assertNotNull(tMetaVar.getMetadata());
    Assert.assertTrue(tMetaVar.getMetadata().containsKey(MetadataTask.MYVAR));

}

From source file:com.intuit.wasabi.assignment.cache.impl.AssignmentsMetadataCacheImpl.java

@Inject
public AssignmentsMetadataCacheImpl(@CassandraRepository ExperimentRepository experimentRepository,
        PrioritiesRepository prioritiesRepository, MutexRepository mutexRepository,
        PagesRepository pagesRepository,
        @Named(ASSIGNMENTS_METADATA_CACHE_REFRESH_CACHE_SERVICE) ScheduledExecutorService refreshCacheService,
        @Named(ASSIGNMENTS_METADATA_CACHE_REFRESH_INTERVAL) Integer refreshIntervalInMinutes,
        @Named(ASSIGNMENTS_METADATA_CACHE_REFRESH_TASK) Runnable metadataCacheRefreshTask,
        HealthCheckRegistry healthCheckRegistry,
        @Named(ASSIGNMENTS_METADATA_CACHE_HEALTH_CHECK) HealthCheck metadataCacheHealthCheck,
        CacheManager cacheManager) {//from   www  .java 2s  .c  o  m

    this.experimentRepository = experimentRepository;
    this.prioritiesRepository = prioritiesRepository;
    this.mutexRepository = mutexRepository;
    this.pagesRepository = pagesRepository;
    this.metadataCacheRefreshTask = (AssignmentsMetadataCacheRefreshTask) metadataCacheRefreshTask;
    this.cacheManager = cacheManager;

    //Schedule metadata cache refresh task
    refreshCacheService.scheduleAtFixedRate(metadataCacheRefreshTask, refreshIntervalInMinutes,
            refreshIntervalInMinutes, TimeUnit.MINUTES);

    //Register health check
    healthCheckRegistry.register(ASSIGNMENT_METADATA_CACHE_SERVICE_NAME, metadataCacheHealthCheck);

    //Create new caches
    for (CACHE_NAME name : CACHE_NAME.values()) {
        cacheManager.addCache(name.toString());
    }

    LOGGER.info("Assignments metadata cache has been created successfully...");
}

From source file:com.amazonaws.codepipeline.jobworker.JobWorkerDaemonTest.java

@Test
public void shouldForceStoppingSchedulingJobPollerAfterOneMinute() throws Exception {
    // given//from w  w w. j  a v  a 2s  .c  om
    when(executorService.awaitTermination(1, TimeUnit.MINUTES)).thenReturn(false).thenReturn(true);

    // when
    jobWorkerDaemon.stop();

    // then
    verify(executorService).shutdown();
    verify(executorService).shutdownNow();
}

From source file:io.kamax.mxisd.invitation.InvitationManager.java

@PreDestroy
private void preDestroy() {
    refreshTimer.cancel();
    ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.MINUTES);
}

From source file:hudson.security.TokenBasedRememberMeServices2SEC868Test.java

@Test
@Issue("SECURITY-868")
public void rememberMeToken_shouldNotAccept_expirationDurationLargerThanConfigured() throws Exception {
    j.jenkins.setDisableRememberMe(false);

    HudsonPrivateSecurityRealm realm = new HudsonPrivateSecurityRealm(false, false, null);
    TokenBasedRememberMeServices2 tokenService = (TokenBasedRememberMeServices2) realm
            .getSecurityComponents().rememberMe;
    j.jenkins.setSecurityRealm(realm);/* www . j a v a2s  .com*/

    String username = "alice";
    User alice = realm.createAccount(username, username);

    { // a malicious cookie with expiration too far in the future should not work
        JenkinsRule.WebClient wc = j.createWebClient();

        // by default we have 14 days of validity, 
        // here we increase artificially the duration of validity, that could be used to have permanent access
        long oneDay = TimeUnit.DAYS.toMillis(1);
        Cookie cookie = createRememberMeCookie(tokenService, oneDay, alice);
        wc.getCookieManager().addCookie(cookie);

        // the application should not use the cookie to connect
        assertUserNotConnected(wc, username);
    }

    { // a hand crafted cookie with regular expiration duration works
        JenkinsRule.WebClient wc = j.createWebClient();

        // by default we have 14 days of validity, 
        // here we reduce a bit the expiration date to simulate an "old" cookie (regular usage)
        long minusFiveMinutes = TimeUnit.MINUTES.toMillis(-5);
        Cookie cookie = createRememberMeCookie(tokenService, minusFiveMinutes, alice);
        wc.getCookieManager().addCookie(cookie);

        // if we reactivate the remember me feature, it's ok
        assertUserConnected(wc, username);
    }
}

From source file:com.cognifide.aet.worker.drivers.FirefoxWebDriverFactory.java

private AetFirefoxDriver getFirefoxDriver(FirefoxProfile fp, DesiredCapabilities capabilities)
        throws IOException {
    AetFirefoxDriver driver;//from  www . j a  v a 2s. com
    if (StringUtils.isBlank(path)) {
        driver = new AetFirefoxDriver(capabilities);
    } else {
        FirefoxBinary binary = new FirefoxBinary(new File(path));
        driver = new AetFirefoxDriver(binary, fp, capabilities);
    }
    driver.manage().timeouts().pageLoadTimeout(5L, TimeUnit.MINUTES);
    return driver;
}

From source file:no.uis.fsws.proxy.StudinfoProxyImpl.java

@Override
@SneakyThrows/*from   w  w  w.j  av a 2s.co  m*/
public List<Emne> getEmne(final XMLGregorianCalendar arstall, final Terminkode terminkode,
        final Sprakkode sprak, final int institusjonsnr, final String emnekode, final String versjonskode) {
    final StudInfoImport svc = getServiceForPrincipal();
    Future<List<Emne>> future = executor.submit(new Callable<List<Emne>>() {

        @Override
        public List<Emne> call() throws Exception {
            final FsStudieinfo sinfo = svc.fetchSubject(institusjonsnr, emnekode, versjonskode,
                    arstall.getYear(), terminkode.toString(), sprak.toString());
            return sinfo.getEmne();
        }
    });

    return future.get(timeoutMinutes, TimeUnit.MINUTES);
}

From source file:com.stgmastek.birt.report.ReportService.java

/**
 * Initializes the service./*from  w w w.ja  va 2 s.  c  o  m*/
 * @param config
 * @throws ReportServiceException
 */
private void initialize(EngineConfigWrapper configWrapper) {
    //// Create Executor Service to hold ReportService Instance
    Integer size = new Integer((String) configWrapper.getEngineConfig().getProperty("threadPoolSize"));
    this.service = Executors.newFixedThreadPool(size.intValue());
    try {
        Platform.startup(configWrapper.getEngineConfig());
    } catch (BirtException e) {
        throw new ReportServiceException(e.getMessage(), e);
    }

    //// Engine Object Pool
    pool = new GenericObjectPool(new BIRTEngineFactory(configWrapper.getEngineConfig()));
    pool.setMaxActive(size);
    pool.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES.toMillis(5));
    initialized = true;
    logger.debug("ReportService pool initialized !! Total Pool size : [" + size + "]");
}

From source file:com.linkedin.pinot.integration.tests.MetadataAndDictionaryAggregationPlanClusterIntegrationTest.java

private void loadDataIntoH2(List<File> avroFiles) throws Exception {
    ExecutorService executor = Executors.newCachedThreadPool();
    setUpH2Connection(avroFiles, executor);
    executor.shutdown();/*from ww w  .j a v  a  2  s  .c o  m*/
    executor.awaitTermination(10, TimeUnit.MINUTES);
}