/** * Creates a new interval with the specified duration after the start instant. * * @param duration the duration to add to the start to get the new end instant, null means zero * @return an interval with the start from this interval and a calculated end * @throws IllegalArgumentException if the duration is negative */ public Interval withDurationAfterStart(ReadableDuration duration) { long durationMillis = DateTimeUtils.getDurationMillis(duration); if (durationMillis == toDurationMillis()) { return this; } Chronology chrono = getChronology(); long startMillis = getStartMillis(); long endMillis = chrono.add(startMillis, durationMillis, 1); return new Interval(startMillis, endMillis, chrono); }
@Override public boolean appliesTo(Interval theInterval, DateTime referenceTimestamp) { final DateTime periodAgo = referenceTimestamp.minus(period); return theInterval.getEndMillis() <= periodAgo.getMillis(); } }
@Override public boolean appliesTo(Interval theInterval, DateTime referenceTimestamp) { final Interval currInterval = new Interval(period, referenceTimestamp); if (includeFuture) { return currInterval.getStartMillis() <= theInterval.getStartMillis(); } else { return currInterval.contains(theInterval); } } }
/** * Creates a new interval with the same start and end, but a different chronology. * * @param chronology the chronology to use, null means ISO default * @return an interval with a different chronology */ public Interval withChronology(Chronology chronology) { if (getChronology() == chronology) { return this; } return new Interval(getStartMillis(), getEndMillis(), chronology); }
public static boolean eligibleForLoad(Period period, Interval interval, DateTime referenceTimestamp, boolean includeFuture) { final Interval currInterval = new Interval(period, referenceTimestamp); if (includeFuture) { return currInterval.getStartMillis() < interval.getEndMillis(); } else { return eligibleForLoad(currInterval, interval); } }
@Test public void testIterableQuarterSimple() { final DateTime baseTime = DateTimes.of("2011-01-01T00:00:00.000Z"); assertSameInterval( Lists.newArrayList( DateTimes.of("2011-01-01T00:00:00.000Z"), DateTimes.of("2011-04-01T00:00:00.000Z"), DateTimes.of("2011-07-01T00:00:00.000Z") ), Granularities.QUARTER.getIterable(new Interval(baseTime, baseTime.plus(Months.NINE))) ); }
existingSegments = Collections.singletonList(createSegment(new Path(taskDirPath, DruidStorageHandlerUtils.INDEX_ZIP).toString(), new Interval(100, 150, DateTimeZone.UTC), "v0", new LinearShardSpec(0))); dataSegment = createSegment(new Path(taskDirPath, DruidStorageHandlerUtils.INDEX_ZIP).toString(), new Interval(180, 250, DateTimeZone.UTC), "v1", new LinearShardSpec(0)); Assert.assertArrayEquals(Lists.newArrayList(DATA_SOURCE_NAME).toArray(), Lists.newArrayList(DruidStorageHandlerUtils.getAllDataSourceNames(connector, metadataStorageTablesConfig)) .toArray()); DataSegment persistedSegment = Iterables.getOnlyElement(dataSegmentList); Assert.assertEquals(dataSegment, persistedSegment); Assert.assertEquals(dataSegment.getVersion(), persistedSegment.getVersion()); Path expectedFinalHadoopPath = new Path(dataSegmentPusher.getPathForHadoop(), dataSegmentPusher.makeIndexPathName(persistedSegment, DruidStorageHandlerUtils.INDEX_ZIP)); Assert.assertEquals(ImmutableMap.of("type", "hdfs", "path", expectedFinalHadoopPath.toString()), persistedSegment.getLoadSpec()); Assert.assertEquals("dummySegmentData", FileUtils.readFileToString(new File(expectedFinalHadoopPath.toUri())));
final List<DataSegment> finalSegmentsToPublish = Lists.newArrayList(); for (DataSegment segment : segments) { List<TimelineObjectHolder<String, DataSegment>> existingChunks = timeline.lookup(segment.getInterval()); if (existingChunks.size() > 1) { + "Not possible to append new segment.", dataSource, segment.getInterval(), existingChunks.size())); for (PartitionChunk<DataSegment> existing : existingHolder.getObject()) { if (max == null || max.getShardSpec().getPartitionNum() < existing.getObject() .getShardSpec() .getPartitionNum()) { max = SegmentIdentifier.fromDataSegment(existing.getObject()); batch.add(new ImmutableMap.Builder<String, Object>().put("id", segment.getIdentifier()) .put("dataSource", segment.getDataSource()) .put("created_date", new DateTime().toString()) .put("start", segment.getInterval().getStart().toString()) .put("end", segment.getInterval().getEnd().toString()) .put("partitioned", !(segment.getShardSpec() instanceof NoneShardSpec)) .put("version", segment.getVersion())
@Test public void testIterableMonth() { final DateTimeZone tz = DateTimes.inferTzFromString("America/Los_Angeles"); final DateTime baseTime = new DateTime("2012-11-03T10:00:00", tz); assertSameInterval( Lists.newArrayList( new DateTime("2012-11-01T00:00:00.000-07:00", tz), new DateTime("2012-12-01T00:00:00.000-08:00", tz), new DateTime("2013-01-01T00:00:00.000-08:00", tz), new DateTime("2013-02-01T00:00:00.000-08:00", tz) ), new PeriodGranularity(new Period("P1M"), null, tz) .getIterable(new Interval(baseTime, baseTime.plus(Months.months(3)))) ); }
Map<String, Map<String, Object>> retVal = ImmutableMap.of( "tiers", tiers, "segments", segments dataSourceSegmentSize += dataSegment.getSize(); if (dataSegment.getInterval().getStartMillis() < minTime) { minTime = dataSegment.getInterval().getStartMillis(); if (dataSegment.getInterval().getEndMillis() > maxTime) { maxTime = dataSegment.getInterval().getEndMillis(); segments.put("minTime", new DateTime(minTime)); segments.put("maxTime", new DateTime(maxTime));
final Interval theInterval = new Interval(interval.replace("_", "/")); final Map<Interval, Map<String, Object>> retVal = Maps.newTreeMap(comparator); for (DataSegment dataSegment : dataSource.getSegments()) { if (theInterval.contains(dataSegment.getInterval())) { Map<String, Object> segments = retVal.get(dataSegment.getInterval()); if (segments == null) { segments = Maps.newHashMap(); retVal.put(dataSegment.getInterval(), segments); Pair<DataSegment, Set<String>> val = getSegment(dataSegment.getIdentifier()); segments.put(dataSegment.getIdentifier(), ImmutableMap.of("metadata", val.lhs, "servers", val.rhs)); final Map<Interval, Map<String, Object>> retVal = Maps.newHashMap(); for (DataSegment dataSegment : dataSource.getSegments()) { if (theInterval.contains(dataSegment.getInterval())) { Map<String, Object> properties = retVal.get(dataSegment.getInterval()); if (properties == null) { if (theInterval.contains(dataSegment.getInterval())) { retVal.add(dataSegment.getIdentifier());
@Test public void testAppliesToPeriod() { DateTime now = DateTimes.of("2012-12-31T01:00:00"); PeriodLoadRule rule = new PeriodLoadRule( new Period("P1M"), false, ImmutableMap.of("", 0) ); Assert.assertTrue(rule.appliesTo(builder.interval(new Interval(now.minusWeeks(1), now)).build(), now)); Assert.assertTrue( rule.appliesTo( builder.interval(new Interval(now.minusDays(1), now.plusDays(1))) .build(), now ) ); Assert.assertFalse( rule.appliesTo( builder.interval(new Interval(now.plusDays(1), now.plusDays(2))) .build(), now ) ); }
@Test public void testIncludeFuture() { DateTime now = DateTimes.of("2012-12-31T01:00:00"); PeriodLoadRule includeFutureRule = new PeriodLoadRule( new Period("P2D"), true, ImmutableMap.of("", 0) ); PeriodLoadRule notIncludeFutureRule = new PeriodLoadRule( new Period("P2D"), false, ImmutableMap.of("", 0) ); Assert.assertTrue( includeFutureRule.appliesTo( builder.interval(new Interval(now.plusDays(1), now.plusDays(2))).build(), now ) ); Assert.assertFalse( notIncludeFutureRule.appliesTo( builder.interval(new Interval(now.plusDays(1), now.plusDays(2))).build(), now ) ); }
@Test public void testAppliesToPartialOverlap() { DateTime now = DateTimes.of("2012-12-31T01:00:00"); PeriodLoadRule rule = new PeriodLoadRule( new Period("P1M"), false, ImmutableMap.of("", 0) ); Assert.assertTrue( rule.appliesTo( builder.interval(new Interval(now.minusWeeks(1), now.plusWeeks(1))).build(), now ) ); Assert.assertTrue( rule.appliesTo( builder.interval( new Interval(now.minusMonths(1).minusWeeks(1), now.minusMonths(1).plusWeeks(1)) ).build(), now ) ); }
assertNotNull(subscription); assertNotNull(currentPhase); assertEquals(currentPhase.getPhaseType(), PhaseType.TRIAL); assertListenerStatus(); Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(31)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus(); currentPhase = subscription.getCurrentPhase(); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusYears(1)); clock.addDeltaFromReality(it.toDurationMillis()); assertListenerStatus();
@Test public void testComputeNumMissingSegments() { Interval jan1st = new Interval(new DateTime(2015, 1, 1, 0, 0, 0), new DateTime(2015, 1, 1, 23, 59, 59)); Interval jan2nd = new Interval(new DateTime(2015, 1, 2, 0, 0, 0), new DateTime(2015, 1, 2, 23, 59, 59)); Interval jan3rd = new Interval(new DateTime(2015, 1, 3, 0, 0, 0), new DateTime(2015, 1, 3, 23, 59, 59)); Interval jan4th = new Interval(new DateTime(2015, 1, 4, 0, 0, 0), new DateTime(2015, 1, 4, 23, 59, 59)); Interval jan5th = new Interval(new DateTime(2015, 1, 5, 0, 0, 0), new DateTime(2015, 1, 5, 23, 59, 59)); jan1st2nd3rd.add(jan2nd); jan1st2nd3rd.add(jan3rd); assertEquals(OfflineSegmentIntervalChecker.computeNumMissingSegments(jan1st2nd3rd, Duration.standardDays(1)), 0); assertEquals(OfflineSegmentIntervalChecker.computeNumMissingSegments(jan1st2nd3rd5th, Duration.standardDays(1)), 1); jan5th2nd1st.add(jan2nd); jan5th2nd1st.add(jan1st); assertEquals(OfflineSegmentIntervalChecker.computeNumMissingSegments(jan5th2nd1st, Duration.standardDays(1)), 2); Interval jan1stAnd2nd = new Interval(new DateTime(2015, 1, 1, 0, 0, 0), new DateTime(2015, 1, 2, 23, 59, 59)); ArrayList<Interval> jan1st2nd4th5th = new ArrayList<Interval>(); jan1st2nd4th5th.add(jan1stAnd2nd);
private void tChangePlanBundleAlignIMM(final String fromProd, final BillingPeriod fromTerm, final String fromPlanSet, final String toProd, final BillingPeriod toTerm, final String toPlanSet) throws SubscriptionBaseApiException { final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, fromProd, fromTerm, fromPlanSet); testListener.pushExpectedEvent(NextEvent.CHANGE); Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(3)); clock.addDeltaFromReality(it.toDurationMillis()); // CHANGE PLAN IMM final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier(toProd, toTerm, toPlanSet); subscription.changePlan(new DefaultEntitlementSpecifier(planPhaseSpecifier), callContext); checkChangePlan(subscription, toProd, ProductCategory.BASE, toTerm, PhaseType.TRIAL); assertListenerStatus(); final PlanPhase currentPhase = subscription.getCurrentPhase(); final DateTime nextExpectedPhaseChange = TestSubscriptionHelper.addDuration(subscription.getStartDate(), currentPhase.getDuration()); testUtil.checkNextPhaseChange(subscription, 1, nextExpectedPhaseChange); // NEXT PHASE testListener.pushExpectedEvent(NextEvent.PHASE); it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(30)); clock.addDeltaFromReality(it.toDurationMillis()); final DateTime futureNow = clock.getUTCNow(); assertTrue(futureNow.isAfter(nextExpectedPhaseChange)); assertListenerStatus(); }
Map<String, Map<String, Object>> retVal = ImmutableMap.of( "tiers", tiers, "segments", segments for (DataSegment dataSegment : druidDataSource.getSegments()) { if (!tierDistinctSegments.get(tier).contains(dataSegment.getIdentifier())) { dataSourceSegmentSize += dataSegment.getSize(); tierDistinctSegments.get(tier).add(dataSegment.getIdentifier()); totalDistinctSegments.add(dataSegment.getIdentifier()); minTime = DateTimes.min(minTime, dataSegment.getInterval().getStart()); maxTime = DateTimes.max(maxTime, dataSegment.getInterval().getEnd());
@Test(groups = "slow") public void testInvalidChangesAcrossProductTypes() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; // CREATE BP final DefaultSubscriptionBase baseSubscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList); // MOVE CLOCK 14 DAYS LATER Interval it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusDays(14)); clock.addDeltaFromReality(it.toDurationMillis()); // Create AO final String aoProduct = "Laser-Scope"; final BillingPeriod aoTerm = BillingPeriod.MONTHLY; final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME; DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList); try { final PlanPhaseSpecifier planPhaseSpecifier = new PlanPhaseSpecifier(baseProduct, baseTerm, basePriceList); aoSubscription.changePlanWithDate(new DefaultEntitlementSpecifier(planPhaseSpecifier), clock.getUTCNow(), callContext); Assert.fail("Should not allow plan change across product type"); } catch (final SubscriptionBaseApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.SUB_CHANGE_INVALID.getCode()); } }