@Override
    public IndexRange calculateRange(String index) {
        checkIfHealthy(indices.waitForRecovery(index),
                (status) -> new RuntimeException("Unable to calculate range for index <" + index + ">, index is unhealthy: " + status));
        final DateTime now = DateTime.now(DateTimeZone.UTC);
        final Stopwatch sw = Stopwatch.createStarted();
        final IndexRangeStats stats = indices.indexRangeStatsOfIndex(index);
        final int duration = Ints.saturatedCast(sw.stop().elapsed(TimeUnit.MILLISECONDS));

        LOG.info("Calculated range of [{}] in [{}ms].", index, duration);
        return MongoIndexRange.create(index, stats.min(), stats.max(), now, duration, stats.streamIds());
    }
@Test
    public void testCalculateRangeWithNonExistingIndex() throws Exception {
        when(indices.waitForRecovery("does-not-exist")).thenReturn(HealthStatus.Red);

        assertThatThrownBy(() -> indexRangeService.calculateRange("does-not-exist"))
                .isInstanceOf(RuntimeException.class)
                .hasMessage("Unable to calculate range for index <does-not-exist>, index is unhealthy: Red");
    }