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.ImagesApiTest.java

@Test
public void testDeleteImage() 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);

    ImagesApi imagesApi = new ImagesApi(this.restClient);

    Task task = imagesApi.delete("foo");
    assertEquals(task, responseTask);//from   w w w  .  j  a va  2  s.c  o m
}

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

@Test
public void testDeleteImage() 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);

    ImagesApi imagesApi = new ImagesRestApi(this.restClient);

    Task task = imagesApi.delete("foo");
    assertEquals(task, responseTask);/* ww w .ja  v  a2 s.c  om*/
}

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

@Test
public void testDeleteAsync() throws IOException, InterruptedException {
    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_CREATED);

    DisksApi disksApi = new DisksApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    disksApi.deleteAsync("persistentDisk", new FutureCallback<Task>() {
        @Override//from   w  w  w .j  a  v a2  s  . co m
        public void onSuccess(@Nullable Task result) {
            assertEquals(result, responseTask);
            latch.countDown();
        }

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

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
    ;
}

From source file:com.netflix.genie.common.dto.JobTest.java

/**
 * Test to make sure can build a valid Job with optional parameters.
 *//*from   w ww  .  j  av  a2 s. c  o m*/
@Test
public void canBuildJobWithOptionals() {
    final Job.Builder builder = new Job.Builder(NAME, USER, VERSION);

    builder.withCommandArgs(COMMAND_ARGS);

    final String archiveLocation = UUID.randomUUID().toString();
    builder.withArchiveLocation(archiveLocation);

    final String clusterName = UUID.randomUUID().toString();
    builder.withClusterName(clusterName);

    final String commandName = UUID.randomUUID().toString();
    builder.withCommandName(commandName);

    final Instant finished = Instant.now();
    builder.withFinished(finished);

    final Instant started = Instant.now();
    builder.withStarted(started);

    builder.withStatus(JobStatus.SUCCEEDED);

    final String statusMsg = UUID.randomUUID().toString();
    builder.withStatusMsg(statusMsg);

    final Instant created = Instant.now();
    builder.withCreated(created);

    final String description = UUID.randomUUID().toString();
    builder.withDescription(description);

    final String id = UUID.randomUUID().toString();
    builder.withId(id);

    final Set<String> tags = Sets.newHashSet(UUID.randomUUID().toString(), UUID.randomUUID().toString(),
            UUID.randomUUID().toString());
    builder.withTags(tags);

    final Instant updated = Instant.now();
    builder.withUpdated(updated);

    final String grouping = UUID.randomUUID().toString();
    builder.withGrouping(grouping);

    final String groupingInstance = UUID.randomUUID().toString();
    builder.withGroupingInstance(groupingInstance);

    final Job job = builder.build();
    Assert.assertThat(job.getName(), Matchers.is(NAME));
    Assert.assertThat(job.getUser(), Matchers.is(USER));
    Assert.assertThat(job.getVersion(), Matchers.is(VERSION));
    Assert.assertThat(job.getCommandArgs().orElseThrow(IllegalArgumentException::new),
            Matchers.is(StringUtils.join(COMMAND_ARGS, StringUtils.SPACE)));
    Assert.assertThat(job.getArchiveLocation().orElseThrow(IllegalArgumentException::new),
            Matchers.is(archiveLocation));
    Assert.assertThat(job.getClusterName().orElseThrow(IllegalArgumentException::new),
            Matchers.is(clusterName));
    Assert.assertThat(job.getCommandName().orElseThrow(IllegalArgumentException::new),
            Matchers.is(commandName));
    Assert.assertThat(job.getFinished().orElseThrow(IllegalArgumentException::new), Matchers.is(finished));
    Assert.assertThat(job.getStarted().orElseThrow(IllegalArgumentException::new), Matchers.is(started));
    Assert.assertThat(job.getStatus(), Matchers.is(JobStatus.SUCCEEDED));
    Assert.assertThat(job.getStatusMsg().orElseThrow(IllegalArgumentException::new), Matchers.is(statusMsg));
    Assert.assertThat(job.getCreated().orElseThrow(IllegalArgumentException::new), Matchers.is(created));
    Assert.assertThat(job.getDescription().orElseThrow(IllegalArgumentException::new),
            Matchers.is(description));
    Assert.assertThat(job.getId().orElseThrow(IllegalArgumentException::new), Matchers.is(id));
    Assert.assertThat(job.getTags(), Matchers.is(tags));
    Assert.assertThat(job.getUpdated().orElseThrow(IllegalArgumentException::new), Matchers.is(updated));
    Assert.assertThat(job.getRuntime(),
            Matchers.is(Duration.ofMillis(finished.toEpochMilli() - started.toEpochMilli())));
    Assert.assertThat(job.getGrouping().orElseThrow(IllegalArgumentException::new), Matchers.is(grouping));
    Assert.assertThat(job.getGroupingInstance().orElseThrow(IllegalArgumentException::new),
            Matchers.is(groupingInstance));
}

From source file:com.derpgroup.echodebugger.resource.EchoDebuggerResource.java

@Path("/users/{userId}")
@GET/*from   w w  w . j a v a  2 s .co m*/
public Map<String, Object> getDefaultResponseByUserId(@PathParam("userId") String userId) {

    User user = (userDao.getUserById(userId) != null) ? userDao.getUserById(userId)
            : userDao.getUserByEchoId(userId);
    if (user == null) {
        EchoDebuggerLogger.logAccessRequest(userId, "SINGLE_RESPONSE", false);
        throw new ResponderException("There is no user with the id of (" + userId + ")",
                ExceptionType.UNRECOGNIZED_ID);
    }
    EchoDebuggerLogger.logAccessRequest(user.getEchoId(), "SINGLE_RESPONSE", true);
    user.setLastWebDownloadTime(Instant.now());
    user.setNumContentDownloads(user.getNumContentDownloads() + 1);

    // Get the response
    Map<String, Object> response = null;
    Map<String, IntentResponses> intentResponses = user.getIntents();
    if (MapUtils.isNotEmpty(intentResponses) && intentResponses.containsKey("GETRESPONSE")) {
        response = intentResponses.get("GETRESPONSE").getData();
    }

    int responseLength = ResponderUtils.getLengthOfContent(response);
    user.setNumCharactersDownloaded(user.getNumCharactersDownloaded() + responseLength);
    userDao.saveUser(user);

    if (response == null) {
        throw new ResponderException("There are no responses stored for user (" + userId + ")",
                ExceptionType.NO_SAVED_RESPONSE);
    }
    return response;
}

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

@Test
public void testPerformOperation() 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);

    VmApi vmApi = new VmApi(restClient);

    VmOperation vmOperation = new VmOperation();
    vmOperation.setOperation(Operation.START_VM.name());

    Task task = vmApi.performOperation("foo", vmOperation);
    assertEquals(task, responseTask);/*  ww  w .j  a v a2  s  . co  m*/
}

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

@Test
public void testDeleteAsync() throws IOException, InterruptedException {
    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_CREATED);

    DisksApi disksApi = new DisksRestApi(restClient);
    final CountDownLatch latch = new CountDownLatch(1);

    disksApi.deleteAsync("persistentDisk", new FutureCallback<Task>() {
        @Override/*from w w  w . j  av a 2s  .  co m*/
        public void onSuccess(@Nullable Task result) {
            assertEquals(result, responseTask);
            latch.countDown();
        }

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

    assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true));
    ;
}

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

private Task getExpectedTaskResponse() throws IOException {
    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_CREATED);
    return responseTask;
}

From source file:net.beaconpe.jraklib.server.Session.java

private void addToQueue(EncapsulatedPacket pk, int flags) throws IOException {
    int priority = flags & 0b0000111;
    if (pk.needACK && pk.messageIndex != -1) {
        Map<Integer, Integer> map;
        if (needACK.get(pk.needACK) != null) {
            map = needACK.get(pk.needACK);
            map.put(pk.messageIndex, pk.messageIndex);
        } else {//from   w w w  .  ja  va2 s  . c  o  m
            map = new ConcurrentHashMap<>();
            map.put(pk.messageIndex, pk.messageIndex);
        }
        needACK.put(pk.identifierACK, map);
    }

    if (priority == JRakLib.PRIORITY_IMMEDIATE) { //Skip queues
        DataPacket packet = new DataPackets.DATA_PACKET_0();
        packet.seqNumber = sendSeqNumber++;
        if (pk.needACK) {
            packet.packets.add(pk);
            pk.needACK = false;
        } else {
            packet.packets.add(pk.toBinary());
        }

        sendPacket(packet);
        packet.sendTime = Instant.now().toEpochMilli();
        recoveryQueue.put(packet.seqNumber, packet);
        return;
    }
    int length = sendQueue.length();
    if (length + pk.getTotalLength() > mtuSize) {
        sendQueue();
    }

    if (pk.needACK) {
        sendQueue.packets.add(pk);
        pk.needACK = false;
    } else {
        sendQueue.packets.add(pk.toBinary());
    }
}

From source file:com.netflix.genie.web.rpc.grpc.services.impl.v4.GRpcAgentFileStreamServiceImpl.java

/**
 * {@inheritDoc}//  ww w .  ja v a2  s  .  co  m
 */
@Override
public StreamObserver<AgentFileMessage> transmit(final StreamObserver<ServerAckMessage> responseObserver) {
    log.info("New file transfer stream established");
    final FileTransferStreamObserver fileTransferStreamObserver = new FileTransferStreamObserver(this,
            responseObserver);

    this.pendingTransferObserversSet.add(fileTransferStreamObserver);

    // Schedule a timeout for this transfer to start (first chunk received)
    this.taskScheduler.schedule(() -> {
        final boolean removed = pendingTransferObserversSet.remove(fileTransferStreamObserver);
        if (removed) {
            fileTransferStreamObserver.responseObserver
                    .onError(new GenieTimeoutException("Timeout waiting for transfer to begin"));
        }
    }, Instant.now().plusMillis(FILE_TRANSFER_BEGIN_TIMEOUT_MILLIS));

    return fileTransferStreamObserver;
}