tooManyLocators.add(Locator.createLocatorFromDbKey(UUID.randomUUID().toString()));
}
BatchMetricsQuery query = new BatchMetricsQuery(tooManyLocators, range, gran);
// Now test a bad case with extremely low timeout. We shouldn't throw any exceptions.
Map<Locator, MetricData> results = batchMetricsQueryHandler.execute(query, new TimeValue(1, TimeUnit.MILLISECONDS));
// Make sure there were things still in progress and nothing breaks.
Assert.assertNull(results);
// Executor queue should not have any items left.
// XXX: OpenJDK6 ArrayBlockingQueue has a weird bug where it returns negative value for size() when you call
// purge() on the executor that uses the queue.
Assert.assertTrue("Number of items left in queue should be 0", executor.getQueue().size() <= 0);
// Note there is no guarantee that items currently in execution will definitely be done or interrupted.
// Test happy case. 5s is plenty of time to read two metrics.
// Use the same executor. We shouldn't see issues.
results = batchMetricsQueryHandler.execute(query, new TimeValue(5, TimeUnit.SECONDS));
Assert.assertEquals(locators.size(), results.size());
for (Map.Entry<Locator, MetricData> item : results.entrySet()) {
MetricData data = item.getValue();
Assert.assertEquals((int) answers.get(item.getKey()).get(gran), data.getData().getPoints().size());