@Setup public void setupDummyCluster() { segment = createSegment(t0); Random r = ThreadLocalRandom.current(); segments = new ArrayList<>(n); for (int i = 0; i < n; ++i) { final DateTime t = t0.minusHours(r.nextInt(365 * 24) - 365 * 12); segments.add(createSegment(t)); } }
/** * Helper method for getting a value containing CURRENTDAY-1 or CURRENTHOUR-1 in the form yyyyMMddHHmmss * @param value * @param timezone * @return */ public static long getLongWithCurrentDate(String value, String timezone) { if (Strings.isNullOrEmpty(value)) { return 0; } DateTime time = getCurrentTime(timezone); DateTimeFormatter dtFormatter = DateTimeFormat.forPattern(CURRENT_DATE_FORMAT).withZone(time.getZone()); if (value.toUpperCase().startsWith(CURRENT_DAY)) { return Long .parseLong(dtFormatter.print(time.minusDays(Integer.parseInt(value.substring(CURRENT_DAY.length() + 1))))); } if (value.toUpperCase().startsWith(CURRENT_HOUR)) { return Long .parseLong(dtFormatter.print(time.minusHours(Integer.parseInt(value.substring(CURRENT_HOUR.length() + 1))))); } return Long.parseLong(value); }
private void sampleGetRelativeTimeSpanString() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25))); text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5))); text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3))); text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25))); text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5))); text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3))); addSample("DateUtils.getRelativeTimeSpanString()", text); }
private void sampleGetRelativeDateTimeString() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Short future: " + DateUtils.getRelativeDateTimeString(this, now.plusMinutes(25), null, 0)); text.add("Medium future: " + DateUtils.getRelativeDateTimeString(this, now.plusHours(5), null, 0)); text.add("Long future: " + DateUtils.getRelativeDateTimeString(this, now.plusDays(3), null, 0)); text.add("Short past: " + DateUtils.getRelativeDateTimeString(this, now.minusMinutes(25), null, 0)); text.add("Medium past: " + DateUtils.getRelativeDateTimeString(this, now.minusHours(5), null, 0)); text.add("Long past: " + DateUtils.getRelativeDateTimeString(this, now.minusDays(3), null, 0)); addSample("DateUtils.getRelativeDateTimeString()", text); }
private void sampleGetRelativeTimeSpanStringWithPreposition() { List<String> text = new ArrayList<String>(); DateTime now = DateTime.now(); text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25), true)); text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5), true)); text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3), true)); text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25), true)); text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5), true)); text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3), true)); addSample("DateUtils.getRelativeTimeSpanString() (with preposition)", text); }
public List<String> searchRecentRunningWorkflows(int lastModifiedHoursAgoFrom, int lastModifiedHoursAgoTo) { DateTime dateTime = new DateTime(); QueryBuilder q = QueryBuilders.boolQuery() .must(QueryBuilders.rangeQuery("updateTime") .gt(dateTime.minusHours(lastModifiedHoursAgoFrom))) .must(QueryBuilders.rangeQuery("updateTime") .lt(dateTime.minusHours(lastModifiedHoursAgoTo))) .must(QueryBuilders.termQuery("status", "RUNNING")); SearchResult<String> workflowIds; try { workflowIds = searchObjectIds(indexName, q, 0, 5000, Collections.singletonList("updateTime:ASC"), WORKFLOW_DOC_TYPE); } catch (IOException e) { logger.error("Unable to communicate with ES to find recent running workflows", e); return Collections.emptyList(); } return workflowIds.getResults(); }
private static void completeBuildInstancesOfStage(Stage stage, JobResult result, Date completionDate) { for (JobInstance job : stage.getJobInstances()) { job.assign("uuid", new DateTime(completionDate.getTime()).minusHours(1).toDate()); job.completing(result, completionDate); job.completed(completionDate); } stage.setLastTransitionedTime(new Timestamp(completionDate.getTime())); }
@Override public List<String> searchRecentRunningWorkflows(int lastModifiedHoursAgoFrom, int lastModifiedHoursAgoTo) { DateTime dateTime = new DateTime(); QueryBuilder q = QueryBuilders.boolQuery() .must(QueryBuilders.rangeQuery("updateTime") .gt(dateTime.minusHours(lastModifiedHoursAgoFrom))) .must(QueryBuilders.rangeQuery("updateTime") .lt(dateTime.minusHours(lastModifiedHoursAgoTo))) .must(QueryBuilders.termQuery("status", "RUNNING")); SearchRequestBuilder s = elasticSearchClient.prepareSearch(indexName) .setTypes("workflow") .setQuery(q) .setSize(5000) .addSort("updateTime", SortOrder.ASC); SearchResponse response = s.execute().actionGet(); return StreamSupport.stream(response.getHits().spliterator(), false) .map(hit -> hit.getId()) .collect(Collectors.toCollection(LinkedList::new)); }
@Before public void setUp() { nowMod = new Modification("user3", "fixed the build.", null, new DateTime().toDate(), "100"); nowMod.createModifiedFile("foo.java", ".", ModifiedAction.modified); oneHourAgoMod = new Modification("user2", "fixed the build.", null, new DateTime().minusHours(1).toDate(), "89"); oneHourAgoMod.createModifiedFile("foo.java", ".", ModifiedAction.modified); yesterdayMod = new Modification("user1", "fixed the build.", null, new DateTime().minusDays(1).toDate(), "9"); yesterdayMod.createModifiedFile("foo.java", ".", ModifiedAction.modified); material = MaterialsMother.svnMaterial("foo"); material.setName(new CaseInsensitiveString("Foo")); }
@Test public void randomSegmentsCostTest() { List<DataSegment> dataSegments = new ArrayList<>(1000); Random random = new Random(1); for (int i = 0; i < 1000; ++i) { dataSegments.add(createSegment(DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, random.nextInt(20)), 100)); } DataSegment referenceSegment = createSegment("ANOTHER_DATA_SOURCE", shifted1HInterval(REFERENCE_TIME, 5), 100); SegmentsCostCache.Bucket.Builder prototype = SegmentsCostCache.Bucket.builder(new Interval( REFERENCE_TIME.minusHours(1), REFERENCE_TIME.plusHours(25) )); dataSegments.forEach(prototype::addSegment); SegmentsCostCache.Bucket bucket = prototype.build(); double cost = bucket.cost(referenceSegment); assertEquals(0.7065117101966677, cost, EPSILON); }
"DUMMY", new Interval( referenceTime.minusHours(2), referenceTime.minusHours(2).plusHours(1)
final DateTime bundleStartDate = now.minusHours(10); final DateTime alignStartDate = bundleStartDate.plusHours(5); final DateTime effectiveDateInThePast = defaultSubscriptionBase.getBundleStartDate().minusHours(10); final TimedPhase[] phasesInThePast = getTimedPhasesOnCreate(productName, initialPhase, defaultSubscriptionBase, effectiveDateInThePast); Assert.assertNull(phasesInThePast[0]);
final DateTime bundleStartDate = now.minusHours(10); final DateTime alignStartDate = bundleStartDate.plusHours(5); final DateTime effectiveDateInThePast = defaultSubscriptionBase.getStartDate().minusHours(10); final TimedPhase[] phasesInThePast = getTimedPhasesOnCreate(productName, initialPhase, defaultSubscriptionBase, effectiveDateInThePast); Assert.assertNull(phasesInThePast[0]);
@Test public void calculationIntervalTest() { DataSegment segmentA = createSegment(DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, 0), 100); DataSegment segmentB = createSegment( DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, (int) TimeUnit.DAYS.toHours(50)), 100 ); SegmentsCostCache.Bucket.Builder prototype = SegmentsCostCache.Bucket.builder( new Interval(REFERENCE_TIME.minusHours(5), REFERENCE_TIME.plusHours(5)) ); prototype.addSegment(segmentA); SegmentsCostCache.Bucket bucket = prototype.build(); assertTrue(bucket.inCalculationInterval(segmentA)); assertFalse(bucket.inCalculationInterval(segmentB)); }
@Test public void twoSegmentsCostTest() { DataSegment segmentA = createSegment(DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, 0), 100); DataSegment segmentB = createSegment(DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, -2), 100); SegmentsCostCache.Bucket.Builder prototype = SegmentsCostCache.Bucket.builder(new Interval( REFERENCE_TIME.minusHours(5), REFERENCE_TIME.plusHours(5) )); prototype.addSegment(segmentA); SegmentsCostCache.Bucket bucket = prototype.build(); double segmentCost = bucket.cost(segmentB); assertEquals(7.8735899489011E-4, segmentCost, EPSILON); }
@Test public void sameSegmentCostTest() { DataSegment segmentA = createSegment(DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, 0), 100); DataSegment segmentB = createSegment(DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, 0), 100); SegmentsCostCache.Bucket.Builder prototype = SegmentsCostCache.Bucket.builder(new Interval( REFERENCE_TIME.minusHours(5), REFERENCE_TIME.plusHours(5) )); prototype.addSegment(segmentA); SegmentsCostCache.Bucket bucket = prototype.build(); double segmentCost = bucket.cost(segmentB); assertEquals(8.26147353873985E-4, segmentCost, EPSILON); }
@Test public void testCompareHour() { Result<Object> res = new Result<Object>(time, null); Result<Object> same = new Result<Object>(time.plusMinutes(55), null); Result<Object> greater = new Result<Object>(time.plusHours(1), null); Result<Object> less = new Result<Object>(time.minusHours(1), null); Granularity hour = Granularities.HOUR; Assert.assertEquals(ResultGranularTimestampComparator.create(hour, descending).compare(res, same), 0); Assert.assertEquals(ResultGranularTimestampComparator.create(hour, descending).compare(res, greater), descending ? 1 : -1); Assert.assertEquals(ResultGranularTimestampComparator.create(hour, descending).compare(res, less), descending ? -1 : 1); } }
@Test public void testCompareDay() { Result<Object> res = new Result<Object>(time, null); Result<Object> same = new Result<Object>(time.plusHours(12), null); Result<Object> greater = new Result<Object>(time.plusHours(25), null); Result<Object> less = new Result<Object>(time.minusHours(1), null); Granularity day = Granularities.DAY; Assert.assertEquals(ResultGranularTimestampComparator.create(day, descending).compare(res, same), 0); Assert.assertEquals(ResultGranularTimestampComparator.create(day, descending).compare(res, greater), descending ? 1 : -1); Assert.assertEquals(ResultGranularTimestampComparator.create(day, descending).compare(res, less), descending ? -1 : 1); }
@Test public void multipleSegmentsCostTest() { DataSegment segmentA = createSegment(DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, -2), 100); DataSegment segmentB = createSegment(DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, 0), 100); DataSegment segmentC = createSegment(DATA_SOURCE, shifted1HInterval(REFERENCE_TIME, 2), 100); SegmentsCostCache.Bucket.Builder prototype = SegmentsCostCache.Bucket.builder(new Interval( REFERENCE_TIME.minusHours(5), REFERENCE_TIME.plusHours(5) )); prototype.addSegment(segmentA); prototype.addSegment(segmentC); SegmentsCostCache.Bucket bucket = prototype.build(); double segmentCost = bucket.cost(segmentB); assertEquals(0.001574717989780039, segmentCost, EPSILON); }
@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))); }