IndexSelector { public String getIndexPatternOlderThanDays(String prefix, int days) { final StringBuilder indexPattern = new StringBuilder(prefix).append('*'); final GregorianCalendar now = getNowUTC(); final GregorianCalendar lastDayToExclude = getLastDayToExclude(days); final GregorianCalendar alreadyExcluded = getNowUTC(); excludeMonths(prefix, now, indexPattern, lastDayToExclude, alreadyExcluded); excludeDays(prefix, indexPattern, lastDayToExclude, alreadyExcluded); return indexPattern.toString(); } IndexSelector(Clock clock); String getIndexPatternOlderThanDays(String prefix, int days);  }
@Test public void testSelectIndexYearChange2Days() throws Exception { final String indexPattern = indexSelector.getIndexPatternOlderThanDays("metrics-", 2); assertEquals("metrics-*,-metrics-1970.01.*,-metrics-1969.12.31,-metrics-1969.12.30", indexPattern); }
@Test public void testSelectIndexYearChange33Days() throws Exception { final String indexPattern = indexSelector.getIndexPatternOlderThanDays("metrics-", 33); assertEquals("metrics-*,-metrics-1970.01.*,-metrics-1969.12.*,-metrics-1969.11.30,-metrics-1969.11.29", indexPattern); }
@Test public void testSelectIndexIntraMonth() throws Exception { when(clock.getTime()).thenReturn(DateUtils.getDayInMillis() * 7); final String indexPattern = indexSelector.getIndexPatternOlderThanDays("metrics-", 2); assertEquals("metrics-*,-metrics-1970.01.08,-metrics-1970.01.07,-metrics-1970.01.06", indexPattern); }