use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method findJobsMergesAllCellsIntoSingleResult.
@Test
public void findJobsMergesAllCellsIntoSingleResult() {
Random random = new Random();
final List<Job> cellOneSnapshot = new ArrayList<>();
final List<Job> cellTwoSnapshot = new ArrayList<>();
for (int i = 0; i < 5; i++) {
cellOneSnapshot.addAll(dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
cellTwoSnapshot.addAll(dataGenerator.newBatchJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
cellOneSnapshot.addAll(dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
cellTwoSnapshot.addAll(dataGenerator.newServiceJobs(random.nextInt(10), GrpcJobManagementModelConverters::toGrpcJob));
clock.advanceTime(1, TimeUnit.MINUTES);
}
cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize()));
cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize()));
JobQuery query = JobQuery.newBuilder().setPage(toGrpcPage(Page.unlimited())).build();
final AssertableSubscriber<JobQueryResult> testSubscriber = service.findJobs(query, UNDEFINED_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoErrors().assertCompleted();
testSubscriber.assertValueCount(1);
final List<JobQueryResult> results = testSubscriber.getOnNextEvents();
assertThat(results).hasSize(1);
// expect stackName to have changed
List<Job> expected = Stream.concat(cellOneSnapshot.stream(), cellTwoSnapshot.stream()).sorted(JobManagerCursors.jobCursorOrderComparator()).map(this::withStackName).collect(Collectors.toList());
assertThat(results.get(0).getItemsList()).containsExactlyElementsOf(expected);
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method singleJobUpdates.
@Test
public void singleJobUpdates() {
Random random = new Random();
List<String> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobs(12)).stream().map(job -> job.getId()).collect(Collectors.toList());
List<String> cellTwoSnapshot = new ArrayList<>(dataGenerator.newBatchJobs(7)).stream().map(job -> job.getId()).collect(Collectors.toList());
CellWithJobIds cellOneService = new CellWithJobIds(cellOneSnapshot);
CellWithJobIds cellTwoService = new CellWithJobIds(cellTwoSnapshot);
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(cellTwoService);
String cellOneJobId = cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size()));
String cellTwoJobId = cellTwoSnapshot.get(random.nextInt(cellTwoSnapshot.size()));
assertThat(cellOneService.containsCapacityUpdates(cellOneJobId)).isFalse();
assertThat(cellTwoService.containsCapacityUpdates(cellOneJobId)).isFalse();
JobCapacityUpdate cellOneUpdate = JobCapacityUpdate.newBuilder().setJobId(cellOneJobId).setCapacity(Capacity.newBuilder().setMax(1).setDesired(2).setMax(3).build()).build();
AssertableSubscriber<Void> testSubscriber = service.updateJobCapacity(cellOneUpdate, UNDEFINED_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoErrors();
testSubscriber.assertNoValues();
testSubscriber.assertCompleted();
assertThat(cellOneService.containsCapacityUpdates(cellOneJobId)).isTrue();
assertThat(cellTwoService.containsCapacityUpdates(cellOneJobId)).isFalse();
testSubscriber.unsubscribe();
JobCapacityUpdate cellTwoUpdate = JobCapacityUpdate.newBuilder().setJobId(cellTwoJobId).setCapacity(Capacity.newBuilder().setMax(2).setDesired(2).setMax(2).build()).build();
testSubscriber = service.updateJobCapacity(cellTwoUpdate, UNDEFINED_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoErrors();
testSubscriber.assertNoValues();
testSubscriber.assertCompleted();
assertThat(cellOneService.containsCapacityUpdates(cellTwoJobId)).isFalse();
assertThat(cellTwoService.containsCapacityUpdates(cellTwoJobId)).isTrue();
testSubscriber.unsubscribe();
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method findJobsWithFailingCell.
@Test
public void findJobsWithFailingCell() {
List<Job> cellTwoSnapshot = new ArrayList<>();
for (int i = 0; i < 5; i++) {
cellTwoSnapshot.addAll(dataGenerator.newBatchJobs(5, GrpcJobManagementModelConverters::toGrpcJob));
cellTwoSnapshot.addAll(dataGenerator.newServiceJobs(5, GrpcJobManagementModelConverters::toGrpcJob));
clock.advanceTime(1, TimeUnit.MINUTES);
}
cellOne.getServiceRegistry().addService(new CellWithFailingJobManagementService());
cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize()));
JobQuery query = JobQuery.newBuilder().setPage(toGrpcPage(Page.unlimited())).build();
final AssertableSubscriber<JobQueryResult> testSubscriber = service.findJobs(query, UNDEFINED_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertError(Status.INTERNAL.asRuntimeException().getClass());
testSubscriber.assertNoValues();
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method findJob.
@Test
public void findJob() {
Random random = new Random();
List<Job> cellOneSnapshot = new ArrayList<>(dataGenerator.newServiceJobs(10, GrpcJobManagementModelConverters::toGrpcJob));
cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize()));
cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(Collections.emptyList(), cellTwoUpdates.serialize()));
Job expected = withStackName(cellOneSnapshot.get(random.nextInt(cellOneSnapshot.size())));
AssertableSubscriber<Job> testSubscriber = service.findJob(expected.getId(), UNDEFINED_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoErrors();
testSubscriber.assertValueCount(1);
testSubscriber.assertValue(expected);
}
use of com.netflix.titus.grpc.protogen.Job in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method observeJobsWaitsForAllMarkers.
@Test
public void observeJobsWaitsForAllMarkers() {
final List<Job> cellOneSnapshot = Arrays.asList(Job.newBuilder().setId("cell-1-job-1").setStatus(ACCEPTED_STATE).build(), Job.newBuilder().setId("cell-1-job-2").setStatus(ACCEPTED_STATE).build(), Job.newBuilder().setId("cell-1-job-3").setStatus(ACCEPTED_STATE).build());
final List<Job> cellTwoSnapshot = Arrays.asList(Job.newBuilder().setId("cell-2-job-1").setStatus(ACCEPTED_STATE).build(), Job.newBuilder().setId("cell-2-job-2").setStatus(ACCEPTED_STATE).build(), Job.newBuilder().setId("cell-2-job-3").setStatus(ACCEPTED_STATE).build());
cellOne.getServiceRegistry().addService(new CellWithFixedJobsService(cellOneSnapshot, cellOneUpdates.serialize()));
cellTwo.getServiceRegistry().addService(new CellWithFixedJobsService(cellTwoSnapshot, cellTwoUpdates.serialize()));
final AssertableSubscriber<JobChangeNotification> testSubscriber = service.observeJobs(ObserveJobsQuery.getDefaultInstance(), UNDEFINED_CALL_METADATA).test();
List<JobChangeNotification> expected = Stream.concat(cellOneSnapshot.stream().map(this::toNotification).map(this::withStackName), cellTwoSnapshot.stream().map(this::toNotification).map(this::withStackName)).collect(Collectors.toList());
// single marker for all cells
final JobChangeNotification mergedMarker = JobChangeNotification.newBuilder().setSnapshotEnd(SnapshotEnd.newBuilder()).build();
expected.add(mergedMarker);
testSubscriber.awaitValueCount(7, 1, TimeUnit.SECONDS);
List<JobChangeNotification> onNextEvents = testSubscriber.getOnNextEvents().stream().map(this::removeEventPropagationData).collect(Collectors.toList());
assertThat(onNextEvents).last().isEqualTo(mergedMarker);
assertThat(onNextEvents).containsExactlyInAnyOrder(expected.toArray(new JobChangeNotification[expected.size()]));
// more updates are flowing
final JobChangeNotification cellOneUpdate = toNotification(Job.newBuilder().setId("cell-1-job-10").setStatus(ACCEPTED_STATE).build());
final JobChangeNotification cellTwoUpdate = toNotification(Job.newBuilder().setId("cell-2-job-10").setStatus(ACCEPTED_STATE).build());
cellOneUpdates.onNext(cellOneUpdate);
cellTwoUpdates.onNext(cellTwoUpdate);
testSubscriber.awaitValueCount(9, 1, TimeUnit.SECONDS);
onNextEvents = testSubscriber.getOnNextEvents().stream().map(this::removeEventPropagationData).collect(Collectors.toList());
assertThat(onNextEvents).last().isNotEqualTo(mergedMarker);
assertThat(onNextEvents).contains(withStackName(cellOneUpdate), withStackName(cellTwoUpdate));
}
Aggregations