InfluxStatisticsProvider implements StatisticsProvider { protected static List<Tuple<Instant, Instant>> getPeriods(final Instant from, final Instant to, DataResolution resolution, ZoneId zoneId) { switch (resolution) { case MONTHLY: return getMonthPeriods(getMonths(from, to, zoneId), from, to); case YEARLY: return getYearPeriods(getYears(from, to, zoneId), from, to); case DAILY: case WEEKLY: default: return Collections.singletonList(new Tuple<>(from, to)); } } InfluxStatisticsProvider(
      StatisticsProviderInfluxService service,
      String id,
      ResourceType resourceType,
      String title,
      String description
  ); @Override String getId(); @Override ResourceType getResourceType(); @Override String getTitle(); @Override String getDescription(); @Override int hashCode(); @Override boolean equals(Object o);  }
@Test public void testGetPeriodsYearly() { for (int i = 0; i < repetitions; i++) { final Instant a = randomInstant(); final Instant b = randomInstant(); final Instant from = Ordering.natural().min(a, b); final Instant to = Ordering.natural().max(a, b); logger.info("from {} to {} {}", from, to, DataResolution.YEARLY.name()); final List<Tuple<Instant, Instant>> periods = InfluxStatisticsProvider.getPeriods(from, to, DataResolution.YEARLY, ZoneId.of("Z")); assertEquals(from, periods.get(0).getA()); if (periods.size() > 1) { assertEquals( LocalDateTime .ofInstant(from, ZoneOffset.UTC) .plusYears(1) .withMonth(1) .withDayOfMonth(1) .withHour(0) .withMinute(0) .withSecond(0) .withNano(0) .minusNanos(1) .toInstant(ZoneOffset.UTC), periods.get(0).getB()); } else { assertEquals(to, periods.get(0).getB()); continue; } assertEquals(to, periods.get(periods.size() - 1).getB()); assertEquals(LocalDateTime .ofInstant(to, ZoneOffset.UTC) .withMonth(1) .withDayOfMonth(1) .withHour(0) .withMinute(0) .withSecond(0) .withNano(0) .toInstant(ZoneOffset.UTC), periods.get(periods.size() - 1).getA()); } }
@Test public void testGetPeriodsDaily() { for (int i = 0; i < repetitions; i++) { final Instant a = randomInstant(); final Instant b = randomInstant(); final Instant from = Ordering.natural().min(a, b); final Instant to = Ordering.natural().max(a, b); logger.info("from {} to {} {}", from, to, DataResolution.DAILY.name()); final List<Tuple<Instant, Instant>> periods = InfluxStatisticsProvider.getPeriods(from, to, DataResolution.DAILY, ZoneId.of("Z")); assertEquals(1, periods.size()); assertEquals(from, periods.get(0).getA()); assertEquals(to, periods.get(0).getB()); } }
@Test public void testGetPeriodsWeekly() { for (int i = 0; i < repetitions; i++) { final Instant a = randomInstant(); final Instant b = randomInstant(); final Instant from = Ordering.natural().min(a, b); final Instant to = Ordering.natural().max(a, b); logger.info("from {} to {} {}", from, to, DataResolution.WEEKLY.name()); final List<Tuple<Instant, Instant>> periods = InfluxStatisticsProvider.getPeriods(from, to, DataResolution.WEEKLY, ZoneId.of("Z")); assertEquals(1, periods.size()); assertEquals(from, periods.get(0).getA()); assertEquals(to, periods.get(0).getB()); } }
@Test public void testGetPeriodsMonthly() { for (int i = 0; i < repetitions; i++) { final Instant a = randomInstant(); final Instant b = randomInstant(); final Instant from = Ordering.natural().min(a, b); final Instant to = Ordering.natural().max(a, b); logger.info("from {} to {} {}", from, to, DataResolution.MONTHLY.name()); final List<Tuple<Instant, Instant>> periods = InfluxStatisticsProvider.getPeriods(from, to, DataResolution.MONTHLY, ZoneId.of("Z")); assertEquals(from, periods.get(0).getA()); if (periods.size() > 1) { assertEquals( LocalDateTime .ofInstant(from, ZoneOffset.UTC) .plusMonths(1) .withDayOfMonth(1) .withHour(0) .withMinute(0) .withSecond(0) .withNano(0) .minusNanos(1) .toInstant(ZoneOffset.UTC), periods.get(0).getB()); } else { assertEquals(to, periods.get(0).getB()); continue; } assertEquals(to, periods.get(periods.size() - 1).getB()); assertEquals(LocalDateTime .ofInstant(to, ZoneOffset.UTC) .withDayOfMonth(1) .withHour(0) .withMinute(0) .withSecond(0) .withNano(0) .toInstant(ZoneOffset.UTC), periods.get(periods.size() - 1).getA()); } }