use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class TaskDataInjectorTest method testFindTasksWithRelocationDeadline.
@Test
public void testFindTasksWithRelocationDeadline() {
long deadline1 = titusRuntime.getClock().wallTime() + 1_000;
long deadline2 = titusRuntime.getClock().wallTime() + 2_000;
TaskQueryResult queryResult = TaskQueryResult.newBuilder().addItems(TASK1).addItems(TASK2).build();
when(relocationDataReplicator.getCurrent()).thenReturn(newRelocationSnapshot(newRelocationPlan(TASK1, deadline1), newRelocationPlan(TASK2, deadline2)));
TaskQueryResult merged = Observable.just(queryResult).map(queryResult1 -> taskDataInjector.injectIntoTaskQueryResult(queryResult1)).toBlocking().first();
assertThat(merged.getItems(0).getMigrationDetails().getNeedsMigration()).isTrue();
assertThat(merged.getItems(0).getMigrationDetails().getDeadline()).isEqualTo(deadline1);
assertThat(merged.getItems(1).getMigrationDetails().getNeedsMigration()).isTrue();
assertThat(merged.getItems(1).getMigrationDetails().getDeadline()).isEqualTo(deadline2);
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class GatewayJobServiceGatewayTest method testCombineActiveAndArchiveTaskResultSet.
private void testCombineActiveAndArchiveTaskResultSet(Function<Pagination, TaskQuery> queryFunction, Function<Integer, TaskQueryResult> activePageResultFunction) {
// First page
TaskQueryResult combinedResult = testCombineForFirstPage();
// Iterate using page numbers
// Archive tasks first.
Pagination lastPagination = combinedResult.getPagination();
for (int p = 1; p < ARCHIVED_TASKS_COUNT / PAGE_SIZE; p++) {
TaskQuery cursorQuery = queryFunction.apply(lastPagination);
TaskQueryResult cursorResult = GatewayJobServiceGateway.combineTaskResults(cursorQuery, activePageResultFunction.apply(0), ARCHIVED_TASKS);
checkCombinedResult(cursorResult, ARCHIVED_TASKS.subList(p * PAGE_SIZE, (p + 1) * PAGE_SIZE));
lastPagination = cursorResult.getPagination();
}
// Now fetch the active data
for (int p = 0; p < JOB_SIZE / PAGE_SIZE; p++) {
TaskQuery cursorQuery = queryFunction.apply(lastPagination);
TaskQueryResult cursorResult = GatewayJobServiceGateway.combineTaskResults(cursorQuery, activePageResultFunction.apply(p), ARCHIVED_TASKS);
checkCombinedResult(cursorResult, ACTIVE_TASKS.subList(p * PAGE_SIZE, (p + 1) * PAGE_SIZE));
lastPagination = cursorResult.getPagination();
}
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testPagination.
@Test(timeout = 30_000)
public void testPagination() {
// We have 3 batch and 3 service jobs.
Page firstPageOf5 = Page.newBuilder().setPageNumber(0).setPageSize(5).build();
Page secondPageOf5 = Page.newBuilder().setPageNumber(1).setPageSize(5).build();
// Jobs
JobQuery.Builder jobQueryBuilder = JobQuery.newBuilder().putFilteringCriteria("attributes", PRE_CREATED_JOBS_LABEL);
JobQueryResult jobQueryResult = client.findJobs(jobQueryBuilder.setPage(firstPageOf5).build());
assertThat(jobQueryResult.getItemsList()).hasSize(5);
checkPage(jobQueryResult.getPagination(), firstPageOf5, 2, 6, true);
JobQueryResult jobQueryResult2 = client.findJobs(jobQueryBuilder.setPage(secondPageOf5).build());
assertThat(jobQueryResult2.getItemsList()).hasSize(1);
checkPage(jobQueryResult2.getPagination(), secondPageOf5, 2, 6, false);
Set<String> foundJobIds = new HashSet<>();
jobQueryResult.getItemsList().forEach(j -> foundJobIds.add(j.getId()));
jobQueryResult2.getItemsList().forEach(j -> foundJobIds.add(j.getId()));
assertThat(foundJobIds).hasSize(6);
// Tasks
TaskQuery.Builder taskQueryBuilder = TaskQuery.newBuilder().putFilteringCriteria("attributes", PRE_CREATED_JOBS_LABEL);
TaskQueryResult taskQueryResult = client.findTasks(taskQueryBuilder.setPage(firstPageOf5).build());
assertThat(taskQueryResult.getItemsList()).hasSize(5);
checkPage(taskQueryResult.getPagination(), firstPageOf5, 2, 6, true);
TaskQueryResult taskQueryResult2 = client.findTasks(taskQueryBuilder.setPage(secondPageOf5).build());
assertThat(taskQueryResult2.getItemsList()).hasSize(1);
checkPage(taskQueryResult2.getPagination(), secondPageOf5, 2, 6, false);
Set<String> foundTasksIds = new HashSet<>();
taskQueryResult.getItemsList().forEach(j -> foundTasksIds.add(j.getId()));
taskQueryResult2.getItemsList().forEach(j -> foundTasksIds.add(j.getId()));
assertThat(foundTasksIds).hasSize(6);
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testSearchByTaskStateV3.
private void testSearchByTaskStateV3(String taskState, String expectedJobId, String expectedTaskId) {
// Job
JobQueryResult jobQueryResult = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByTaskStateV3").putFilteringCriteria("taskStates", taskState).setPage(PAGE).build());
assertThat(jobQueryResult.getItemsList()).hasSize(1);
Job jobQueryResultItem = jobQueryResult.getItems(0);
assertThat(jobQueryResultItem.getId()).isEqualTo(expectedJobId);
// Task
TaskQueryResult taskQueryResult = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("applicationName", "testSearchByTaskStateV3").putFilteringCriteria("taskStates", taskState).setPage(PAGE).build());
assertThat(taskQueryResult.getItemsList()).hasSize(1);
assertThat(taskQueryResult.getItems(0).getId()).isEqualTo(expectedTaskId);
}
use of com.netflix.titus.grpc.protogen.TaskQueryResult in project titus-control-plane by Netflix.
the class JobCriteriaQueryTest method testFindJobAndTaskByTaskIdsV3.
@Test(timeout = 30_000)
public void testFindJobAndTaskByTaskIdsV3() {
String task0 = jobsScenarioBuilder.takeJob(batchJobsWithCreatedTasks.get(0)).getTaskByIndex(0).getTask().getId();
String task2 = jobsScenarioBuilder.takeJob(batchJobsWithCreatedTasks.get(2)).getTaskByIndex(0).getTask().getId();
// Jobs
JobQueryResult jobQueryResult = client.findJobs(JobQuery.newBuilder().putFilteringCriteria("taskIds", task0 + ',' + task2).setPage(PAGE).build());
final List<Job> itemsList = jobQueryResult.getItemsList();
assertThat(itemsList).hasSize(2);
// Tasks
TaskQueryResult taskQueryResult = client.findTasks(TaskQuery.newBuilder().putFilteringCriteria("taskIds", task0 + ',' + task2).setPage(PAGE).build());
assertThat(taskQueryResult.getItemsList()).hasSize(2);
}
Aggregations