@Test
public void testClusterAgentRemoval() {

    AgentInstanceGroup instanceGroup = createInstanceGroup(0);
    when(agentManagementService.getInstanceGroups()).thenReturn(singletonList(instanceGroup));
    AgentInstance agentInstance1 = createRemovableInstance("instanceGroup1", "agentInstance1");
    AgentInstance agentInstance2 = createActiveInstance("instanceGroup1", "agentInstance1");
    List<AgentInstance> agentInstances = asList(agentInstance1, agentInstance2);
    when(agentManagementService.getAgentInstances("instanceGroup1")).thenReturn(agentInstances);
    when(agentManagementService.terminateAgents("instanceGroup1", singletonList("agentInstance1"), true))
            .thenReturn(Observable.just(singletonList(Either.ofValue(true))));
    Task task = createTask("agentInstance2");
    when(v3JobOperations.getTasks()).thenReturn(singletonList(task));
    testScheduler.advanceTimeBy(6, TimeUnit.MINUTES);
    ClusterRemovableAgentRemover clusterRemovableAgentRemover = new ClusterRemovableAgentRemover(titusRuntime, configuration,
            agentManagementService, v3JobOperations, testScheduler);
    clusterRemovableAgentRemover.doRemoveAgents().await();
    verify(agentManagementService).terminateAgents("instanceGroup1", singletonList("agentInstance1"), true);
}