List of usage examples for java.time Instant now
public static Instant now()
From source file:com.buffalokiwi.api.APIDate.java
/** * Create a new APIDate set to now. * This will use the local system offset */ public APIDate() { this(Instant.now().atZone(ZoneId.systemDefault())); }
From source file:com.google.maps.DistanceMatrixApiTest.java
@Test public void testNewRequestWithAllPossibleParams() throws Exception { try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) { String[] origins = new String[] { "Perth, Australia", "Sydney, Australia", "Melbourne, Australia", "Adelaide, Australia", "Brisbane, Australia", "Darwin, Australia", "Hobart, Australia", "Canberra, Australia" }; String[] destinations = new String[] { "Uluru, Australia", "Kakadu, Australia", "Blue Mountains, Australia", "Bungle Bungles, Australia", "The Pinnacles, Australia" }; DistanceMatrixApi.newRequest(sc.context).origins(origins).destinations(destinations) .mode(TravelMode.DRIVING).language("en-AU").avoid(RouteRestriction.TOLLS).units(Unit.IMPERIAL) .departureTime(Instant.now().plus(Duration.ofMinutes(2))) // this is ignored when an API key is used .await();//from w w w .j a v a 2s . co m sc.assertParamValue(StringUtils.join(origins, "|"), "origins"); sc.assertParamValue(StringUtils.join(destinations, "|"), "destinations"); sc.assertParamValue(TravelMode.DRIVING.toUrlValue(), "mode"); sc.assertParamValue("en-AU", "language"); sc.assertParamValue(RouteRestriction.TOLLS.toUrlValue(), "avoid"); sc.assertParamValue(Unit.IMPERIAL.toUrlValue(), "units"); } }
From source file:org.elasticsearch.plugin.readonlyrest.utils.containers.ESWithReadonlyRestContainer.java
private WaitStrategy waitStrategy(ESInitalizer initalizer) { final ObjectMapper mapper = new ObjectMapper(); return new GenericContainer.AbstractWaitStrategy() { @Override//w w w. j a v a 2s . co m protected void waitUntilReady() { logger.info("Waiting for ES container ..."); final RestClient client = getAdminClient(); final Instant startTime = Instant.now(); while (!isReady(client) && !checkTimeout(startTime, startupTimeout)) { try { Thread.sleep(WAIT_BETWEEN_RETRIES.toMillis()); } catch (InterruptedException e) { e.printStackTrace(); } } initalizer.initialize(getAdminClient()); logger.info("ES container stated"); } private boolean isReady(RestClient client) { try { Response result = client.performRequest("GET", "_cluster/health"); if (result.getStatusLine().getStatusCode() != 200) return false; Map<String, String> healthJson = mapper.readValue(result.getEntity().getContent(), new TypeReference<Map<String, String>>() { }); return "green".equals(healthJson.get("status")); } catch (IOException e) { return false; } } }; }
From source file:org.noorganization.instalist.server.api.TagResourceTest.java
@Test public void testGetTags() throws Exception { String url = "/groups/%d/tags"; Response notAuthorizedResponse = target(String.format(url, mGroup.getId())).request().get(); assertEquals(401, notAuthorizedResponse.getStatus()); Response wrongAuthResponse = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token wrongauth").get(); assertEquals(401, wrongAuthResponse.getStatus()); Response wrongGroupResponse = target(String.format(url, mNAGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get(); assertEquals(401, wrongGroupResponse.getStatus()); Response okResponse1 = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get(); assertEquals(200, okResponse1.getStatus()); TagInfo[] allTagInfo = okResponse1.readEntity(TagInfo[].class); assertEquals(2, allTagInfo.length);/*from www .j ava 2 s . c om*/ for (TagInfo current : allTagInfo) { if (mTag.getUUID().equals(UUID.fromString(current.getUUID()))) { assertEquals("tag1", current.getName()); assertEquals(mTag.getUpdated(), current.getLastChanged().toInstant()); assertFalse(current.getDeleted()); } else if (mDeletedTag.getUUID().equals(UUID.fromString(current.getUUID()))) { assertNull(current.getName()); assertEquals(mDeletedTag.getUpdated(), current.getLastChanged().toInstant()); assertTrue(current.getDeleted()); } else fail("Unexpected tag."); } Thread.sleep(200); mManager.getTransaction().begin(); mTag.setUpdated(Instant.now()); mManager.getTransaction().commit(); Response okResponse2 = target(String.format(url, mGroup.getId())) .queryParam("changedsince", ISO8601Utils.format(new Date(System.currentTimeMillis() - 100), true)) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get(); assertEquals(200, okResponse2.getStatus()); TagInfo[] oneTagInfo = okResponse2.readEntity(TagInfo[].class); assertEquals(1, oneTagInfo.length); assertEquals(mTag.getUUID(), UUID.fromString(oneTagInfo[0].getUUID())); assertEquals("tag1", oneTagInfo[0].getName()); assertFalse(oneTagInfo[0].getDeleted()); }
From source file:de.siegmar.securetransfer.controller.SendController.java
/** * Process the send form./* w w w .j av a 2s .co m*/ */ @PostMapping public ModelAndView create(final HttpServletRequest req, final RedirectAttributes redirectAttributes) throws IOException, FileUploadException { if (!ServletFileUpload.isMultipartContent(req)) { throw new IllegalStateException("No multipart request!"); } // Create encryptionKey and initialization vector (IV) to encrypt data final KeyIv encryptionKey = messageService.newEncryptionKey(); // secret shared with receiver using the link - not stored in database final String linkSecret = messageService.newRandomId(); final DataBinder binder = initBinder(); final List<SecretFile> tmpFiles = handleStream(req, encryptionKey, binder); final EncryptMessageCommand command = (EncryptMessageCommand) binder.getTarget(); final BindingResult errors = binder.getBindingResult(); if (!errors.hasErrors() && command.getMessage() == null && (tmpFiles == null || tmpFiles.isEmpty())) { errors.reject(null, "Neither message nor files submitted"); } if (errors.hasErrors()) { return new ModelAndView(FORM_SEND_MSG, binder.getBindingResult().getModel()); } final String senderId = messageService.storeMessage(command.getMessage(), tmpFiles, encryptionKey, HashCode.fromString(linkSecret).asBytes(), command.getPassword(), Instant.now().plus(command.getExpirationDays(), ChronoUnit.DAYS)); redirectAttributes.addFlashAttribute("messageSent", true).addFlashAttribute("message", command.getMessage()); return new ModelAndView("redirect:/send/" + senderId).addObject("linkSecret", linkSecret); }
From source file:com.orange.cepheus.broker.persistence.SubscriptionsRepositoryTest.java
@Test public void removeSubscriptionTest() throws URISyntaxException, SubscriptionPersistenceException { SubscribeContext subscribeContext = createSubscribeContextTemperature(); Subscription subscription = new Subscription("12345", Instant.now().plus(1, ChronoUnit.DAYS), subscribeContext);//w ww .ja v a2 s . c om subscriptionsRepository.saveSubscription(subscription); Assert.assertEquals(1, subscriptionsRepository.getAllSubscriptions().size()); subscriptionsRepository.removeSubscription("12345"); Assert.assertEquals(0, subscriptionsRepository.getAllSubscriptions().size()); }
From source file:com.vmware.photon.controller.api.client.resource.ClusterApiTest.java
@Test public void testResizeAsync() 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); ClusterApi clusterApi = new ClusterApi(restClient); final CountDownLatch latch = new CountDownLatch(1); clusterApi.resizeAsync("dummy-cluster-id", 100, new FutureCallback<Task>() { @Override/* w w w . j a v a 2 s . c o m*/ public void onSuccess(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:co.runrightfast.vertx.core.eventbus.ProtobufMessageProducer.java
public static DeliveryOptions addRunRightFastHeaders(final DeliveryOptions options) { final MultiMap headers = options.getHeaders(); if (headers == null) { options.addHeader(MESSAGE_ID.header, uuid()); options.addHeader(MESSAGE_TIMESTAMP.header, DateTimeFormatter.ISO_INSTANT.format(Instant.now())); return options; }//from ww w .j av a 2 s . co m if (!headers.contains(MESSAGE_ID.header)) { headers.add(MESSAGE_ID.header, uuid()); } if (!headers.contains(MESSAGE_TIMESTAMP.header)) { headers.add(MESSAGE_TIMESTAMP.header, DateTimeFormatter.ISO_INSTANT.format(Instant.now())); } return options; }
From source file:com.vmware.photon.controller.api.client.resource.ClusterRestApiTest.java
@Test public void testResizeAsync() 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); ClusterApi clusterApi = new ClusterRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); clusterApi.resizeAsync("dummy-cluster-id", 100, new FutureCallback<Task>() { @Override//from w w w. j a v a2 s .c o m public void onSuccess(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:org.noorganization.instalist.server.api.UnitResourceTest.java
@Test public void testGetUnits() throws Exception { String url = "/groups/%d/units"; Response notAuthorizedResponse = target(String.format(url, mGroup.getId())).request().get(); assertEquals(401, notAuthorizedResponse.getStatus()); Response wrongAuthResponse = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token wrongauth").get(); assertEquals(401, wrongAuthResponse.getStatus()); Response wrongGroupResponse = target(String.format(url, mNAGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get(); assertEquals(401, wrongGroupResponse.getStatus()); Response okResponse1 = target(String.format(url, mGroup.getId())).request() .header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get(); assertEquals(200, okResponse1.getStatus()); UnitInfo[] allUnitInfo = okResponse1.readEntity(UnitInfo[].class); assertEquals(2, allUnitInfo.length); for (UnitInfo current : allUnitInfo) { if (mUnit.getUUID().equals(UUID.fromString(current.getUUID()))) { assertEquals("unit1", current.getName()); assertEquals(mUnit.getUpdated(), current.getLastChanged().toInstant()); assertFalse(current.getDeleted()); } else if (mDeletedUnit.getUUID().equals(UUID.fromString(current.getUUID()))) { assertNull(current.getName()); assertEquals(mDeletedUnit.getUpdated(), current.getLastChanged().toInstant()); assertTrue(current.getDeleted()); } else//from w ww .j a v a2 s .c o m fail("Unexpected unit."); } Thread.sleep(1000); mManager.getTransaction().begin(); mUnit.setUpdated(Instant.now()); mManager.getTransaction().commit(); Response okResponse2 = target(String.format(url, mGroup.getId())) .queryParam("changedsince", ISO8601Utils.format(new Date(System.currentTimeMillis() - 500), true)) .request().header(HttpHeaders.AUTHORIZATION, "X-Token " + mToken).get(); assertEquals(200, okResponse2.getStatus()); UnitInfo[] oneUnitInfo = okResponse2.readEntity(UnitInfo[].class); assertEquals(1, oneUnitInfo.length); assertEquals(mUnit.getUUID(), UUID.fromString(oneUnitInfo[0].getUUID())); assertEquals("unit1", oneUnitInfo[0].getName()); assertFalse(oneUnitInfo[0].getDeleted()); }