public DateTime timeoutTime(long timeoutInMillis) { return new DateTime().plusMillis((int) timeoutInMillis); } }
protected void flushAfterDuration(final long truncatedTime, final Sink sink) { log.info( "Abandoning segment %s at %s", sink.getSegment().getId(), DateTimes.nowUtc().plusMillis((int) flushDuration.getMillis()) ); ScheduledExecutors.scheduleWithFixedDelay( flushScheduledExec, flushDuration, new Callable<ScheduledExecutors.Signal>() { @Override public ScheduledExecutors.Signal call() { log.info("Abandoning segment %s", sink.getSegment().getId()); abandonSegment(truncatedTime, sink); return ScheduledExecutors.Signal.STOP; } } ); }
@Test public void shouldGiveTimeoutTime() throws Exception { DateTime expected = new DateTime().plusMillis((int) Timeout.NINETY_SECONDS.inMillis()); DateTime actual = new SystemTimeClock().timeoutTime(Timeout.NINETY_SECONDS); assertThat(actual.equals(expected) || actual.isAfter(expected),is(true)); } }
@Test(timeout = 60_000L) public void testShutdown() throws Exception { EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)) .andReturn(null) .anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_ALLOW_UNSECURED_PATH)).andReturn(null).anyTimes(); EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)) .andReturn(AllowAllAuthenticator.ALLOW_ALL_RESULT) .anyTimes(); req.setAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED, true); EasyMock.expectLastCall().anyTimes(); EasyMock.replay(req); firehose.shutdown(DateTimes.nowUtc().plusMillis(100).toString(), req); while (!firehose.isClosed()) { Thread.sleep(50); } }
@Test(groups = "slow") public void test() throws Exception { final UUID accountId = new UUID(0L, 1L); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); Mockito.when(accountApi.getImmutableAccountDataByRecordId(Mockito.eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); final DateTime now = clock.getUTCNow(); final DateTime readyTime = now.plusMillis(2000); final OverdueCheckNotificationKey notificationKey = new OverdueCheckNotificationKey(accountId); checkPoster.insertOverdueNotification(accountId, readyTime, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE, notificationKey, internalCallContext); // Move time in the future after the notification effectiveDate clock.setDeltaFromReality(3000); await().atMost(5, SECONDS).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return mockDispatcher.getEventCount() == 1; } }); Assert.assertEquals(mockDispatcher.getEventCount(), 1); Assert.assertEquals(mockDispatcher.getLatestAccountId(), accountId); } }
@Test public void testUsedOverlapEnd() throws IOException { coordinator.announceHistoricalSegments(SEGMENTS); Assert.assertEquals( SEGMENTS, ImmutableSet.copyOf( coordinator.getUsedSegmentsForInterval( defaultSegment.getDataSource(), defaultSegment.getInterval().withEnd(defaultSegment.getInterval().getEnd().plusMillis(1)) ) ) ); }
@Test public void testAddFieldToTimestamp() { assertFunction("date_add('millisecond', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMillis(3), session)); assertFunction("date_add('second', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusSeconds(3), session)); assertFunction("date_add('minute', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMinutes(3), session)); assertFunction("date_add('hour', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusHours(3), session)); assertFunction("date_add('hour', 23, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusHours(23), session)); assertFunction("date_add('hour', -4, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.minusHours(4), session)); assertFunction("date_add('hour', -23, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.minusHours(23), session)); assertFunction("date_add('day', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusDays(3), session)); assertFunction("date_add('week', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusWeeks(3), session)); assertFunction("date_add('month', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMonths(3), session)); assertFunction("date_add('quarter', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusMonths(3 * 3), session)); assertFunction("date_add('year', 3, " + TIMESTAMP_LITERAL + ")", TimestampType.TIMESTAMP, sqlTimestampOf(TIMESTAMP.plusYears(3), session)); assertFunction("date_add('millisecond', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMillis(3))); assertFunction("date_add('second', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusSeconds(3))); assertFunction("date_add('minute', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMinutes(3))); assertFunction("date_add('hour', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusHours(3))); assertFunction("date_add('day', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusDays(3))); assertFunction("date_add('week', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusWeeks(3))); assertFunction("date_add('month', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3))); assertFunction("date_add('quarter', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusMonths(3 * 3))); assertFunction("date_add('year', 3, " + WEIRD_TIMESTAMP_LITERAL + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(WEIRD_TIMESTAMP.plusYears(3))); }
private EventCounterIf<EventCounter> nextCurrentCounter(ReadableDateTime now) { EventCounter eventCounter = new EventCounterImpl(now, now.toDateTime().plusMillis(timeBucketSizeMillis)); allTimeCounter.addEventCounter(eventCounter); hourCounter.addEventCounter(eventCounter); tenMinuteCounter.addEventCounter(eventCounter); minuteCounter.addEventCounter(eventCounter); return eventCounter; }
/** * Return the delay before next activation after detecting a busy loop. * * @return The delay in milliseconds. */ public DateTime getShortTransitionActivation() { return now().plusMillis(shortTransitionDelay); }
public TimelineSourceEventAccumulator(final TimelineDao dao, final TimelineCoder timelineCoder, final SampleCoder sampleCoder, final BackgroundDBChunkWriter backgroundWriter, final int sourceId, final int eventCategoryId, final DateTime firstSampleTime, final Integer timelineLengthMillis) { this.timelineLengthMillis = timelineLengthMillis; this.backgroundWriter = backgroundWriter; this.timelineCoder = timelineCoder; this.sampleCoder = sampleCoder; this.sourceId = sourceId; this.eventCategoryId = eventCategoryId; // Set the end-of-chunk time by tossing a random number, to evenly distribute the db writeback load. this.chunkEndTime = timelineLengthMillis != null ? firstSampleTime.plusMillis(rand.nextInt(timelineLengthMillis)) : null; }
private Date calculateOrderStartDate(Date finishDate, Integer changeoverDurationInMillis) { DateTime finishDateTime = new DateTime(finishDate); finishDateTime = finishDateTime.plusMillis(changeoverDurationInMillis); return finishDateTime.toDate(); }
DateTime dt = new DateTime("2014-09-15T21:20:14", DateTimeZone.UTC); System.out.println(dt); DateTime other = dt.plusMillis(581042272); System.out.println(other);
DateTime udate = new DateTime("2016-05-01T20:10:04", DateTimeZone.UTC); System.out.println(udate); DateTime zone = udate.plusMillis(10000) .withZone(DateTimeZone.forID("Asia/Kolkata")); System.out.println(zone);
/** * {@inheritDoc} * * @see org.modeshape.graph.property.DateTime#plusMillis(int) */ public org.modeshape.graph.property.DateTime plusMillis( int milliseconds ) { return new JodaDateTime(this.instance.plusMillis(milliseconds)); }
private List<DateTime> getMillisLabels(DateTime min, DateTime max, int unitSize) { List<DateTime> labels = new ArrayList<>(); DateTime dt = new DateTime(min.getYear(), min.getMonthOfYear(), min.getDayOfMonth(), min.getHourOfDay(), min.getMinuteOfHour(), min.getSecondOfMinute(), min.getMillisOfSecond() / unitSize * unitSize); while (dt.isBefore(max) || dt.isEqual(max)) { labels.add(dt); dt = dt.plusMillis(unitSize); } labels.add(dt); return labels; }
protected boolean isDateTimeSkewValid(int skewMillis, int forwardMillis, DateTime time) { if (time == null) { return false; } final DateTime reference = new DateTime(); final Interval validTimeInterval = new Interval( reference.minusMillis(skewMillis + forwardMillis), reference.plusMillis(skewMillis) ); return validTimeInterval.contains(time); }
@Override public synchronized void put(Id<Node> nodeId, DynamicAnnouncement announcement) { Preconditions.checkNotNull(nodeId, "nodeId is null"); Preconditions.checkNotNull(announcement, "announcement is null"); Set<Service> services = ImmutableSet.copyOf(transform(announcement.getServiceAnnouncements(), toServiceWith(nodeId, announcement.getLocation(), announcement.getPool()))); DateTime expiration = currentTime.get().plusMillis((int) maxAge.toMillis()); descriptors.put(nodeId, new Entry(expiration, services)); }
@Override public void jobEnds(JobExecution execution, JobExecutionContext context) { String sql = "update " + getTableName() + " set endDate = :endDate, ended = :ended, result = :result where id = :id"; SqlParameterSource params = new MapSqlParameterSource() .addValue("endDate", new DateTime(context.getFireTime()).plusMillis((int) context.getJobRunTime()).toDate()) .addValue("ended", true) .addValue("result", execution.getResult().name()) .addValue("id", execution.getId()); jdbcTemplate.update(sql, params); }
public TestInterval(int years, int months, int days, int hours, int minutes, int seconds, int millis) { end = start.plusYears(years) .plusMonths(months) .plusDays(days) .plusHours(hours) .plusMinutes(minutes) .plusSeconds(seconds) .plusMillis(millis); interval = new Interval(start, end); }
@Test public void testAddFieldToTime() { assertFunction("date_add('millisecond', 3, " + TIME_LITERAL + ")", TimeType.TIME, toTime(TIME.plusMillis(3))); assertFunction("date_add('second', 3, " + TIME_LITERAL + ")", TimeType.TIME, toTime(TIME.plusSeconds(3))); assertFunction("date_add('minute', 3, " + TIME_LITERAL + ")", TimeType.TIME, toTime(TIME.plusMinutes(3))); assertFunction("date_add('hour', 3, " + TIME_LITERAL + ")", TimeType.TIME, toTime(TIME.plusHours(3))); assertFunction("date_add('millisecond', 3, " + WEIRD_TIME_LITERAL + ")", TIME_WITH_TIME_ZONE, toTimeWithTimeZone(WEIRD_TIME.plusMillis(3))); assertFunction("date_add('second', 3, " + WEIRD_TIME_LITERAL + ")", TIME_WITH_TIME_ZONE, toTimeWithTimeZone(WEIRD_TIME.plusSeconds(3))); assertFunction("date_add('minute', 3, " + WEIRD_TIME_LITERAL + ")", TIME_WITH_TIME_ZONE, toTimeWithTimeZone(WEIRD_TIME.plusMinutes(3))); assertFunction("date_add('hour', 3, " + WEIRD_TIME_LITERAL + ")", TIME_WITH_TIME_ZONE, toTimeWithTimeZone(WEIRD_TIME.plusHours(3))); }