@Test
public void testTaggedInstanceGroupsAreRemovedAfterDeadline() {

    AgentInstanceGroup instanceGroup = AgentStoreReaper.tagToRemove(AgentGenerator.agentServerGroups().getValue(), testScheduler);
    AgentInstance instance = AgentGenerator.agentInstances(instanceGroup).getValue();
    when(agentStore.retrieveAgentInstanceGroups()).thenReturn(Observable.just(instanceGroup));
    when(agentStore.retrieveAgentInstances()).thenReturn(Observable.just(instance));
    testScheduler.advanceTimeBy(AgentStoreReaper.MIN_EXPIRED_DATA_RETENTION_PERIOD_MS - 1, TimeUnit.MILLISECONDS);
    verify(agentStore, times(0)).removeAgentInstanceGroups(Collections.singletonList(instanceGroup.getId()));
    verify(agentStore, times(0)).removeAgentInstances(Collections.singletonList(instance.getId()));
    testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
    verify(agentStore, times(1)).removeAgentInstanceGroups(Collections.singletonList(instanceGroup.getId()));
    verify(agentStore, times(1)).removeAgentInstances(Collections.singletonList(instance.getId()));
}