@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());
  }
}