Source:
<code>public void testOldJobReaper() throws Exception { final MasterModel masterModel = mock(MasterModel.class); final Clock clock = mock(Clock.class); when(clock.now()).thenReturn(new Instant(HOURS.toMillis(48))); final List<Datapoint> datapoints = Lists.newArrayList( new Datapoint("job1", emptyMap(), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(22))), true), new Datapoint("job2", emptyMap(), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(40))), false), new Datapoint("job3", emptyMap(), emptyList(), false), new Datapoint("job4", deployments(JobId.fromString("job4"), 2), emptyList(), false), new Datapoint("job5", deployments(JobId.fromString("job5"), 3), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(22))), false), new Datapoint("job6", deployments(JobId.fromString("job6"), 3), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(40))), false) ); when(masterModel.getJobs()).thenReturn( datapoints.stream().collect(Collectors.toMap(Datapoint::getJobId, Datapoint::getJob))); for (final Datapoint datapoint : datapoints) { when(masterModel.getJobHistory(datapoint.getJobId())).thenReturn(datapoint.getHistory()); when(masterModel.getJobStatus(datapoint.getJobId())).thenReturn(datapoint.getJobStatus()); } final OldJobReaper reaper = new OldJobReaper(masterModel, RETENTION_DAYS, clock); reaper.startAsync().awaitRunning(); <START> verify(masterModel, timeout(5000).atLeastOnce()).getJobs(); <END> for (final Datapoint datapoint : datapoints) { if (datapoint.expectReap) { verify(masterModel, timeout(500)).removeJob(datapoint.getJobId(), Job.EMPTY_TOKEN); } } }</code><technical_language>is this needed? stubbed behavior</technical_language>

Target:
public void testOldJobReaper() throws Exception { final MasterModel masterModel = mock(MasterModel.class); final Clock clock = mock(Clock.class); when(clock.now()).thenReturn(new Instant(HOURS.toMillis(48))); final List<Datapoint> datapoints = Lists.newArrayList( new Datapoint("job1", emptyMap(), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(22))), true), new Datapoint("job2", emptyMap(), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(40))), false), new Datapoint("job3", emptyMap(), emptyList(), true), new Datapoint("job4", emptyMap(), emptyList(), HOURS.toMillis(23), true), new Datapoint("job5", emptyMap(), emptyList(), HOURS.toMillis(25), false), new Datapoint("job6", deployments(JobId.fromString("job6"), 2), emptyList(), false), new Datapoint("job7", deployments(JobId.fromString("job7"), 3), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(22))), false), new Datapoint("job8", deployments(JobId.fromString("job8"), 3), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(40))), false) ); when(masterModel.getJobs()).thenReturn( datapoints.stream().collect(Collectors.toMap(Datapoint::getJobId, Datapoint::getJob))); for (final Datapoint datapoint : datapoints) { when(masterModel.getJobHistory(datapoint.getJobId())).thenReturn(datapoint.getHistory()); when(masterModel.getJobStatus(datapoint.getJobId())).thenReturn(datapoint.getJobStatus()); } final OldJobReaper reaper = new OldJobReaper(masterModel, RETENTION_DAYS, clock); reaper.startAsync().awaitRunning(); Thread.sleep(1000); for (final Datapoint datapoint : datapoints) { if (datapoint.expectReap) { verify(masterModel, timeout(500)).removeJob(datapoint.getJobId(), Job.EMPTY_TOKEN); } else { verify(masterModel, never()).removeJob(datapoint.getJobId(), Job.EMPTY_TOKEN); } } }