@Test
public void testScheduledRefreshRecoversFromError() throws Exception {

    when(storage.findAll()).thenReturn(Observable.error(new IOException("simulated storage error")));
    capacityMonitoringService.enterActiveMode();
    testScheduler.triggerActions();
    verify(agentManagementService, times(0)).updateCapacity(any(), any(), any());
    // Next refresh round
    setupMocksForApp(1, 1, CRITICAL_APP, FLEX_APP);
    testScheduler.advanceTimeBy(DefaultCapacityMonitoringService.PERIODIC_UPDATE_INTERVAL_MS, TimeUnit.MILLISECONDS);
    verify(agentManagementService, times(1))
            .updateCapacity(CRITICAL_INSTANCE_GROUP_ID, Optional.of(1), Optional.empty());
    verify(agentManagementService, times(0))
            .updateCapacity(FLEX_INSTANCE_GROUP_ID, Optional.of(1), Optional.empty());
}