public InstanceStatusChangedEvent(InstanceId instance, long version, StatusInfo statusInfo) { this(instance, version, Instant.now(), statusInfo); }
public InstanceDeregisteredEvent(InstanceId instance, long version) { this(instance, version, Instant.now()); }
public static ParameterizedType makeClassName(String baseName, Optional<String> suffix) { String className = baseName + "_" + suffix.orElseGet(() -> Instant.now().atZone(UTC).format(TIMESTAMP_FORMAT)) + "_" + CLASS_ID.incrementAndGet(); return typeFromJavaClassName("com.facebook.presto.$gen." + toJavaIdentifierString(className)); }
private void cleanUp() { Instant now = Instant.now(); if (lastCleanup.plus(cleanupInterval).isAfter(now)) { return; } lastCleanup = now; for (Entry<String, NotificationFilter> entry : getNotificationFilters().entrySet()) { if (entry.getValue() instanceof ExpiringNotificationFilter && ((ExpiringNotificationFilter) entry.getValue()).isExpired()) { LOGGER.debug("Expired filter '{}' removed", entry); filters.remove(entry.getKey()); } } }
/** * Wait until allocations are at 0, or the given duration elapses. */ protected void waitForDataBufferRelease(Duration duration) throws InterruptedException { Instant start = Instant.now(); while (Instant.now().isBefore(start.plus(duration))) { try { verifyAllocations(); break; } catch (AssertionError ex) { // ignore; } Thread.sleep(50); } }
private NotificationFilter createFilter(@Nullable InstanceId id, String name, @Nullable Long ttl) { Instant expiry = ttl != null && ttl >= 0 ? Instant.now().plusMillis(ttl) : null; if (id != null) { return new InstanceIdNotificationFilter(id, expiry); } else { return new ApplicationNameNotificationFilter(name, expiry); } } }
@Override OffsetTime getTimePart( Supplier<ZoneId> defaultZone ) { ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), defaultZone.get() ) ).getOffset(); return OffsetTime.of( value, currentOffset ); }
protected Mono<Void> updateStatusForAllInstances() { log.debug("Updating status for all instances"); Instant expiryInstant = Instant.now().minus(statusLifetime); return Flux.fromIterable(lastQueried.entrySet()) .filter(e -> e.getValue().isBefore(expiryInstant)) .map(Map.Entry::getKey) .flatMap(this::updateStatus) .then(); }
private static ZoneOffset parseOffset( Matcher matcher, Supplier<ZoneId> defaultZone ) { ZoneOffset offset = parseOffset( matcher ); if ( offset == null ) { ZoneId zoneId = defaultZone.get(); offset = zoneId instanceof ZoneOffset ? (ZoneOffset) zoneId : zoneId.getRules().getOffset( Instant.now() ); } return offset; }
@Override OffsetTime getTimePart( Supplier<ZoneId> defaultZone ) { ZoneOffset currentOffset = assertValidArgument( () -> ZonedDateTime.ofInstant( Instant.now(), defaultZone.get() ) ).getOffset(); return OffsetTime.of(value.toLocalTime(), currentOffset); }
@Before public void setup() throws URISyntaxException { this.currentDate = Instant.now().truncatedTo(ChronoUnit.SECONDS); this.dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); this.dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); }
private JsonObject createJsonObject() { JsonObject obj = new JsonObject(); obj.put("mystr", "bar"); obj.put("myint", Integer.MAX_VALUE); obj.put("mylong", Long.MAX_VALUE); obj.put("myfloat", Float.MAX_VALUE); obj.put("mydouble", Double.MAX_VALUE); obj.put("myboolean", true); obj.put("mybinary", TestUtils.randomByteArray(100)); obj.put("myinstant", Instant.now()); return obj; }
protected Mono<Void> sendReminders() { Instant now = Instant.now(); return Flux.fromIterable(this.reminders.values()) .filter(reminder -> reminder.getLastNotification().plus(reminderPeriod).isBefore(now)) .flatMap(reminder -> delegate.notify(reminder.getEvent()) .doOnSuccess(signal -> reminder.setLastNotification(now))) .then(); }
@Test public void testPutInstantAsObject() { Object instant = Instant.now(); JsonObject jsonObject = new JsonObject(); jsonObject.put("instant", instant); // assert data is stored as String assertTrue(jsonObject.getValue("instant") instanceof String); }
@Test public void encodeCustomTypeInstant() { Instant now = Instant.now(); String json = Json.encode(now); assertNotNull(json); // the RFC is one way only Instant decoded = Instant.from(ISO_INSTANT.parse(json.substring(1, json.length() - 1))); assertEquals(now, decoded); }
@Override public final void read(Message message) { assertNotNull(message); assertNotNull(message.getSenderId()); assertNotNull(message.getContent()); Instant now = Instant.now(); assertTrue(now.isAfter(message.getTimestamp()) || now.equals(message.getTimestamp())); processMessage(message); latch.countDown(); }
@Test public void handleReturnValueLastModified() throws Exception { Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS); Instant oneMinAgo = currentTime.minusSeconds(60); long timestamp = currentTime.toEpochMilli(); MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifModifiedSince(timestamp)); ResponseEntity<String> entity = ok().lastModified(oneMinAgo.toEpochMilli()).body("body"); MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class)); HandlerResult result = handlerResult(entity, returnType); this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5)); assertConditionalResponse(exchange, HttpStatus.NOT_MODIFIED, null, null, oneMinAgo); }
@Test public void handleReturnValueETagAndLastModified() throws Exception { String eTag = "\"deadb33f8badf00d\""; Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS); Instant oneMinAgo = currentTime.minusSeconds(60); MockServerWebExchange exchange = MockServerWebExchange.from(get("/path") .ifNoneMatch(eTag) .ifModifiedSince(currentTime.toEpochMilli()) ); ResponseEntity<String> entity = ok().eTag(eTag).lastModified(oneMinAgo.toEpochMilli()).body("body"); MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class)); HandlerResult result = handlerResult(entity, returnType); this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5)); assertConditionalResponse(exchange, HttpStatus.NOT_MODIFIED, null, eTag, oneMinAgo); }
@Test public void handleReturnValueChangedETagAndLastModified() throws Exception { String etag = "\"deadb33f8badf00d\""; String newEtag = "\"changed-etag-value\""; Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS); Instant oneMinAgo = currentTime.minusSeconds(60); MockServerWebExchange exchange = MockServerWebExchange.from(get("/path") .ifNoneMatch(etag) .ifModifiedSince(currentTime.toEpochMilli()) ); ResponseEntity<String> entity = ok().eTag(newEtag).lastModified(oneMinAgo.toEpochMilli()).body("body"); MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class)); HandlerResult result = handlerResult(entity, returnType); this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5)); assertConditionalResponse(exchange, HttpStatus.OK, "body", newEtag, oneMinAgo); }
@Test public void testAddInstant() { Instant now = Instant.now(); assertSame(jsonArray, jsonArray.add(now)); assertEquals(now, jsonArray.getInstant(0)); assertEquals(now.toString(), jsonArray.getValue(0)); try { jsonArray.add((Instant)null); fail(); } catch (NullPointerException e) { // OK } }