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:de.speexx.jira.jan.command.issuequery.CsvCreator.java

LocalDateTime addChangeData(final List<String> out, final HistoricalDataEntry entry,
        final TemporalChangeOutput temporalOutput, final LocalDateTime lastChangeDate) {
    out.add(entry.getFrom());//from w  w w  . j  ava  2 s  .c om
    final LocalDateTime changeDate = entry.getChangeDate();
    if (temporalOutput == TIME || temporalOutput == BOTH) {
        out.add(localDateTimeToString(entry.getChangeDate()));
    }
    if (temporalOutput == DURATION || temporalOutput == BOTH) {
        final Duration duration = Duration.between(lastChangeDate, changeDate);
        final String dur = String.valueOf(duration.toMillis() /*/ MILLIS*/);
        out.add(dur);
    }
    out.add(entry.getTo());
    return changeDate;
}

From source file:de.loercher.localpress.integration.GeoAndRatingITest.java

@Test
public void testAddArticle() {
    String nowString = "2015-10-12T08:00+02:00[Europe/Berlin]";
    ZonedDateTime now = new DateTimeConverter().fromString(nowString);

    AddArticleEntityDTO geoDTO = new AddArticleEntityDTO(nowString);
    Instant instant = now.toInstant();
    Instant fir = Instant.now();

    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("UserID", "ulf");

    HttpEntity<AddArticleEntityDTO> request = new HttpEntity<>(geoDTO, headers);

    RestTemplate template = new RestTemplate();
    ResponseEntity<Map> result = template.postForEntity("http://52.29.77.191:8080/localpress/feedback", request,
            Map.class);

    Instant afterRating = Instant.now();

    GeoBaseEntity.EntityBuilder builder = new GeoBaseEntity.EntityBuilder();
    GeoBaseEntity entity = builder.author("ulf")
            .coordinates(Arrays.asList(new Coordinate[] { new Coordinate(50.1, 8.4) }))
            .timestamp(now.toEpochSecond()).content("abc.de").title("mein titel").user("ulf").build();

    HttpEntity<GeoBaseEntity> second = new HttpEntity<>(entity, headers);
    System.out.println(result.getBody().get("articleID"));

    template.put("http://euve33985.vserver.de:8080/geo/" + result.getBody().get("articleID"), second);

    Instant afterGeoPut = Instant.now();

    result = template.getForEntity("http://euve33985.vserver.de:8080/geo/" + result.getBody().get("articleID"),
            Map.class);

    Instant afterGeoGet = Instant.now();

    assertEquals("User ID has changed over time!", "ulf", result.getBody().get("user"));
    assertEquals("Content URL has changed over time!", "abc.de", result.getBody().get("content"));

    DateTimeConverter conv = new DateTimeConverter();

    Duration first = Duration.between(fir, afterRating);
    Duration sec = Duration.between(afterRating, afterGeoPut);
    Duration third = Duration.between(afterGeoPut, afterGeoGet);

    System.out.println("Begin: " + conv.toString(now));
    System.out.println("Time until POST to rating: " + new Double(first.toMillis()) / 1000);
    System.out.println("Time until PUT to geo: " + new Double(sec.toMillis()) / 1000);
    System.out.println("Time until GET to geo: " + new Double(third.toMillis()) / 1000);
}

From source file:com.joyent.manta.client.multipart.JobsMultipartManagerIT.java

public void canAbortMultipartBinary() throws IOException {
    final long oneMB = 1024L * 1024L;

    File[] parts = new File[] { createTemporaryDataFile(oneMB, 1), createTemporaryDataFile(oneMB, 1),
            createTemporaryDataFile(oneMB, 1) };

    final String name = uploadName("can-abort-multipart-binary");
    final String path = testPathPrefix + name;

    final JobsMultipartUpload upload = multipart.initiateUpload(path);

    final ArrayList<MantaMultipartUploadTuple> uploadedParts = new ArrayList<>();

    for (int i = 0; i < parts.length; i++) {
        File part = parts[i];// w  ww.  j av a  2  s  .co  m
        int partNumber = i + 1;
        MantaMultipartUploadTuple uploaded = multipart.uploadPart(upload, partNumber, part);
        uploadedParts.add(uploaded);
    }

    multipart.validateThatThereAreSequentialPartNumbers(upload);
    multipart.complete(upload, uploadedParts);

    Instant start = Instant.now();
    multipart.abort(upload);

    boolean caught = false;

    try {
        multipart.waitForCompletion(upload, (Function<UUID, Void>) uuid -> {
            fail("Completion operation didn't succeed within timeout");
            return null;
        });
    } catch (MantaMultipartException e) {
        if (e.getMessage().startsWith("Manta job backing multipart upload was "
                + "aborted. This upload was unable to be completed.")) {
            caught = true;
        }
    }

    assertTrue(caught, "Backing job aborted exception wasn't thrown");
    Instant end = Instant.now();

    MantaMultipartStatus status = multipart.getStatus(upload);
    assertEquals(status, MantaMultipartStatus.ABORTED);

    MantaJob job = multipart.findJob(upload);

    Duration totalCompletionTime = Duration.between(start, end);

    LOG.info("Aborting took {} seconds", totalCompletionTime.toMillis() / 1000);

    if (!job.getCancelled()) {
        fail("Job wasn't cancelled:" + job.toString());
    }

    assertFalse(mantaClient.existsAndIsAccessible(multipart.multipartUploadDir(upload.getId())),
            "Upload directory shouldn't be present after abort");
}

From source file:com.joyent.manta.client.multipart.JobsMultipartManagerIT.java

public void canUploadSmallMultipartString() throws IOException {
    String[] parts = new String[] { "Hello ", "world ", "Joyent", "!" };

    StringBuilder combined = new StringBuilder();
    for (String p : parts) {
        combined.append(p);//from  www.  ja  va2s.  c  om
    }

    final String name = uploadName("can-upload-small-multipart-string");
    final String path = testPathPrefix + name;

    final JobsMultipartUpload upload = multipart.initiateUpload(path);
    final ArrayList<MantaMultipartUploadTuple> uploadedParts = new ArrayList<>();

    for (int i = 0; i < parts.length; i++) {
        String part = parts[i];
        int partNumber = i + 1;
        MantaMultipartUploadTuple uploaded = multipart.uploadPart(upload, partNumber, part);

        uploadedParts.add(uploaded);
    }

    multipart.validateThatThereAreSequentialPartNumbers(upload);
    Instant start = Instant.now();
    multipart.complete(upload, uploadedParts);

    multipart.waitForCompletion(upload, (Function<UUID, Void>) uuid -> {
        fail("Completion operation didn't succeed within timeout");
        return null;
    });
    Instant end = Instant.now();

    MantaMultipartStatus status = multipart.getStatus(upload);

    assertEquals(status, MantaMultipartStatus.COMPLETED);

    assertEquals(mantaClient.getAsString(path), combined.toString(),
            "Manta combined string doesn't match expectation: " + multipart.findJob(upload));

    Duration totalCompletionTime = Duration.between(start, end);

    LOG.info("Concatenating {} parts took {} seconds", parts.length, totalCompletionTime.toMillis() / 1000);
}

From source file:com.joyent.manta.client.multipart.EncryptedJobsMultipartManagerIT.java

public void canAbortMultipartBinary() throws IOException {
    final long oneMB = 1024L * 1024L;

    File[] parts = new File[] { createTemporaryDataFile(oneMB, 1), createTemporaryDataFile(oneMB, 1),
            createTemporaryDataFile(oneMB, 1) };

    final String name = uploadName("can-abort-multipart-binary");
    final String path = testPathPrefix + name;

    final EncryptedMultipartUpload<JobsMultipartUpload> upload = multipart.initiateUpload(path);

    final ArrayList<MantaMultipartUploadTuple> uploadedParts = new ArrayList<>();

    for (int i = 0; i < parts.length; i++) {
        File part = parts[i];//from   w  w  w  .j a v a2 s.  c o m
        int partNumber = i + 1;
        MantaMultipartUploadTuple uploaded = multipart.uploadPart(upload, partNumber, part);
        uploadedParts.add(uploaded);
    }

    multipart.validateThatThereAreSequentialPartNumbers(upload);
    multipart.complete(upload, uploadedParts);

    Instant start = Instant.now();
    multipart.abort(upload);

    boolean caught = false;

    try {
        multipart.getWrapped().waitForCompletion(upload, (Function<UUID, Void>) uuid -> {
            fail("Completion operation didn't succeed within timeout");
            return null;
        });
    } catch (MantaMultipartException e) {
        if (e.getMessage().startsWith("Manta job backing multipart upload was "
                + "aborted. This upload was unable to be completed.")) {
            caught = true;
        }
    }

    assertTrue(caught, "Backing job aborted exception wasn't thrown");
    Instant end = Instant.now();

    MantaMultipartStatus status = multipart.getStatus(upload);
    assertEquals(status, MantaMultipartStatus.ABORTED);

    MantaJob job = multipart.getWrapped().findJob(upload);

    Duration totalCompletionTime = Duration.between(start, end);

    LOG.info("Aborting took {} seconds", totalCompletionTime.toMillis() / 1000);

    if (!job.getCancelled()) {
        fail("Job wasn't cancelled:" + job.toString());
    }

    assertFalse(mantaClient.existsAndIsAccessible(multipart.getWrapped().multipartUploadDir(upload.getId())),
            "Upload directory shouldn't be present after abort");
}

From source file:com.joyent.manta.client.multipart.JobsMultipartManagerIT.java

private void canUploadMultipartBinary(final long sizeInMb, final int noOfParts) throws IOException {
    final long size = sizeInMb * 1024L * 1024L;

    File[] parts = new File[noOfParts];

    for (int i = 0; i < noOfParts; i++) {
        parts[i] = createTemporaryDataFile(size, 1);
    }/*from   w w  w  .  ja v a2 s.  c o m*/

    final File expectedFile = concatenateFiles(parts);
    final byte[] expectedMd5 = md5(expectedFile);

    final String name = uploadName("can-upload-5mb-multipart-binary");
    final String path = testPathPrefix + name;

    final JobsMultipartUpload upload = multipart.initiateUpload(path);

    final ArrayList<MantaMultipartUploadTuple> uploadedParts = new ArrayList<>();

    for (int i = 0; i < parts.length; i++) {
        File part = parts[i];
        int partNumber = i + 1;
        MantaMultipartUploadTuple uploaded = multipart.uploadPart(upload, partNumber, part);
        uploadedParts.add(uploaded);
    }

    multipart.validateThatThereAreSequentialPartNumbers(upload);
    Instant start = Instant.now();
    multipart.complete(upload, uploadedParts.stream());
    multipart.waitForCompletion(upload, (Function<UUID, Void>) uuid -> {
        fail("Completion operation didn't succeed within timeout");
        return null;
    });
    Instant end = Instant.now();

    MantaMultipartStatus status = multipart.getStatus(upload);
    assertEquals(status, MantaMultipartStatus.COMPLETED);

    MantaObjectResponse head = mantaClient.head(path);
    byte[] remoteMd5 = head.getMd5Bytes();

    if (!Arrays.equals(remoteMd5, expectedMd5)) {
        StringBuilder builder = new StringBuilder();
        builder.append("MD5 values do not match - job id: ").append(multipart.findJob(upload));
        fail(builder.toString());
    }

    Duration totalCompletionTime = Duration.between(start, end);

    LOG.info("Concatenating {} parts took {} seconds", parts.length, totalCompletionTime.toMillis() / 1000);
}

From source file:com.joyent.manta.client.multipart.EncryptedJobsMultipartManagerIT.java

public void canUploadSmallMultipartString() throws IOException {
    String[] parts = new String[] { "Hello ", "world ", "Joyent", "!" };

    StringBuilder combined = new StringBuilder();
    for (String p : parts) {
        combined.append(p);//  w  w w  . j  a  va 2s .c om
    }

    final String name = uploadName("can-upload-small-multipart-string");
    final String path = testPathPrefix + name;

    final EncryptedMultipartUpload<JobsMultipartUpload> upload = multipart.initiateUpload(path);
    final ArrayList<MantaMultipartUploadTuple> uploadedParts = new ArrayList<>();

    for (int i = 0; i < parts.length; i++) {
        String part = parts[i];
        int partNumber = i + 1;
        MantaMultipartUploadTuple uploaded = multipart.uploadPart(upload, partNumber, part);

        uploadedParts.add(uploaded);
    }

    multipart.validateThatThereAreSequentialPartNumbers(upload);
    Instant start = Instant.now();
    multipart.complete(upload, uploadedParts);

    multipart.getWrapped().waitForCompletion(upload, (Function<UUID, Void>) uuid -> {
        fail("Completion operation didn't succeed within timeout");
        return null;
    });
    Instant end = Instant.now();

    MantaMultipartStatus status = multipart.getStatus(upload);

    assertEquals(status, MantaMultipartStatus.COMPLETED);

    assertEquals(mantaClient.getAsString(path), combined.toString(),
            "Manta combined string doesn't match expectation: " + multipart.getWrapped().findJob(upload));

    Duration totalCompletionTime = Duration.between(start, end);

    LOG.info("Concatenating {} parts took {} seconds", parts.length, totalCompletionTime.toMillis() / 1000);
}

From source file:com.joyent.manta.client.multipart.EncryptedJobsMultipartManagerIT.java

private void canUploadMultipartBinary(final long sizeInMb, final int noOfParts) throws IOException {
    final long size = sizeInMb * 1024L * 1024L;

    File[] parts = new File[noOfParts];

    for (int i = 0; i < noOfParts; i++) {
        parts[i] = createTemporaryDataFile(size, 1);
    }/*from ww w  . ja v a  2 s.  c  om*/

    final File expectedFile = concatenateFiles(parts);
    final byte[] expectedMd5 = md5(expectedFile);

    final String name = uploadName("can-upload-5mb-multipart-binary");
    final String path = testPathPrefix + name;

    final EncryptedMultipartUpload<JobsMultipartUpload> upload = multipart.initiateUpload(path);

    final ArrayList<MantaMultipartUploadTuple> uploadedParts = new ArrayList<>();

    for (int i = 0; i < parts.length; i++) {
        File part = parts[i];
        int partNumber = i + 1;
        MantaMultipartUploadTuple uploaded = multipart.uploadPart(upload, partNumber, part);
        uploadedParts.add(uploaded);
    }

    multipart.validateThatThereAreSequentialPartNumbers(upload);
    Instant start = Instant.now();
    multipart.complete(upload, uploadedParts.stream());
    multipart.getWrapped().waitForCompletion(upload, (Function<UUID, Void>) uuid -> {
        fail("Completion operation didn't succeed within timeout");
        return null;
    });
    Instant end = Instant.now();

    MantaMultipartStatus status = multipart.getStatus(upload);
    assertEquals(status, MantaMultipartStatus.COMPLETED);

    // If we are using encryption the remote md5 is the md5 of the
    // cipher text.  To prove we uploaded the right bytes and can
    // get them back again, we need to download and calculate.

    final byte[] remoteMd5;
    try (MantaObjectInputStream gotObject = mantaClient.getAsInputStream(path)) {
        remoteMd5 = DigestUtils.md5(gotObject);
    }

    if (!Arrays.equals(remoteMd5, expectedMd5)) {
        StringBuilder builder = new StringBuilder();
        builder.append("MD5 values do not match - job id: ").append(multipart.getWrapped().findJob(upload));
        fail(builder.toString());
    }

    Duration totalCompletionTime = Duration.between(start, end);

    LOG.info("Concatenating {} parts took {} seconds", parts.length, totalCompletionTime.toMillis() / 1000);
}

From source file:azkaban.executor.ExecutionFlowDao.java

List<ExecutableFlow> fetchRecentlyFinishedFlows(final Duration maxAge) throws ExecutorManagerException {
    try {/*from   w w  w.  j  a  v  a2s .  c  o m*/
        return this.dbOperator.query(FetchRecentlyFinishedFlows.FETCH_RECENTLY_FINISHED_FLOW,
                new FetchRecentlyFinishedFlows(), System.currentTimeMillis() - maxAge.toMillis(),
                Status.SUCCEEDED.getNumVal(), Status.KILLED.getNumVal(), Status.FAILED.getNumVal());
    } catch (final SQLException e) {
        throw new ExecutorManagerException("Error fetching recently finished flows", e);
    }
}

From source file:com.publictransitanalytics.scoregenerator.output.TimeQualifiedPointAccessibility.java

public TimeQualifiedPointAccessibility(final PathScoreCard scoreCard, final Grid grid, final Center center,
        final LocalDateTime time, final Duration tripDuration, final boolean backward,
        final Duration inServiceTime) throws InterruptedException {
    type = AccessibilityType.TIME_QUALIFIED_POINT_ACCESSIBILITY;
    direction = backward ? Direction.INBOUND : Direction.OUTBOUND;
    mapBounds = new Bounds(grid.getBounds());
    this.center = new Point(center.getLogicalCenter().getPointRepresentation());
    this.time = time.format(DateTimeFormatter.ofPattern("YYYY-MM-dd HH:mm:ss"));

    this.tripDuration = DurationFormatUtils.formatDurationWords(tripDuration.toMillis(), true, true);
    final ImmutableMap.Builder<Bounds, FullSectorReachInformation> builder = ImmutableMap.builder();

    final TaskIdentifier task = new TaskIdentifier(time, center);

    final Set<Sector> sectors = grid.getAllSectors();
    for (final Sector sector : sectors) {
        final MovementPath sectorPath = scoreCard.getBestPath(sector, task);
        if (sectorPath != null) {
            final Bounds sectorBounds = new Bounds(sector);

            builder.put(sectorBounds, new FullSectorReachInformation(sectorPath));
        }// w w  w . j  av  a2  s . c  o m
    }
    sectorPaths = builder.build();
    totalSectors = grid.getReachableSectors().size();
    inServiceSeconds = inServiceTime.getSeconds();
}