Java Code Examples for java.time.Duration#toSeconds()

The following examples show how to use java.time.Duration#toSeconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationContentRepositoryIT.java    From blackduck-alert with Apache License 2.0 5 votes vote down vote up
public void notificationQueryTest(BiFunction<String, Pageable, Page<NotificationEntity>> queryFunction) throws ParseException, AlertException {
    final String searchTerm = "searchTerm";
    final int numberToCreate = 1000;
    Number numberOfSearchTermMatches = initializeNotificationRepo(searchTerm, numberToCreate);

    Instant beforeQueryInstant = Instant.now();
    Page<NotificationEntity> matchingNotifications = queryFunction.apply(searchTerm, Pageable.unpaged());
    Instant afterQueryInstant = Instant.now();

    Duration queryDuration = Duration.between(beforeQueryInstant, afterQueryInstant);
    Long durationInSeconds = queryDuration.toSeconds();
    System.out.println("Duration (in seconds): " + durationInSeconds);

    assertEquals(numberOfSearchTermMatches, matchingNotifications.getTotalElements());
}
 
Example 2
Source File: EndpointCertificateManager.java    From vespa with Apache License 2.0 5 votes vote down vote up
public Optional<EndpointCertificateMetadata> getEndpointCertificateMetadata(Instance instance, ZoneId zone, Optional<DeploymentInstanceSpec> instanceSpec) {
    var t0 = Instant.now();
    Optional<EndpointCertificateMetadata> metadata = getOrProvision(instance, zone, instanceSpec);
    Duration duration = Duration.between(t0, Instant.now());
    if (duration.toSeconds() > 30) log.log(Level.INFO, String.format("Getting endpoint certificate metadata for %s took %d seconds!", instance.id().serializedForm(), duration.toSeconds()));
    return metadata;
}
 
Example 3
Source File: CredentialsServiceImpl.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private static CacheDirective toCacheDirective(final Duration ttl) {

        final long seconds = ttl.toSeconds();

        final CacheDirective cacheDirective;
        if (seconds > 0) {
            cacheDirective = maxAgeDirective(seconds);
        } else {
            cacheDirective = noCacheDirective();
        }

        return cacheDirective;

    }
 
Example 4
Source File: DeviceServiceProperties.java    From enmasse with Apache License 2.0 4 votes vote down vote up
public void setCredentialsTtl(final Duration credentialsTtl) {
    if (credentialsTtl.toSeconds() <= 0) {
        throw new IllegalArgumentException("'credentialsTtl' must be a positive duration of at least one second");
    }
    this.credentialsTtl = credentialsTtl;
}
 
Example 5
Source File: DeviceServiceProperties.java    From enmasse with Apache License 2.0 4 votes vote down vote up
public void setRegistrationTtl(final Duration registrationTtl) {
    if (registrationTtl.toSeconds() <= 0) {
        throw new IllegalArgumentException("'registrationTtl' must be a positive duration of at least one second");
    }
    this.registrationTtl = registrationTtl;
}
 
Example 6
Source File: DeviceServiceProperties.java    From enmasse with Apache License 2.0 4 votes vote down vote up
public void setCredentialsTtl(final Duration credentialsTtl) {
    if ( credentialsTtl.toSeconds() <= 0 ) {
        throw new IllegalArgumentException("'credentialsTtl' must be a positive duration of at least one second");
    }
    this.credentialsTtl = credentialsTtl;
}