Search in sources :

Example 1 with TestClock

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);
}
Also used : TestDataFactory(com.netflix.titus.supplementary.relocation.TestDataFactory) Archaius2Ext(com.netflix.titus.common.util.archaius2.Archaius2Ext) DisruptionBudgetGenerator.unlimitedRate(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.unlimitedRate) RelocationAttributes(com.netflix.titus.runtime.RelocationAttributes) Task(com.netflix.titus.api.jobmanager.model.job.Task) DisruptionBudgetGenerator.budget(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.budget) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) KubernetesNodeDataResolver(com.netflix.titus.supplementary.relocation.connector.KubernetesNodeDataResolver) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) RelocationConfiguration(com.netflix.titus.supplementary.relocation.RelocationConfiguration) Duration(java.time.Duration) RelocationConnectorStubs(com.netflix.titus.supplementary.relocation.RelocationConnectorStubs) JobFunctions.ofServiceSize(com.netflix.titus.api.jobmanager.model.job.JobFunctions.ofServiceSize) ReadOnlyJobOperations(com.netflix.titus.api.jobmanager.service.ReadOnlyJobOperations) TaskRelocationReason(com.netflix.titus.api.relocation.model.TaskRelocationPlan.TaskRelocationReason) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) MutableDataGenerator(com.netflix.titus.common.data.generator.MutableDataGenerator) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) DeschedulingResult(com.netflix.titus.supplementary.relocation.model.DeschedulingResult) DisruptionBudgetGenerator.selfManagedPolicy(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.selfManagedPolicy) Job(com.netflix.titus.api.jobmanager.model.job.Job) JobFunctions.withJobId(com.netflix.titus.api.jobmanager.model.job.JobFunctions.withJobId) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobFunctions.withDisruptionBudget(com.netflix.titus.api.jobmanager.model.job.JobFunctions.withDisruptionBudget) JobGenerator(com.netflix.titus.testkit.model.job.JobGenerator) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) List(java.util.List) ReadOnlyEvictionOperations(com.netflix.titus.api.eviction.service.ReadOnlyEvictionOperations) Optional(java.util.Optional) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) TestClock(com.netflix.titus.common.util.time.TestClock) Collections(java.util.Collections) TitusNode(com.netflix.titus.supplementary.relocation.connector.TitusNode) Mockito.mock(org.mockito.Mockito.mock) ReadOnlyJobOperations(com.netflix.titus.api.jobmanager.service.ReadOnlyJobOperations) KubernetesNodeDataResolver(com.netflix.titus.supplementary.relocation.connector.KubernetesNodeDataResolver) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) TestClock(com.netflix.titus.common.util.time.TestClock) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) ReadOnlyEvictionOperations(com.netflix.titus.api.eviction.service.ReadOnlyEvictionOperations) TitusNode(com.netflix.titus.supplementary.relocation.connector.TitusNode) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)

Example 2 with TestClock

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);
}
Also used : TestClock(com.netflix.titus.common.util.time.TestClock) Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Aggregations

Task (com.netflix.titus.api.jobmanager.model.job.Task)2 TaskRelocationPlan (com.netflix.titus.api.relocation.model.TaskRelocationPlan)2 TestClock (com.netflix.titus.common.util.time.TestClock)2 Test (org.junit.Test)2 ReadOnlyEvictionOperations (com.netflix.titus.api.eviction.service.ReadOnlyEvictionOperations)1 Job (com.netflix.titus.api.jobmanager.model.job.Job)1 JobFunctions.ofServiceSize (com.netflix.titus.api.jobmanager.model.job.JobFunctions.ofServiceSize)1 JobFunctions.withDisruptionBudget (com.netflix.titus.api.jobmanager.model.job.JobFunctions.withDisruptionBudget)1 JobFunctions.withJobId (com.netflix.titus.api.jobmanager.model.job.JobFunctions.withJobId)1 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)1 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)1 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)1 ReadOnlyJobOperations (com.netflix.titus.api.jobmanager.service.ReadOnlyJobOperations)1 TaskRelocationReason (com.netflix.titus.api.relocation.model.TaskRelocationPlan.TaskRelocationReason)1 MutableDataGenerator (com.netflix.titus.common.data.generator.MutableDataGenerator)1 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)1 TitusRuntimes (com.netflix.titus.common.runtime.TitusRuntimes)1 Archaius2Ext (com.netflix.titus.common.util.archaius2.Archaius2Ext)1 RelocationAttributes (com.netflix.titus.runtime.RelocationAttributes)1 AbstractTaskRelocationTest (com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest)1