@Test
public void testScheduledRefresh() throws Exception {

    setupMocksForApp(1, 1, CRITICAL_APP, FLEX_APP);
    capacityMonitoringService.enterActiveMode();
    testScheduler.triggerActions();
    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());
    // Next refresh round
    AgentInstanceGroup criticalInstanceGroup = getCriticalInstanceGroup(2, 2);
    CapacityAllocations allocations = new CapacityAllocations(singletonMap(criticalInstanceGroup, 2), emptyMap());
    when(capacityGuaranteeStrategy.compute(any())).thenReturn(allocations);
    when(agentManagementService.updateCapacity(any(), any(), any())).thenReturn(Completable.complete());
    testScheduler.advanceTimeBy(DefaultCapacityMonitoringService.PERIODIC_UPDATE_INTERVAL_MS, TimeUnit.MILLISECONDS);
    verify(agentManagementService, times(1))
            .updateCapacity(CRITICAL_INSTANCE_GROUP_ID, Optional.of(2), Optional.empty());
}