AgentStoreReaper { public static AgentInstanceGroup tagToRemove(AgentInstanceGroup instanceGroup, Scheduler scheduler) { return instanceGroup.toBuilder() .withAttributes(CollectionsExt.copyAndAdd(instanceGroup.getAttributes(), AgentStoreReaper.INSTANCE_GROUP_REMOVED_ATTRIBUTE, Long.toString(scheduler.now()))) .build(); } @Inject  AgentStoreReaper(AgentStoreReaperConfiguration configuration, AgentStore agentStore, Registry registry);  AgentStoreReaper(AgentStoreReaperConfiguration configuration, AgentStore agentStore, Registry registry, Scheduler scheduler); @Activator void enterActiveMode(); @PreDestroy void shutdown(); static boolean isTaggedToRemove(AgentInstanceGroup instanceGroup); static AgentInstanceGroup tagToRemove(AgentInstanceGroup instanceGroup, Scheduler scheduler); static final String INSTANCE_GROUP_REMOVED_ATTRIBUTE; }
@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())); }