### Question:
JobHistoryReaper extends RateLimitedService<String> { public JobHistoryReaper(final MasterModel masterModel, final ZooKeeperClient client) { this(masterModel, client, PERMITS_PER_SECOND, new Random().nextInt(DELAY)); } JobHistoryReaper(final MasterModel masterModel,
                          final ZooKeeperClient client); @VisibleForTesting  JobHistoryReaper(final MasterModel masterModel,
                   final ZooKeeperClient client,
                   final double permitsPerSecond,
                   final int initialDelay);   }### Answer:
@Test public void testJobHistoryReaper() throws Exception { final MasterModel masterModel = mock(MasterModel.class); final List<Datapoint> datapoints = Lists.newArrayList( new Datapoint("job1", Job.newBuilder().setName("job1").build(), false), new Datapoint("job2", null, true) ); for (final Datapoint dp : datapoints) { when(masterModel.getJob(argThat(matchesName(dp.getJobName())))).thenReturn(dp.getJob()); } final ZooKeeperClient client = mock(ZooKeeperClient.class); final List<String> jobHistories = ImmutableList.of("job1", "job2"); when(client.getChildren(Paths.historyJobs())).thenReturn(jobHistories); final JobHistoryReaper reaper = new JobHistoryReaper(masterModel, client, 100, 0); reaper.startAsync().awaitRunning(); for (final Datapoint datapoint : datapoints) { if (datapoint.expectReap) { verify(client, timeout(500)).deleteRecursive(Paths.historyJob(datapoint.getJobId())); } else { verify(client, never()).deleteRecursive(Paths.historyJob(datapoint.getJobId())); } } }