use of com.netflix.titus.common.util.time.TestClock in project titus-control-plane by Netflix.
the class DefaultDeschedulerServiceTest method verifyRelocationPlan.
private void verifyRelocationPlan(long relocationDelay, String reasonMessage) {
ReadOnlyJobOperations jobOperations = mock(ReadOnlyJobOperations.class);
DefaultDeschedulerService dds = new DefaultDeschedulerService(jobOperations, mock(ReadOnlyEvictionOperations.class), new KubernetesNodeDataResolver(configuration, TestDataFactory.mockFabric8IOConnector(), node -> true), () -> "foo|bar", titusRuntime);
Job<ServiceJobExt> job = JobGenerator.serviceJobs(oneTaskServiceJobDescriptor().but(ofServiceSize(2), withDisruptionBudget(budget(selfManagedPolicy(relocationDelay), unlimitedRate(), Collections.emptyList())))).getValue();
ServiceJobTask task = JobGenerator.serviceTasks(job).getValue();
when(jobOperations.getJob(job.getId())).thenReturn(Optional.of(job));
TitusNode node = TitusNode.newBuilder().withId("node1").withServerGroupId("asg1").withRelocationRequired(true).withBadCondition(false).build();
// Advance test clock
long clockAdvancedMs = 5_000;
TestClock testClock = (TestClock) titusRuntime.getClock();
testClock.advanceTime(Duration.ofMillis(clockAdvancedMs));
Optional<TaskRelocationPlan> relocationPlanForTask = dds.getRelocationPlanForTask(node, task, Collections.emptyMap());
assertThat(relocationPlanForTask).isPresent();
assertThat(relocationPlanForTask.get().getTaskId()).isEqualTo(task.getId());
// relocation time is expected to be decision clock time + retentionTimeMs
assertThat(relocationPlanForTask.get().getRelocationTime()).isEqualTo(relocationDelay + clockAdvancedMs);
assertThat(relocationPlanForTask.get().getDecisionTime()).isEqualTo(clockAdvancedMs);
assertThat(relocationPlanForTask.get().getReasonMessage()).isEqualTo(reasonMessage);
}
use of com.netflix.titus.common.util.time.TestClock in project titus-control-plane by Netflix.
the class MustBeRelocatedSelfManagedTaskCollectorStepTest method testOriginalPlanIsReturnedOnEachInvocation.
@Test
public void testOriginalPlanIsReturnedOnEachInvocation() {
Job<BatchJobExt> job = TestDataFactory.newBatchJob("job1", 1, newSelfManagedDisruptionBudget(1_000));
relocationConnectorStubs.addJob(job);
Task task = jobOperations.getTasks().get(0);
relocationConnectorStubs.place(TestDataFactory.REMOVABLE_INSTANCE_GROUP_ID, task);
Map<String, TaskRelocationPlan> firstResult = step.collectTasksThatMustBeRelocated();
assertThat(firstResult).hasSize(1);
TaskRelocationPlan first = firstResult.get(task.getId());
((TestClock) titusRuntime.getClock()).advanceTime(1, TimeUnit.SECONDS);
Map<String, TaskRelocationPlan> secondResult = step.collectTasksThatMustBeRelocated();
assertThat(secondResult).hasSize(1);
TaskRelocationPlan second = secondResult.get(task.getId());
assertThat(first).isEqualTo(second);
}
Aggregations