use of com.spotify.helios.master.MasterModel in project helios by spotify.
the class DeadAgentReaperTest method testDeadAgentReaper.
@Test
public void testDeadAgentReaper() throws Exception {
final MasterModel masterModel = mock(MasterModel.class);
final Clock clock = mock(Clock.class);
when(clock.now()).thenReturn(new Instant(HOURS.toMillis(2000)));
final List<Datapoint> datapoints = Lists.newArrayList(new Datapoint("host1", 0, TIMEOUT_HOURS - 1, HostStatus.Status.DOWN, true), new Datapoint("host2", 0, TIMEOUT_HOURS + 1, HostStatus.Status.DOWN, false), new Datapoint("host3", 1000, 1000, HostStatus.Status.UP, false), new Datapoint("host4", 500, 300, HostStatus.Status.DOWN, true), // Agents started in the future should not be reaped, even if they are reported as down
new Datapoint("host5", 5000, 0, HostStatus.Status.DOWN, false), // they should
new Datapoint("host6", 0, 0, HostStatus.Status.UP, false));
when(masterModel.listHosts()).thenReturn(Lists.newArrayList(datapoints.stream().map(input -> input.host).collect(Collectors.toList())));
for (final Datapoint datapoint : datapoints) {
when(masterModel.isHostUp(datapoint.host)).thenReturn(HostStatus.Status.UP == datapoint.status);
when(masterModel.getAgentInfo(datapoint.host)).thenReturn(AgentInfo.newBuilder().setStartTime(datapoint.startTime).setUptime(datapoint.uptime).build());
}
final DeadAgentReaper reaper = new DeadAgentReaper(masterModel, TIMEOUT_HOURS, clock, 100, 0);
reaper.startAsync().awaitRunning();
for (final Datapoint datapoint : datapoints) {
if (datapoint.expectReap) {
verify(masterModel, timeout(500)).deregisterHost(datapoint.host);
} else {
verify(masterModel, never()).deregisterHost(datapoint.host);
}
}
}
use of com.spotify.helios.master.MasterModel in project helios by spotify.
the class JobHistoryReaperTest method testJobHistoryReaper.
@Test
public void testJobHistoryReaper() throws Exception {
final MasterModel masterModel = mock(MasterModel.class);
final List<Datapoint> datapoints = Lists.newArrayList(// A job history with a corresponding job should NOT BE reaped.
new Datapoint("job1", Job.newBuilder().setName("job1").build(), false), // A job history without a corresponding job should BE reaped.
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()));
}
}
}
use of com.spotify.helios.master.MasterModel in project helios by spotify.
the class OldJobReaperTest method testOldJobReaper.
@Test
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(// A job not deployed, with history, and last used too long ago should BE reaped
new Datapoint("job1", emptyMap(), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(22))), true), // A job not deployed, with history, and last used recently should NOT BE reaped
new Datapoint("job2", emptyMap(), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(40))), false), // A job not deployed, without history, and without a creation date should BE reaped
new Datapoint("job3", emptyMap(), emptyList(), true), // A job not deployed, without history, and created before retention time should BE reaped
new Datapoint("job4", emptyMap(), emptyList(), HOURS.toMillis(23), true), // A job not deployed, without history, created after retention time should NOT BE reaped
new Datapoint("job5", emptyMap(), emptyList(), HOURS.toMillis(25), false), // A job deployed and without history should NOT BE reaped
new Datapoint("job6", deployments(JobId.fromString("job6"), 2), emptyList(), false), // A job deployed, with history, and last used too long ago should NOT BE reaped
new Datapoint("job7", deployments(JobId.fromString("job7"), 3), events(ImmutableList.of(HOURS.toMillis(20), HOURS.toMillis(22))), false), // A job deployed, with history, and last used recently should NOT BE reaped
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, 100, 0);
reaper.startAsync().awaitRunning();
// Wait one second to give the reaper enough time to process all the jobs before verifying :(
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);
}
}
}
Aggregations