Example usage for java.time Instant now

List of usage examples for java.time Instant now

Introduction

In this page you can find the example usage for java.time Instant now.

Prototype

public static Instant now() 

Source Link

Document

Obtains the current instant from the system clock.

Usage

From source file:com.vmware.photon.controller.api.client.resource.TasksRestApiTest.java

@Test
public void testGetTaskAsync() throws Throwable {
    final Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_OK);
    TasksApi tasksApi = new TasksRestApi(this.restClient);

    tasksApi.getTaskAsync("foo", new FutureCallback<Task>() {
        @Override/*from  w  ww.j a v  a  2 s .co m*/
        public void onSuccess(@Nullable Task task) {
            assertEquals(task, responseTask);
        }

        @Override
        public void onFailure(Throwable t) {
            fail(t.toString());
        }
    });
}

From source file:io.dropwizard.primer.PerimerAuthorizationsTest.java

@Test
public void testAuthorizedCall() throws PrimerException, JsonProcessingException, ExecutionException {
    stubFor(post(urlEqualTo("/v1/verify/test/test"))
            .willReturn(/*w  w w  .  ja va 2s . c  o m*/
                    aResponse().withStatus(200).withHeader("Content-Type", "application/json")
                            .withBody(mapper.writeValueAsBytes(VerifyResponse.builder()
                                    .expiresAt(Instant.now().plusSeconds(10000).toEpochMilli()).token(token)
                                    .userId("test").build()))));
    assertNotNull(PrimerAuthorizationRegistry.authorize("simple/auth/test", "GET", token));
}

From source file:org.eclipse.hono.service.cache.SpringBasedExpiringValueCache.java

@Override
public void put(final K key, final V value, final Duration maxAge) {

    Objects.requireNonNull(key);/* w w  w  . j  av  a2 s . co m*/
    Objects.requireNonNull(value);
    Objects.requireNonNull(maxAge);

    put(key, value, Instant.now().plus(maxAge));
}

From source file:com.vmware.photon.controller.api.client.resource.FlavorApiTest.java

@Test
public void testCreate() throws IOException {
    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    FlavorApi flavorApi = new FlavorApi(restClient);

    Task task = flavorApi.create(new FlavorCreateSpec());
    assertEquals(task, responseTask);//from   w  w w .j  av a 2s . c  o  m
}

From source file:org.lendingclub.mercator.newrelic.NewRelicScanner.java

/**
 * Scans all the APM's in NewRelic and establishes relationship to servers
 * that are hosting them. In this way we know what all servers are hosting 
 * a particular application.// w  w  w.j  a  v a  2  s .com
 * 
 */
private void scanApms() {
    Instant startTime = Instant.now();

    ObjectNode apps = getNewRelicClient().getApplications();
    Preconditions.checkNotNull(getProjector().getNeoRxClient(), "neorx client must be set");

    String cypher = "WITH {json} as data " + "UNWIND data.applications as app "
            + "MERGE (a:NewRelicApplication { nr_appId: toString(app.id), nr_accountId: {accountId}} ) "
            + "ON CREATE SET a.appName = app.name, a.lastReportedAt = app.last_reported_at, a.createTs = timestamp(), a.healthStatus = app.health_status, "
            + "a.reporting = app.reporting, a.language = app.language, a.updateTs = timestamp() "
            + "ON MATCH SET a.lastReportedAt = app.last_reported_at, a.reporting = app.reporting, a.healthStatus = app.health_status, a.updateTs = timestamp() "
            + "FOREACH ( sid IN app.links.servers | MERGE (s:NewRelicServer { nr_serverId: toString(sid), nr_accountId:{accountId} }) MERGE (a)-[:HOSTED_ON]->(s))";

    getProjector().getNeoRxClient().execCypher(cypher, "json", apps, "accountId",
            clientSupplier.get().getAccountId());

    Instant endTime = Instant.now();

    logger.info("Updating neo4j with the latest information about {} NewRelic Applications took {} secs",
            apps.get("applications").size(), Duration.between(startTime, endTime).getSeconds());

}

From source file:com.vmware.photon.controller.api.client.resource.FlavorRestApiTest.java

@Test
public void testCreate() throws IOException {
    Task responseTask = new Task();
    responseTask.setId("12345");
    responseTask.setState("QUEUED");
    responseTask.setQueuedTime(Date.from(Instant.now()));

    ObjectMapper mapper = new ObjectMapper();
    String serializedTask = mapper.writeValueAsString(responseTask);

    setupMocks(serializedTask, HttpStatus.SC_CREATED);

    FlavorApi flavorApi = new FlavorRestApi(restClient);

    Task task = flavorApi.create(new FlavorCreateSpec());
    assertEquals(task, responseTask);//w w  w  .  j  a va 2  s  .c  o m
}

From source file:oauth2.entities.User.java

public boolean isPasswordExpired() {
    return passwordExpiresAt == null || !passwordExpiresAt.isAfter(Instant.now());
}

From source file:io.cfp.auth.service.TokenService.java

/**
  * Check if token is valid/*from   w ww. ja  v  a2 s . c om*/
  * @param token
  * @return
  */
public boolean isValid(String token) {
    try {
        java.util.Date expiration = Jwts.parser().setSigningKey(signingKey).parseClaimsJws(token).getBody()
                .getExpiration();
        if (expiration == null)
            return false;

        return expiration.toInstant().isAfter(Instant.now());
    } catch (ExpiredJwtException | UnsupportedJwtException | SignatureException | MalformedJwtException
            | IllegalArgumentException e) {
        return false;
    }
}

From source file:com.coinblesk.server.controller.VersionController.java

@RequestMapping(value = "", method = POST, consumes = APPLICATION_JSON_UTF8_VALUE, produces = APPLICATION_JSON_UTF8_VALUE)
@ResponseBody//  w  ww.ja  v a  2 s  . co m
public VersionTO version(@RequestBody VersionTO input) {
    final String tag = "{version}";
    final Instant startTime = Instant.now();

    try {
        final String serverVersion = getServerVersion();
        final BitcoinNet serverNetwork = appConfig.getBitcoinNet();
        final String clientVersion = input.clientVersion();
        final BitcoinNet clientNetwork = input.bitcoinNet();

        if (clientVersion == null || clientVersion.isEmpty() || clientNetwork == null) {
            return new VersionTO().type(Type.INPUT_MISMATCH);
        }

        final boolean isSupported = isVersionSupported(clientVersion) && isNetworkSupported(clientNetwork);
        LOG.debug("{} - serverVersion={}, serverNetwork={}, clientVersion={}, clientNetwork={}, isSupported={}",
                tag, serverVersion, serverNetwork, clientVersion, clientNetwork, isSupported);

        return new VersionTO().bitcoinNet(serverNetwork).setSupported(isSupported).setSuccess();
    } catch (Exception e) {
        LOG.error("{} - failed with exception: ", tag, e);
        return new VersionTO().type(Type.SERVER_ERROR).message(e.getMessage());
    } finally {
        LOG.debug("{} - finished in {} ms", tag, Duration.between(startTime, Instant.now()).toMillis());
    }
}

From source file:io.pivotal.strepsirrhini.chaosloris.data.EventRepositoryTest.java

@Test
public void findByChaos() {
    Schedule schedule = new Schedule("test-schedule", "test-name");
    this.scheduleRepository.saveAndFlush(schedule);

    Application application1 = new Application(UUID.randomUUID());
    this.applicationRepository.saveAndFlush(application1);

    Chaos chaos1 = new Chaos(application1, 0.1, schedule);
    this.chaosRepository.saveAndFlush(chaos1);

    Event event1 = new Event(chaos1, Instant.now(), Collections.emptyList(), Integer.MIN_VALUE);
    this.eventRepository.saveAndFlush(event1);

    Application application2 = new Application(UUID.randomUUID());
    this.applicationRepository.saveAndFlush(application2);

    Chaos chaos2 = new Chaos(application2, 0.1, schedule);
    this.chaosRepository.saveAndFlush(chaos2);

    Event event2 = new Event(chaos2, Instant.now(), Collections.emptyList(), Integer.MIN_VALUE);
    this.eventRepository.saveAndFlush(event2);

    List<Event> events = this.eventRepository.findByChaos(chaos1);
    assertThat(events).containsExactly(event1);
}