List of usage examples for java.time Instant now
public static Instant now()
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testPerformRestartOperation() 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 VmRestApi(restClient); Task task = vmApi.performRestartOperation("foo"); assertEquals(task, responseTask);/*from w w w .j a v a2s . c om*/ }
From source file:ai.grakn.engine.controller.TasksControllerTest.java
@Test public void whenGettingTaskByIdDelayed_TaskIdReturned() { Instant runAt = Instant.now().plusMillis(10); TaskState task = createTask(ShortExecutionMockTask.class, TaskSchedule.at(runAt)); when(manager.storage().getState(task.getId())).thenReturn(task); Response response = get(task.getId()); Json json = response.as(Json.class, jsonMapper); assertThat(json.at("id").asString(), equalTo(task.getId().getValue())); assertThat(json.at(TASK_RUN_AT_PARAMETER).asLong(), equalTo(runAt.toEpochMilli())); }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testPerformRestartOperationAsync() 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); VmApi vmApi = new VmApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.performRestartOperationAsync("foo", new FutureCallback<Task>() { @Override//from w ww . j a va2s. 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.VmRestApiTest.java
@Test public void testPerformRestartOperationAsync() 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); VmApi vmApi = new VmRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.performRestartOperationAsync("foo", new FutureCallback<Task>() { @Override//www .j a v a 2 s .c o 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:keywhiz.service.resources.admin.SecretsResource.java
/** * Rollback to a previous secret version * * @param secretName the name of the secret to rollback * @param versionId the ID of the version to return to * @excludeParams user/*from w w w . j a v a 2 s . c om*/ * @description Returns the previous versions of the secret if found Used by Keywhiz CLI. * @responseMessage 200 Found and reset the secret to this version * @responseMessage 404 Secret with given name not found or invalid version provided */ @Path("rollback/{secretName}/{versionId}") @Timed @ExceptionMetered @POST public Response resetSecretVersion(@Auth User user, @PathParam("secretName") String secretName, @PathParam("versionId") LongParam versionId) { logger.info("User '{}' rolling back secret '{}' to version with ID '{}'.", user, secretName, versionId); secretDAOReadWrite.setCurrentSecretVersionByName(secretName, versionId.get()); // If the secret wasn't found or the request was misformed, setCurrentSecretVersionByName // already threw an exception Map<String, String> extraInfo = new HashMap<>(); extraInfo.put("new version", versionId.toString()); auditLog.recordEvent( new Event(Instant.now(), EventTag.SECRET_CHANGEVERSION, user.getName(), secretName, extraInfo)); // Send the new secret in response URI uri = UriBuilder.fromResource(SecretsResource.class).path("rollback/{secretName}/{versionID}") .build(secretName, versionId); return Response.created(uri).entity(secretDetailResponseFromName(secretName)).build(); }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testPerformResumeOperation() 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); Task task = vmApi.performResumeOperation("foo"); assertEquals(task, responseTask);/*w ww . jav a2s .c o m*/ }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testPerformResumeOperation() 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 VmRestApi(restClient); Task task = vmApi.performResumeOperation("foo"); assertEquals(task, responseTask);/*from ww w . j a v a 2 s.com*/ }
From source file:com.amazonaws.sample.entitlement.services.AdministrationService.java
/** * Add subscription/*from w w w . j ava2 s . com*/ * @throws ApplicationBadStateException if the application the current request is for is in an error state * @return prettified string of JSON */ public String addUserSubscription(String subscription) throws ApplicationBadStateException { try { Item subscriptionItem = Item.fromJSON(subscription); // lookup user item by GSI query on user table (table must only contain one result) ItemCollection<QueryOutcome> responses = entitlementServiceUserTable.getIndex("emailGSI").query("email", subscriptionItem.getString("Email")); Iterator<Item> iter = responses.iterator(); Item user = iter.next(); // add and remove attributes to create valid subscription subscriptionItem.withString("UserApplicationId", subscriptionItem.getString("id")).removeAttribute("id") .withPrimaryKey("UserId", user.getString("id"), "CreationTimeMilli", Instant.now().toEpochMilli()); // save new subscription entitlementServiceUserSubscriptionTable.putItem(subscriptionItem).getItem(); return subscriptionItem.toJSONPretty(); } catch (AmazonServiceException e) { if (e.getErrorType().equals(AmazonServiceException.ErrorType.Service)) { log.error("An error occurred while getting data from DynamoDB: " + e); } throw e; } }
From source file:net.beaconpe.jraklib.server.Session.java
public void handlePacket(Packet packet) throws IOException { isActive = true;//from w ww. ja v a2 s . com lastUpdate = Instant.now().toEpochMilli(); if (state == STATE_CONNECTED || state == STATE_CONNECTING_2) { if (packet.buffer[0] >= 0x80 || packet.buffer[0] <= 0x8f && packet instanceof DataPacket) { packet.decode(); DataPacket dp = (DataPacket) packet; if (dp.seqNumber < windowStart || dp.seqNumber > windowEnd || receivedWindow.containsKey(dp.seqNumber)) { return; } int diff = dp.seqNumber - lastSeqNumber; NACKQueue.remove(Integer.valueOf(dp.seqNumber)); ACKQueue.add(dp.seqNumber); receivedWindow.put(dp.seqNumber, dp.seqNumber); if (diff != 1) { for (int i = lastSeqNumber + 1; i < dp.seqNumber; i++) { if (!receivedWindow.containsKey(i)) { NACKQueue.add(i); } } } if (diff >= 1) { lastSeqNumber = dp.seqNumber; windowStart += diff; windowEnd += diff; } for (Object pk : dp.packets) { if (pk instanceof EncapsulatedPacket) { handleEncapsulatedPacket((EncapsulatedPacket) pk); } } } else { if (packet instanceof ACK) { packet.decode(); for (int seq : ((ACK) packet).packets) { if (recoveryQueue.containsKey(seq)) { for (Object pk : recoveryQueue.get(seq).packets) { if (pk instanceof EncapsulatedPacket && ((EncapsulatedPacket) pk).needACK && ((EncapsulatedPacket) pk).messageIndex != -1) { if (needACK.containsKey(((EncapsulatedPacket) pk).identifierACK)) { Map<Integer, Integer> map = needACK .get(((EncapsulatedPacket) pk).identifierACK); map.remove(((EncapsulatedPacket) pk).messageIndex); needACK.put(((EncapsulatedPacket) pk).identifierACK, map); } } recoveryQueue.remove(seq); } } } } else if (packet instanceof NACK) { packet.decode(); for (Integer seq : ((NACK) packet).packets) { if (recoveryQueue.containsKey(seq)) { DataPacket pk = recoveryQueue.get(seq); pk.seqNumber = sendSeqNumber++; packetToSend.add(pk); recoveryQueue.remove(seq); } } } } } else if (packet.buffer[0] > 0x00 || packet.buffer[0] < 0x80) { //Not Data packet :) packet.decode(); if (packet instanceof UNCONNECTED_PING) { UNCONNECTED_PONG pk = new UNCONNECTED_PONG(); pk.serverID = sessionManager.getID(); pk.pingID = ((UNCONNECTED_PING) packet).pingId; pk.serverName = sessionManager.getName(); pk.encode(); sendPacket(pk); } else if (packet instanceof OPEN_CONNECTION_REQUEST_1) { //((OPEN_CONNECTION_REQUEST_1) packet).protocol; //TODO: check protocol number and refuse connections OPEN_CONNECTION_REPLY_1 pk = new OPEN_CONNECTION_REPLY_1(); pk.mtuSize = ((OPEN_CONNECTION_REQUEST_1) packet).mtuSize; pk.serverID = sessionManager.getID(); pk.encode(); sendPacket(pk); state = STATE_CONNECTING_1; } else if (state == STATE_CONNECTING_1 && packet instanceof OPEN_CONNECTION_REQUEST_2) { id = ((OPEN_CONNECTION_REQUEST_2) packet).clientID; if (((OPEN_CONNECTION_REQUEST_2) packet).serverAddress.getPort() == sessionManager.getPort() || !sessionManager.portChecking) { mtuSize = Math.min(Math.abs(((OPEN_CONNECTION_REQUEST_2) packet).mtuSize), 1464); //Max size, do not allow creating large buffers to fill server memory OPEN_CONNECTION_REPLY_2 pk = new OPEN_CONNECTION_REPLY_2(); pk.mtuSize = (short) mtuSize; pk.serverID = sessionManager.getID(); pk.clientAddress = new InetSocketAddress(address, port); pk.encode(); sendPacket(pk); state = STATE_CONNECTING_2; } } } }
From source file:ws.salient.session.Session.java
public boolean expired(Instant instant) { Instant minsAgo = Instant.now().minus(15, ChronoUnit.MINUTES); return (instant != null && instant.isBefore(minsAgo)); }