List of usage examples for java.time Instant now
public static Instant now()
From source file:ch.digitalfondue.npjt.query.DateTimeQueriesTest.java
@Test public void dateQueriesTest() { QueryFactory qf = new QueryFactory("hsqldb", new JdbcTemplate(dataSource)); qf.addColumnMapperFactory(new ZonedDateTimeMapper.Factory()); qf.addParameterConverters(new ZonedDateTimeMapper.Converter()); qf.addColumnMapperFactory(new LocalDateMapper.Factory()); qf.addParameterConverters(new LocalDateMapper.Converter()); qf.addColumnMapperFactory(new LocalDateTimeMapper.Factory()); qf.addParameterConverters(new LocalDateTimeMapper.Converter()); qf.addColumnMapperFactory(new InstantMapper.Factory()); qf.addParameterConverters(new InstantMapper.Converter()); DateQueries dq = qf.from(DateQueries.class); dq.createTable();//ww w . j ava2 s .com ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")); dq.insertValue("KEY", now); check(dq, "KEY", now); dq.insertValue("KEY2", now.toLocalDate()); check(dq, "KEY2", now.toLocalDate()); dq.insertValue("KEY3", now.toLocalDateTime()); check(dq, "KEY3", now); Instant iNow = Instant.now(); dq.insertValue("KEY4", iNow); Assert.assertEquals(iNow, dq.findInstantByKey("KEY4")); Assert.assertEquals(iNow, dq.findConfInstantByKey("KEY4").value); }
From source file:co.runrightfast.component.events.impl.ComponentEventImpl.java
/** * * @param componentId required//from w w w . j av a 2 s .c o m * @param id optional - new id generated if not supplied * @param eventTimestamp optional - uses now if not specified * @param jvmId optional - uses {@link AppUtils#JVM_ID} if not specified * @param event required * @param data conditionally required based on event * @param exception optional * @param tags optional */ public ComponentEventImpl(@NonNull final ComponentId componentId, final UUID id, final Instant eventTimestamp, final String jvmId, @NonNull final Event<DATA> event, final Optional<DATA> data, final Optional<Throwable> exception, final Optional<Set<String>> tags) { if (event.eventDataType().isPresent()) { checkArgument(data != null && data.isPresent(), "event is expecting data : event=%s", event.name()); checkArgument(TypeUtils.isInstance(data.get(), event.eventDataType().get()), "event data type does not match : event=%s, expected=%s, actual=%s", event.name(), event.eventDataType().get(), data.get().getClass()); } else { checkArgument(data == null || !data.isPresent(), "event is not expecting data : event=%s", event.name()); } this.componentId = componentId; this.id = id != null ? id : UUID.randomUUID(); this.eventTimestamp = eventTimestamp != null ? eventTimestamp : Instant.now(); this.jvmId = StringUtils.isNotBlank(jvmId) ? jvmId : AppUtils.JVM_ID; this.event = event; this.data = data != null ? data : Optional.empty(); this.exception = exception != null ? exception : Optional.empty(); this.tags = tags != null ? tags : Optional.empty(); }
From source file:it.polimi.diceH2020.SPACE4CloudWS.services.PerformanceSolverProxy.java
@Cacheable(value = it.polimi.diceH2020.SPACE4CloudWS.main.Configurator.CACHE_NAME, keyGenerator = it.polimi.diceH2020.SPACE4CloudWS.main.Configurator.SPJ_KEYGENERATOR) public Pair<Optional<Double>, Long> evaluate(@NonNull SolutionPerJob solPerJob) { Instant first = Instant.now(); logger.info("Cache missing. Evaluation with " + performanceSolver.getClass().getSimpleName() + "."); Optional<Double> optionalResult = performanceSolver.evaluate(solPerJob); Instant after = Instant.now(); return new ImmutablePair<>(optionalResult, Duration.between(first, after).toMillis()); }
From source file:com.netflix.genie.web.util.UnixProcessCheckerUnitTests.java
/** * Make sure if the timeout has been exceeded then an exception is thrown indicating the process should be killed. * * @throws GenieTimeoutException on timeout * @throws IOException on any other error *//*from ww w. ja va 2 s . c om*/ @Test(expected = GenieTimeoutException.class) public void canCheckProcessTimeout() throws GenieTimeoutException, IOException { final Instant yesterday = Instant.now().minus(1, ChronoUnit.DAYS); this.processChecker = new UnixProcessChecker(PID, this.executor, yesterday); this.processChecker.checkProcess(); }
From source file:ai.grakn.test.engine.tasks.storage.TaskStateGraphStoreTest.java
@Test public void testUpdateTaskState() { Instant runAt = Instant.now(); Json configuration = Json.object("test key", "test value"); TaskId id = stateStorage.newState(task(at(runAt), configuration)); assertNotNull(id);/*from ww w. j ava2 s . c o m*/ // Get current values TaskState state = stateStorage.getState(id); // Change state.markRunning(engineID); stateStorage.updateState(state); TaskState newState = stateStorage.getState(id); assertEquals(RUNNING, newState.status()); assertEquals(engineID, newState.engineID()); // Change Exception exception = new UnsupportedOperationException("message"); newState.markFailed(exception); stateStorage.updateState(newState); newState = stateStorage.getState(id); assertEquals(exception.getClass().getName(), newState.exception()); assertEquals(getFullStackTrace(exception), newState.stackTrace()); }
From source file:com.orange.cepheus.broker.Subscriptions.java
/** * Add a subscription./*from w ww . j a v a2 s .c o m*/ * @param subscribeContext * @return the subscriptionId * @throws SubscriptionException, SubscriptionPersistenceException */ public String addSubscription(SubscribeContext subscribeContext) throws SubscriptionException, SubscriptionPersistenceException { //if duration is not present, then lb set duration to P1M Duration duration = convertDuration(subscribeContext.getDuration()); if (duration.isNegative()) { throw new SubscriptionException("negative duration is not allowed", new Throwable()); } if (duration.isZero()) { duration = convertDuration("P1M"); } // Compile all entity patterns now to check for conformance (result is cached for later use) try { subscribeContext.getEntityIdList().forEach(patterns::getPattern); } catch (PatternSyntaxException e) { throw new SubscriptionException("bad pattern", e); } // Generate a subscription id String subscriptionId = UUID.randomUUID().toString(); //create subscription and set the expiration date and subscriptionId Subscription subscription = new Subscription(subscriptionId, Instant.now().plus(duration), subscribeContext); //save subscription subscriptionsRepository.saveSubscription(subscription); subscriptions.put(subscriptionId, subscription); return subscriptionId; }
From source file:eu.hansolo.tilesfx.tools.Location.java
public Location(final double LATITUDE, final double LONGITUDE, final String NAME) { this(LATITUDE, LONGITUDE, 0, Instant.now(), NAME, "", TileColor.BLUE); }
From source file:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java
@Test public void testCreateAsync() 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); TenantsApi tenantsApi = new TenantsApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.createAsync("foo", new FutureCallback<Task>() { @Override//from w w w. j a va 2s . c om 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.TenantsRestApiTest.java
@Test public void testCreateAsync() 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); TenantsApi tenantsApi = new TenantsRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.createAsync("foo", new FutureCallback<Task>() { @Override// w ww. j a va 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:org.pdfsam.ui.StatefullPreferencesStageService.java
public void newsStageDisplayed() { Preferences.userRoot().node(STAGE_PATH).putLong(NEWS_STAGE_DISPLAY_TIME_KEY, Instant.now().toEpochMilli()); LOG.trace("Latest news stage display time stored"); }