.setOwner(new Identity().setRole("role").setUser("role"))));
}
@Test
public void testMaintenanceCycle() {
ScheduledTask task = makeTask(HOST_A, "taskA");
expectMaintenanceModeChange(HOST_A, SCHEDULED);
expectFetchTasksByHost(HOST_A, ImmutableSet.of(task));
expect(stateManager.changeState(
Tasks.id(task),
Optional.<ScheduleStatus>absent(),
ScheduleStatus.DRAINING,
MaintenanceControllerImpl.DRAINING_MESSAGE))
.andReturn(true);
expectMaintenanceModeChange(HOST_A, DRAINING);
expect(storageUtil.attributeStore.getHostAttributes(HOST_A)).andReturn(Optional.of(
IHostAttributes.build(new HostAttributes().setHost(HOST_A).setMode(DRAINING))));
// TaskA is FINISHED and therefore no longer active
expectFetchTasksByHost(HOST_A, ImmutableSet.<ScheduledTask>of());
expectMaintenanceModeChange(HOST_A, DRAINED);
expectMaintenanceModeChange(HOST_A, NONE);
control.replay();
assertStatus(HOST_A, SCHEDULED, maintenance.startMaintenance(A));
assertStatus(HOST_A, DRAINING, maintenance.drain(A));
eventSink.post(
TaskStateChange.transition(IScheduledTask.build(task.setStatus(FINISHED)), RUNNING));
assertStatus(HOST_A, NONE, maintenance.endMaintenance(A));
}