Search in sources :

Example 1 with JobScenarioBuilder

use of com.netflix.titus.master.integration.v3.scenario.JobScenarioBuilder in project titus-control-plane by Netflix.

the class V3JobSchedulingAndRebootTest method submitBatchJobAndRebootTitusMaster.

@Test(timeout = LONG_TEST_TIMEOUT_MS)
public void submitBatchJobAndRebootTitusMaster() {
    jobsScenarioBuilder.schedule(ONE_TASK_BATCH_JOB, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.startTasksInNewJob()));
    jobsScenarioBuilder.stop();
    titusStackResource.getMaster().reboot();
    JobsScenarioBuilder newJobsScenarioBuilder = new JobsScenarioBuilder(titusStackResource.getOperations());
    newJobsScenarioBuilder.assertJobs(jobs -> jobs.size() == 1).takeJob(0).assertJob(JobAsserts.jobInState(JobState.Accepted)).assertTasks(tasks -> tasks.size() == 1);
}
Also used : BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) JobAsserts(com.netflix.titus.master.integration.v3.scenario.JobAsserts) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) V3_ENGINE_APP_PREFIX(com.netflix.titus.testkit.junit.master.TitusStackResource.V3_ENGINE_APP_PREFIX) Category(org.junit.experimental.categories.Category) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) Rule(org.junit.Rule) EmbeddedTitusCells.basicKubeCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCells.basicKubeCell) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 2 with JobScenarioBuilder

use of com.netflix.titus.master.integration.v3.scenario.JobScenarioBuilder in project titus-control-plane by Netflix.

the class JobIpAllocationsTest method testWaitingTaskContext.

/**
 * Tests a job waiting for an in use IP allocation has updated task context fields.
 */
@Test(timeout = 30_000)
// TODO Read static IP allocation status from pod message field, and add it to the task context.
@Ignore
public void testWaitingTaskContext() throws Exception {
    JobDescriptor<ServiceJobExt> firstIpJobDescriptor = ONE_TASK_SERVICE_JOB;
    JobDescriptor<ServiceJobExt> secondIpJobDescriptor = firstIpJobDescriptor.but(j -> j.getJobGroupInfo().toBuilder().withSequence("v001"));
    // Schedule the first task and ensure it's in the correct zone with the correct task context
    jobsScenarioBuilder.schedule(firstIpJobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.startTasksInNewJob()).allTasks(taskScenarioBuilder -> taskScenarioBuilder.expectTaskContext(TaskAttributes.TASK_ATTRIBUTES_IP_ALLOCATION_ID, getIpAllocationIdFromJob(0, firstIpJobDescriptor))).allTasks(taskScenarioBuilder -> taskScenarioBuilder.expectZoneId(getZoneFromJobIpAllocation(0, firstIpJobDescriptor))));
    String firstJobId = jobsScenarioBuilder.takeJob(0).getJobId();
    // Schedule the second task and ensure it's blocked on the first task
    jobsScenarioBuilder.schedule(secondIpJobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.jobAccepted()).expectAllTasksCreated().allTasks(taskScenarioBuilder -> taskScenarioBuilder.expectStateUpdates(TaskStatus.TaskState.Accepted)));
    String secondJobId = jobsScenarioBuilder.takeJob(1).getJobId();
    // Query the gRPC endpoint and ensure the first task does not have a waiting task context field.
    TaskQueryResult firstTaskQueryResult = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(100).build()).putFilteringCriteria("jobIds", firstJobId).build());
    assertThat(firstTaskQueryResult.getItemsCount()).isEqualTo(1);
    firstTaskQueryResult.getItemsList().forEach(task -> {
        assertThat(task.getTaskContextMap()).doesNotContainKeys(TaskAttributes.TASK_ATTRIBUTES_IN_USE_IP_ALLOCATION);
    });
    String firstTaskId = firstTaskQueryResult.getItems(0).getId();
    // Query the gRPC endpoint and ensure the second task has a waiting task context field.
    TaskQueryResult secondTaskQueryResult = client.findTasks(TaskQuery.newBuilder().setPage(Page.newBuilder().setPageSize(100).build()).putFilteringCriteria("jobIds", secondJobId).build());
    assertThat(secondTaskQueryResult.getItemsCount()).isEqualTo(1);
    secondTaskQueryResult.getItemsList().forEach(task -> {
        assertThat(task.getTaskContextMap()).contains(new AbstractMap.SimpleImmutableEntry<>(TaskAttributes.TASK_ATTRIBUTES_IN_USE_IP_ALLOCATION, firstTaskId));
    });
    // Observe the second job and ensure the streamed task has a waiting task context field.
    boolean verified = false;
    Iterator<JobChangeNotification> it = client.observeJob(JobId.newBuilder().setId(secondJobId).build());
    while (it.hasNext()) {
        JobChangeNotification jobChangeNotification = it.next();
        if (jobChangeNotification.hasTaskUpdate()) {
            Map<String, String> taskContext = jobChangeNotification.getTaskUpdate().getTask().getTaskContextMap();
            assertThat(taskContext).contains(new AbstractMap.SimpleImmutableEntry<>(TaskAttributes.TASK_ATTRIBUTES_IN_USE_IP_ALLOCATION, firstTaskId));
            verified = true;
        } else if (jobChangeNotification.hasSnapshotEnd()) {
            break;
        }
    }
    assertThat(verified).isTrue();
}
Also used : TaskScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.TaskScenarioBuilder) JobDescriptorGenerator.serviceJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.serviceJobDescriptors) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) Function(java.util.function.Function) TaskStatus(com.netflix.titus.grpc.protogen.TaskStatus) SignedIpAddressAllocation(com.netflix.titus.api.jobmanager.model.job.vpc.SignedIpAddressAllocation) Map(java.util.Map) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) GrpcJobManagementModelConverters.toGrpcJobDescriptor(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcJobDescriptor) JobTestUtils.submitBadJob(com.netflix.titus.master.integration.v3.job.JobTestUtils.submitBadJob) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) Before(org.junit.Before) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) Iterator(java.util.Iterator) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Page(com.netflix.titus.grpc.protogen.Page) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) AbstractMap(java.util.AbstractMap) List(java.util.List) Rule(org.junit.Rule) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) Ignore(org.junit.Ignore) JobIpAllocationGenerator(com.netflix.titus.testkit.model.job.JobIpAllocationGenerator) EmbeddedTitusCells.basicKubeCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCells.basicKubeCell) TaskAttributes(com.netflix.titus.api.jobmanager.TaskAttributes) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobId(com.netflix.titus.grpc.protogen.JobId) AbstractMap(java.util.AbstractMap) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Ignore(org.junit.Ignore) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 3 with JobScenarioBuilder

use of com.netflix.titus.master.integration.v3.scenario.JobScenarioBuilder in project titus-control-plane by Netflix.

the class JobCriteriaQueryTest method testSearchByJobState.

@Test(timeout = 30_000)
public void testSearchByJobState() throws Exception {
    JobDescriptor<BatchJobExt> jobDescriptor = batchJobDescriptors().getValue().toBuilder().withApplicationName("testSearchByJobState").build();
    String acceptedJobId = jobsScenarioBuilder.scheduleAndReturnJob(jobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob())).getId();
    String killInitiatedJobId = jobsScenarioBuilder.scheduleAndReturnJob(jobDescriptor, jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob()).killJob().expectJobUpdateEvent(job -> job.getStatus().getState() == JobState.KillInitiated, "Expected state: " + JobState.KillInitiated)).getId();
    String acceptedTaskId = jobsScenarioBuilder.takeJob(acceptedJobId).getTaskByIndex(0).getTask().getId();
    String killInitiatedTaskId = jobsScenarioBuilder.takeJob(killInitiatedJobId).getTaskByIndex(0).getTask().getId();
    // Indexes are recomputed after events are sent, so if we run findJobs/findTasks immediately, they may use stale index.
    Thread.sleep(10);
    JobQuery.Builder jobQueryBuilder = JobQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByJobState").setPage(PAGE);
    TaskQuery.Builder taskQueryBuilder = TaskQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByJobState").setPage(PAGE);
    // Jobs (Accepted)
    JobQueryResult acceptedJobQueryResult = client.findJobs(jobQueryBuilder.putFilteringCriteria("jobState", "Accepted").build());
    assertThat(acceptedJobQueryResult.getItemsList()).hasSize(1);
    Job acceptedJobQueryResultItem = acceptedJobQueryResult.getItems(0);
    assertThat(acceptedJobQueryResultItem.getId()).isEqualTo(acceptedJobId);
    // Jobs (KillInitiated)
    JobQueryResult killInitJobQueryResult = client.findJobs(jobQueryBuilder.putFilteringCriteria("jobState", "KillInitiated").setPage(PAGE).build());
    assertThat(killInitJobQueryResult.getItemsList()).hasSize(1);
    Job killInitJobQueryResultItem = killInitJobQueryResult.getItems(0);
    assertThat(killInitJobQueryResultItem.getId()).isEqualTo(killInitiatedJobId);
    // Tasks (Accepted)
    TaskQueryResult acceptedTaskQueryResult = client.findTasks(taskQueryBuilder.putFilteringCriteria("jobState", "Accepted").setPage(PAGE).build());
    assertThat(acceptedTaskQueryResult.getItemsList()).hasSize(1);
    assertThat(acceptedTaskQueryResult.getItems(0).getId()).isEqualTo(acceptedTaskId);
    // Tasks (KillInitiated)
    TaskQueryResult killInitTaskQueryResult = client.findTasks(taskQueryBuilder.putFilteringCriteria("jobState", "KillInitiated").setPage(PAGE).build());
    assertThat(killInitTaskQueryResult.getItemsList()).hasSize(1);
    assertThat(killInitTaskQueryResult.getItems(0).getId()).isEqualTo(killInitiatedTaskId);
}
Also used : TaskScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.TaskScenarioBuilder) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) EmbeddedTitusMasters(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMasters) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) EmbeddedKubeClusters(com.netflix.titus.testkit.embedded.kube.EmbeddedKubeClusters) ClassRule(org.junit.ClassRule) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) ImmutableMap(com.google.common.collect.ImmutableMap) PlatformSidecar(com.netflix.titus.api.jobmanager.model.job.PlatformSidecar) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Task(com.netflix.titus.grpc.protogen.Task) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) Set(java.util.Set) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) Page(com.netflix.titus.grpc.protogen.Page) List(java.util.List) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) CellAssertions.assertCellInfo(com.netflix.titus.master.integration.v3.job.CellAssertions.assertCellInfo) BeforeClass(org.junit.BeforeClass) Job(com.netflix.titus.grpc.protogen.Job) Image(com.netflix.titus.api.jobmanager.model.job.Image) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Owner(com.netflix.titus.api.jobmanager.model.job.Owner) TaskStatus(com.netflix.titus.grpc.protogen.TaskStatus) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Test(org.junit.Test) Pagination(com.netflix.titus.grpc.protogen.Pagination) JobScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobScenarioBuilder) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) EmbeddedTitusMaster(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMaster) EmbeddedTitusCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCell) Collections(java.util.Collections) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Job(com.netflix.titus.grpc.protogen.Job) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 4 with JobScenarioBuilder

use of com.netflix.titus.master.integration.v3.scenario.JobScenarioBuilder in project titus-control-plane by Netflix.

the class JobCriteriaQueryTest method testSearchByCellV3.

@Test(timeout = 30_000)
public void testSearchByCellV3() {
    final int numberOfJobs = 3;
    String[] expectedJobIds = new String[numberOfJobs];
    String[] expectedTaskIds = new String[numberOfJobs];
    for (int i = 0; i < numberOfJobs; i++) {
        String jobId = jobsScenarioBuilder.scheduleAndReturnJob(BATCH_JOB_TEMPLATE.toBuilder().withApplicationName("testSearchByCellV3").build(), jobScenarioBuilder -> jobScenarioBuilder.template(ScenarioTemplates.launchJob())).getId();
        expectedJobIds[i] = jobId;
        expectedTaskIds[i] = jobsScenarioBuilder.takeJob(jobId).getTaskByIndex(0).getTask().getId();
    }
    // Jobs
    JobQuery.Builder jobQueryBuilder = JobQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByCellV3").setPage(PAGE);
    JobQueryResult jobs1 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", "titus.cell,titus.stack").putFilteringCriteria("attributes.op", "or").build());
    assertContainsJobs(jobs1, expectedJobIds);
    jobs1.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
    JobQueryResult jobs2 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", "titus.cell").putFilteringCriteria("attributes.op", "and").build());
    assertContainsJobs(jobs2, expectedJobIds);
    jobs2.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
    JobQueryResult jobs3 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s,titus.stack:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "or").build());
    assertContainsJobs(jobs3, expectedJobIds);
    jobs3.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
    JobQueryResult jobs4 = client.findJobs(jobQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "and").build());
    assertContainsJobs(jobs4, expectedJobIds);
    jobs4.getItemsList().forEach(job -> assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME));
    // Tasks
    TaskQuery.Builder taskQueryBuilder = TaskQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByCellV3").setPage(PAGE);
    TaskQueryResult tasks1 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", "titus.cell,titus.stack").putFilteringCriteria("attributes.op", "or").build());
    assertContainsTasks(tasks1, expectedTaskIds);
    tasks1.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
    TaskQueryResult tasks2 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", "titus.cell").putFilteringCriteria("attributes.op", "and").build());
    assertContainsTasks(tasks2, expectedTaskIds);
    tasks2.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
    TaskQueryResult tasks3 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s,titus.stack:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "or").build());
    assertContainsTasks(tasks3, expectedTaskIds);
    tasks3.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
    final TaskQueryResult tasks4 = client.findTasks(taskQueryBuilder.putFilteringCriteria("attributes", String.format("titus.cell:%1$s", EmbeddedTitusMaster.CELL_NAME)).putFilteringCriteria("attributes.op", "and").build());
    assertContainsTasks(tasks4, expectedTaskIds);
    tasks4.getItemsList().forEach(task -> assertCellInfo(task, EmbeddedTitusMaster.CELL_NAME));
}
Also used : TaskScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.TaskScenarioBuilder) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) EmbeddedTitusMasters(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMasters) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) JobGroupInfo(com.netflix.titus.api.jobmanager.model.job.JobGroupInfo) JobState(com.netflix.titus.api.jobmanager.model.job.JobState) EmbeddedKubeClusters(com.netflix.titus.testkit.embedded.kube.EmbeddedKubeClusters) ClassRule(org.junit.ClassRule) JobDescriptorGenerator.oneTaskServiceJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskServiceJobDescriptor) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) ImmutableMap(com.google.common.collect.ImmutableMap) PlatformSidecar(com.netflix.titus.api.jobmanager.model.job.PlatformSidecar) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) Task(com.netflix.titus.grpc.protogen.Task) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) Set(java.util.Set) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) Page(com.netflix.titus.grpc.protogen.Page) List(java.util.List) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) CellAssertions.assertCellInfo(com.netflix.titus.master.integration.v3.job.CellAssertions.assertCellInfo) BeforeClass(org.junit.BeforeClass) Job(com.netflix.titus.grpc.protogen.Job) Image(com.netflix.titus.api.jobmanager.model.job.Image) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) Owner(com.netflix.titus.api.jobmanager.model.job.Owner) TaskStatus(com.netflix.titus.grpc.protogen.TaskStatus) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) JobManagementServiceGrpc(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc) Test(org.junit.Test) Pagination(com.netflix.titus.grpc.protogen.Pagination) JobScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobScenarioBuilder) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) EmbeddedTitusMaster(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMaster) EmbeddedTitusCell(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCell) Collections(java.util.Collections) TaskQuery(com.netflix.titus.grpc.protogen.TaskQuery) JobQuery(com.netflix.titus.grpc.protogen.JobQuery) TaskQueryResult(com.netflix.titus.grpc.protogen.TaskQueryResult) JobQueryResult(com.netflix.titus.grpc.protogen.JobQueryResult) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 5 with JobScenarioBuilder

use of com.netflix.titus.master.integration.v3.scenario.JobScenarioBuilder in project titus-control-plane by Netflix.

the class JobObserveTest method observeJobs.

@Test(timeout = LONG_TEST_TIMEOUT_MS)
public void observeJobs() throws InterruptedException {
    TestStreamObserver<JobChangeNotification> subscriber = subscribe(ObserveJobsQuery.getDefaultInstance());
    for (int i = 0; i < 2; i++) {
        String jobId = jobsScenarioBuilder.scheduleAndReturnJob(oneTaskBatchJobDescriptor(), jobScenarioBuilder -> jobScenarioBuilder.template(startTasksInNewJob()).template(ScenarioTemplates.killJob())).getId();
        JobChangeNotification event;
        while (true) {
            event = subscriber.takeNext(SHORT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
            if (event.hasJobUpdate()) {
                Job job = event.getJobUpdate().getJob();
                assertThat(job.getId()).isEqualTo(jobId);
                CellAssertions.assertCellInfo(job, EmbeddedTitusMaster.CELL_NAME);
                if (job.getStatus().getState() == JobState.Finished) {
                    break;
                }
            }
        }
    }
    subscriber.cancel();
}
Also used : Arrays(java.util.Arrays) JobDescriptorGenerator.serviceJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.serviceJobDescriptors) JobModel(com.netflix.titus.api.jobmanager.model.job.JobModel) ObserveJobsQuery(com.netflix.titus.grpc.protogen.ObserveJobsQuery) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Job(com.netflix.titus.grpc.protogen.Job) ScenarioTemplates(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates) ScenarioTemplates.startTasksInNewJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.startTasksInNewJob) Image(com.netflix.titus.grpc.protogen.Image) ScenarioTemplates.killJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.killJob) JobState(com.netflix.titus.grpc.protogen.JobStatus.JobState) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) Owner(com.netflix.titus.api.jobmanager.model.job.Owner) SERVICE(com.netflix.titus.grpc.protogen.JobDescriptor.JobSpecCase.SERVICE) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) TaskState(com.netflix.titus.grpc.protogen.TaskStatus.TaskState) EmbeddedTitusCells(com.netflix.titus.testkit.embedded.cell.EmbeddedTitusCells) ImmutableMap(com.google.common.collect.ImmutableMap) Task(com.netflix.titus.grpc.protogen.Task) JobDescriptorGenerator.oneTaskBatchJobDescriptor(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor) CellAssertions(com.netflix.titus.master.integration.v3.job.CellAssertions) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) RuleChain(org.junit.rules.RuleChain) TitusStackResource(com.netflix.titus.testkit.junit.master.TitusStackResource) Rule(org.junit.Rule) JobDescriptorGenerator.batchJobDescriptors(com.netflix.titus.testkit.model.job.JobDescriptorGenerator.batchJobDescriptors) EmbeddedTitusMaster(com.netflix.titus.testkit.embedded.cell.master.EmbeddedTitusMaster) JobsScenarioBuilder(com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) JobChangeNotification(com.netflix.titus.grpc.protogen.JobChangeNotification) Job(com.netflix.titus.grpc.protogen.Job) ScenarioTemplates.startTasksInNewJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.startTasksInNewJob) ScenarioTemplates.killJob(com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates.killJob) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Aggregations

JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)7 TitusStackResource (com.netflix.titus.testkit.junit.master.TitusStackResource)7 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)6 JobsScenarioBuilder (com.netflix.titus.master.integration.v3.scenario.JobsScenarioBuilder)6 ScenarioTemplates (com.netflix.titus.master.integration.v3.scenario.ScenarioTemplates)6 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)6 Test (org.junit.Test)6 Category (org.junit.experimental.categories.Category)6 RuleChain (org.junit.rules.RuleChain)6 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)5 JobDescriptorGenerator.oneTaskBatchJobDescriptor (com.netflix.titus.testkit.model.job.JobDescriptorGenerator.oneTaskBatchJobDescriptor)5 List (java.util.List)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)4 JobManagementServiceGrpc (com.netflix.titus.grpc.protogen.JobManagementServiceGrpc)4 Page (com.netflix.titus.grpc.protogen.Page)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)3 JobState (com.netflix.titus.api.jobmanager.model.job.JobState)3 Owner (com.netflix.titus.api.jobmanager.model.job.Owner)3