AbstractSchemaService extends DefaultService implements SchemaService { protected int getNumSecondsUntilNthHourOfWeek(int nthHour, Calendar fromCalendar) { int day = fromCalendar.get(Calendar.DAY_OF_WEEK) - 1; int hour = fromCalendar.get(Calendar.HOUR_OF_DAY); int currNthHour = day * 24 + hour; int hoursUntil = currNthHour < nthHour ? (nthHour - currNthHour) : (nthHour + 7*24 - currNthHour); int secondsPastHour = fromCalendar.get(Calendar.MINUTE) * 60; return hoursUntil * 60 * 60 - secondsPastHour; } protected  AbstractSchemaService(SystemConfiguration config, MonitorService monitorService); @Override void put(Metric metric); @Override void put(List<Metric> metrics); @Override void dispose(); @Override abstract Properties getServiceProperties(); @Override abstract List<MetricSchemaRecord> get(MetricSchemaRecordQuery query); @Override abstract List<MetricSchemaRecord> getUnique(MetricSchemaRecordQuery query, RecordType type); @Override abstract List<String> browseUnique(MetricSchemaRecordQuery query, RecordType type, int indexLevel); @Override abstract List<MetricSchemaRecord> keywordSearch(KeywordQuery query);  }
@Test public void testNumHoursUntilNextFlushBloomFilter() { Calendar wedAtSix = Calendar.getInstance(); wedAtSix.set(Calendar.HOUR_OF_DAY, 6); wedAtSix.set(Calendar.DAY_OF_WEEK, 4); for (int dayIndex = 0; dayIndex < 3; dayIndex++) { int nthHour = dayIndex * 24 + 4; int secondsUntil = _esSchemaService.getNumSecondsUntilNthHourOfWeek(nthHour, wedAtSix); int floorHoursUntil = secondsUntil / 60 / 60; int expectedHours = (4 + dayIndex) * 24 - 2; assertTrue("hoursUntil should be between " + (expectedHours - 1) + " and " + expectedHours, expectedHours - 1 <= floorHoursUntil && floorHoursUntil <= expectedHours); } for (int dayIndex = 3; dayIndex < 7; dayIndex++) { int nthHour = dayIndex * 24 + 8; int secondsUntil = _esSchemaService.getNumSecondsUntilNthHourOfWeek(nthHour, wedAtSix); int floorHoursUntil = secondsUntil / 60 / 60; int expectedHours = (dayIndex - 3) * 24 + 2; assertTrue("hoursUntil should be between " + (expectedHours - 1) + " and " + expectedHours, expectedHours - 1 <= floorHoursUntil && floorHoursUntil <= expectedHours); } }