Example usage for java.time Duration toMillis

List of usage examples for java.time Duration toMillis

Introduction

In this page you can find the example usage for java.time Duration toMillis.

Prototype

public long toMillis() 

Source Link

Document

Converts this duration to the total length in milliseconds.

Usage

From source file:Main.java

public static void main(String[] args) {
    Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON);
    System.out.println(duration.toMillis());

}

From source file:io.appium.java_client.pagefactory_tests.TimeoutTest.java

private static long getExpectedMillis(Duration duration) {
    return duration.toMillis();
}

From source file:io.appium.java_client.pagefactory_tests.TimeoutTest.java

private static String assertionMessage(Duration expectedDuration) {
    return format("Check difference from the expected waiting duration %s",
            formatDuration(expectedDuration.toMillis(), "H:mm:ss:SSS", true));
}

From source file:com.epam.dlab.automation.helper.WaitForStatus.java

public static boolean selfService(Duration duration) throws InterruptedException {
    HttpRequest request = new HttpRequest();
    int actualStatus;
    long timeout = duration.toMillis();
    long expiredTime = System.currentTimeMillis() + timeout;

    while ((actualStatus = request.webApiGet(NamingHelper.getSsnURL(), ContentType.TEXT)
            .statusCode()) != HttpStatusCode.OK) {
        if (timeout != 0 && expiredTime < System.currentTimeMillis()) {
            break;
        }/*from  ww w.ja  v  a 2  s  . c  om*/
        Thread.sleep(getSsnRequestTimeout());
    }

    if (actualStatus != HttpStatusCode.OK) {
        LOGGER.info("ERROR: Timeout has been expired for SSN available. Timeout was {}", duration);
        return false;
    } else {
        LOGGER.info("Current status code for SSN is {}", actualStatus);
    }

    return true;
}

From source file:com.epam.dlab.automation.helper.WaitForStatus.java

public static int uploadKey(String url, String token, int status, Duration duration)
        throws InterruptedException {
    LOGGER.info(" Waiting until status code {} with URL {} with token {}", status, url, token);
    HttpRequest request = new HttpRequest();
    int actualStatus;
    long timeout = duration.toMillis();
    long expiredTime = System.currentTimeMillis() + timeout;

    while ((actualStatus = request.webApiGet(url, token).getStatusCode()) == status) {
        if (timeout != 0 && expiredTime < System.currentTimeMillis()) {
            break;
        }/*  w  ww  . ja  va 2 s.c  om*/
        Thread.sleep(getSsnRequestTimeout());
    }

    if (actualStatus == status) {
        LOGGER.info("ERROR: {}: Timeout has been expired for request.");
        LOGGER.info("  URL is {}", url);
        LOGGER.info("  token is {}", token);
        LOGGER.info("  status is {}", status);
        LOGGER.info("  timeout is {}", duration);
    } else {
        LOGGER.info(" Current status code for {} is {}", url, actualStatus);
    }

    return actualStatus;
}

From source file:com.epam.dlab.automation.helper.WaitForStatus.java

public static String notebook(String url, String token, String notebookName, String status, Duration duration)
        throws InterruptedException {
    LOGGER.info("Waiting for status {} with URL {} with token {} for notebook {}", status, url, token,
            notebookName);/*from   w  w  w.  j ava 2  s  . com*/
    HttpRequest request = new HttpRequest();
    String actualStatus;
    long timeout = duration.toMillis();
    long expiredTime = System.currentTimeMillis() + timeout;

    do {
        actualStatus = getNotebookStatus(request.webApiGet(url, token).getBody().jsonPath(), notebookName);
        if (timeout != 0 && expiredTime < System.currentTimeMillis()) {
            break;
        }
        Thread.sleep(getSsnRequestTimeout());
    } while (status.contains(actualStatus));

    if (status.contains(actualStatus)) {
        LOGGER.info("ERROR: {}: Timeout has been expired for request.", notebookName);
        LOGGER.info("  {}: URL is {}", notebookName, url);
        LOGGER.info("  {}: token is {}", notebookName, token);
        LOGGER.info("  {}: status is {}", notebookName, status);
        LOGGER.info("  {}: timeout is {}", notebookName, duration);
    } else {
        LOGGER.info("{}: Current state for Notebook {} is {}", notebookName, notebookName, actualStatus);
    }

    return actualStatus;
}

From source file:com.epam.dlab.automation.helper.WaitForStatus.java

public static String cluster(String url, String token, String notebookName, String computationalName,
        String status, Duration duration) throws InterruptedException {
    LOGGER.info("{}: Waiting until status {} with URL {} with token {} for computational {} on notebook {}",
            notebookName, status, url, token, computationalName, notebookName);
    HttpRequest request = new HttpRequest();
    String actualStatus;// www. jav a2 s. co m
    long timeout = duration.toMillis();
    long expiredTime = System.currentTimeMillis() + timeout;

    do {
        actualStatus = getClusterStatus(request.webApiGet(url, token).getBody().jsonPath(), notebookName,
                computationalName);
        if (timeout != 0 && expiredTime < System.currentTimeMillis()) {
            break;
        }
        Thread.sleep(getSsnRequestTimeout());
    } while (actualStatus.contains(status));

    if (actualStatus.contains(status)) {
        LOGGER.info("ERROR: Timeout has been expired for request.");
        LOGGER.info("  URL is {}", url);
        LOGGER.info("  token is {}", token);
        LOGGER.info("  status is {}", status);
        LOGGER.info("  timeout is {}", duration);
    } else {
        LOGGER.info("{}: Current state for cluster {} on notebook is {}", notebookName, computationalName,
                actualStatus);
    }

    return actualStatus;
}

From source file:com.liferay.jenkins.tools.DurationMatcher.java

protected int parseDuration(String[] optionValues) throws IllegalArgumentException {
    String joinedString = StringUtils.join(optionValues, "");
    String spacedString = StringUtils.join(optionValues, " ");

    try {/*from w  w  w  .j ava2  s. c  o m*/
        return Integer.parseInt(joinedString);
    } catch (NumberFormatException e) {
        logger.debug("'{}' is not a numeric duration string", spacedString);
    }

    try {
        Duration durationObject = Duration.parse(joinedString);

        return (int) durationObject.toMillis();
    } catch (DateTimeParseException e) {
        logger.debug("'{}' is not an ISO-8601 duration string", spacedString);
    }

    try {
        String textDurationString = parseTextDuration(optionValues);

        Duration durationObject = Duration.parse(textDurationString);

        return (int) durationObject.toMillis();
    } catch (DateTimeParseException e) {
        logger.debug("'{}' is not a text duration string", spacedString);
    }

    throw new IllegalArgumentException("Unable to parse duration string '" + spacedString + "'");
}

From source file:org.ng200.openolympus.DurationJacksonModule.java

public DurationJacksonModule() {
    addSerializer(new JsonSerializer<Duration>() {
        @Override//ww  w.  jav  a  2 s  . c o m
        public void serialize(Duration duration, JsonGenerator gen, SerializerProvider serializerProvider)
                throws IOException, JsonProcessingException {
            gen.writeNumber(duration.toMillis());
        }

        @Override
        public Class<Duration> handledType() {
            return Duration.class;
        }
    });
    addDeserializer(Duration.class, new JsonDeserializer<Duration>() {
        @Override
        public Duration deserialize(JsonParser jp, DeserializationContext ctxt)
                throws IOException, JsonProcessingException {
            long l = jp.getValueAsLong();
            return Duration.ofMillis(l);
        }

        @Override
        public Class<Duration> handledType() {
            return Duration.class;
        }
    });
}

From source file:com.epam.dlab.automation.jenkins.JenkinsService.java

private void waitForJenkinsStartup(Duration duration) throws InterruptedException {
    String actualStatus;/*from   w w  w  .j  a  v  a2s.c om*/
    long timeout = duration.toMillis();
    long expiredTime = System.currentTimeMillis() + timeout;

    while ((actualStatus = getQueueStatus()).endsWith(JenkinsConfigProperties.SUCCESS_STATUS)) {
        Thread.sleep(JenkinsConfigProperties.JENKINS_REQUEST_TIMEOUT);
        if (timeout != 0 && expiredTime < System.currentTimeMillis()) {
            actualStatus = getQueueStatus();
            break;
        }
    }

    if (actualStatus.endsWith(JenkinsConfigProperties.SUCCESS_STATUS)) {
        LOGGER.info("ERROR: Timeout has been expired for Jenkins");
        LOGGER.info("  timeout is {}");
    }
}