// Check the total
assertEquals(total, aggregateCounterRepository.findOne(counterName).getValue());
// Query the entire period
Interval queryInterval = new Interval(start, end);
AggregateCount aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval,
AggregateCountResolution.minute);
assertEquals(counterName, aggregateCount.getName());
assertEquals(queryInterval, aggregateCount.getInterval());
long[] counts = aggregateCount.getCounts();
// counts.length should include the end time's minute
assertEquals((2 * 24 * 60) + 1, counts.length);
assertEquals(27, counts[0]);
assertEquals(28, counts[1]);
assertEquals(59, counts[32]);
for (int i = 33; i < counts.length; i++) {
int expect = (i - 33) % 60;
assertEquals("Count at index " + i + " should be " + expect, expect, counts[i]);
}
// Query a 24 hour period in minutes
now = start.plusHours(5).withMinuteOfHour(0);
queryInterval = new Interval(now, now.plusHours(24));
aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval, AggregateCountResolution.minute);
counts = aggregateCount.getCounts();
// Add 'now.plusHours(24)' minute time to the count
assertEquals((24 * 60) + 1, counts.length);
assertEquals(0, counts[0]); // on an hour boundary
for (int i = 1; i < counts.length; i++) {
int expect = i % 60;
assertEquals("Count at index " + i + " should be " + expect, expect, counts[i]);
}
// Query the entire period in hours
queryInterval = new Interval(start, end);
aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval, AggregateCountResolution.hour);
counts = aggregateCount.getCounts();
assertEquals(49, counts.length);
// The first hour starts before the first counts are added
assertEquals(1419, counts[0]); // sum [27..59]
for (int i = 1; i < (counts.length - 1); i++) {
assertEquals(1770, counts[i]); // sum [0..59]
}
// The last hour ends at 27th minute
assertEquals(378, counts[counts.length - 1]); // sum [0..27]
// Query the entire period in days
aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval, AggregateCountResolution.day);
counts = aggregateCount.getCounts();
assertEquals(3, counts.length);
// Query beyond the period where we have data
DateTime newStart = start.withYear(2012);
aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval.withStart(newStart), AggregateCountResolution.day);
counts = aggregateCount.getCounts();
assertEquals(368, counts.length);
aggregateCount = aggregateCounterRepository.getCounts(counterName, queryInterval.withStart(newStart), AggregateCountResolution.month);
}