use of com.netflix.titus.grpc.protogen.LoadBalancerId in project titus-control-plane by Netflix.
the class AggregatingLoadBalancerServiceTest method addLoadBalancer.
@Test
public void addLoadBalancer() {
JobLoadBalancer jobLoadBalancer1 = new JobLoadBalancer(JOB_1, LB_1);
JobLoadBalancer jobLoadBalancer2 = new JobLoadBalancer(JOB_2, LB_2);
final CellWithLoadBalancers cellWithLoadBalancersOne = new CellWithLoadBalancers(singletonList(jobLoadBalancer1));
final CellWithLoadBalancers cellWithLoadBalancersTwo = new CellWithLoadBalancers(new ArrayList<>(singletonList(jobLoadBalancer2)));
final CellWithJobIds cellWithJobIdsOne = new CellWithJobIds(singletonList(JOB_1));
final CellWithJobIds cellWithJobIdsTwo = new CellWithJobIds(singletonList(JOB_2));
cellOne.getServiceRegistry().addService(cellWithLoadBalancersOne);
cellOne.getServiceRegistry().addService(cellWithJobIdsOne);
cellTwo.getServiceRegistry().addService(cellWithLoadBalancersTwo);
cellTwo.getServiceRegistry().addService(cellWithJobIdsTwo);
final AssertableSubscriber<Void> resultSubscriber = service.addLoadBalancer(AddLoadBalancerRequest.newBuilder().setJobId(JOB_2).setLoadBalancerId(LoadBalancerId.newBuilder().setId(LB_3).build()).build(), JUNIT_REST_CALL_METADATA).test();
resultSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
resultSubscriber.assertNoErrors();
resultSubscriber.assertNoValues();
resultSubscriber.assertCompleted();
final AssertableSubscriber<GetJobLoadBalancersResult> jobResults = service.getLoadBalancers(JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
jobResults.assertNoErrors();
final List<GetJobLoadBalancersResult> onNextEvents = jobResults.getOnNextEvents();
assertThat(onNextEvents.size()).isEqualTo(1);
final List<LoadBalancerId> loadBalancersList = onNextEvents.get(0).getLoadBalancersList();
assertThat(loadBalancersList.size()).isEqualTo(2);
final List<String> resultLoadBalancerIds = loadBalancersList.stream().map(LoadBalancerId::getId).collect(Collectors.toList());
assertThat(resultLoadBalancerIds).contains(LB_2, LB_3);
}
use of com.netflix.titus.grpc.protogen.LoadBalancerId in project titus-control-plane by Netflix.
the class LoadBalancerTests method putLoadBalancersPerJob.
/**
* Common testing helper that adds a specified number of random load balancer ids to
* a specified number of jobs. The helper ensures the gRPC request was successful and
* returns the job ids and load balancer ids as a map.
*/
public static Map<String, Set<LoadBalancerId>> putLoadBalancersPerJob(int numJobs, int numLoadBalancersPerJob, BiConsumer<AddLoadBalancerRequest, TestStreamObserver<Empty>> putLoadBalancer) {
// Create job entries
Map<String, Set<LoadBalancerId>> jobIdToLoadBalancersMap = new ConcurrentHashMap<>();
for (int i = 1; i <= numJobs; i++) {
jobIdToLoadBalancersMap.put("Titus-" + i, new HashSet<>());
}
// For each job, insert load balancers
jobIdToLoadBalancersMap.forEach((jobId, loadBalancerSet) -> {
for (int i = 0; i < numLoadBalancersPerJob; i++) {
LoadBalancerId loadBalancerId = LoadBalancerId.newBuilder().setId(RandomStringUtils.randomAlphanumeric(10)).build();
AddLoadBalancerRequest request = AddLoadBalancerRequest.newBuilder().setJobId(jobId).setLoadBalancerId(loadBalancerId).build();
TestStreamObserver<Empty> addResponse = new TestStreamObserver<>();
putLoadBalancer.accept(request, addResponse);
assertThatCode(addResponse::awaitDone).doesNotThrowAnyException();
assertThat(addResponse.hasError()).isFalse();
loadBalancerSet.add(loadBalancerId);
}
});
return jobIdToLoadBalancersMap;
}
use of com.netflix.titus.grpc.protogen.LoadBalancerId in project titus-control-plane by Netflix.
the class AggregatingLoadBalancerServiceTest method removeLoadBalancer.
@Test
public void removeLoadBalancer() {
JobLoadBalancer jobLoadBalancer1 = new JobLoadBalancer(JOB_1, LB_1);
JobLoadBalancer jobLoadBalancer2 = new JobLoadBalancer(JOB_2, LB_2);
JobLoadBalancer jobLoadBalancer3 = new JobLoadBalancer(JOB_2, LB_3);
final CellWithLoadBalancers cellWithLoadBalancersOne = new CellWithLoadBalancers(singletonList(jobLoadBalancer1));
final CellWithLoadBalancers cellWithLoadBalancersTwo = new CellWithLoadBalancers(new ArrayList<>(Arrays.asList(jobLoadBalancer2, jobLoadBalancer3)));
final CellWithJobIds cellWithJobIdsOne = new CellWithJobIds(singletonList(JOB_1));
final CellWithJobIds cellWithJobIdsTwo = new CellWithJobIds(singletonList(JOB_2));
cellOne.getServiceRegistry().addService(cellWithLoadBalancersOne);
cellOne.getServiceRegistry().addService(cellWithJobIdsOne);
cellTwo.getServiceRegistry().addService(cellWithLoadBalancersTwo);
cellTwo.getServiceRegistry().addService(cellWithJobIdsTwo);
final AssertableSubscriber<Void> resultSubscriber = service.removeLoadBalancer(RemoveLoadBalancerRequest.newBuilder().setJobId(JOB_2).setLoadBalancerId(LoadBalancerId.newBuilder().setId(LB_2).build()).build(), JUNIT_REST_CALL_METADATA).test();
resultSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
resultSubscriber.assertNoErrors();
resultSubscriber.assertNoValues();
resultSubscriber.assertCompleted();
final AssertableSubscriber<GetJobLoadBalancersResult> jobResults = service.getLoadBalancers(JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
jobResults.awaitValueCount(1, 1, TimeUnit.SECONDS);
jobResults.assertNoErrors();
final List<GetJobLoadBalancersResult> onNextEvents = jobResults.getOnNextEvents();
assertThat(onNextEvents.size()).isEqualTo(1);
final List<LoadBalancerId> loadBalancersList = onNextEvents.get(0).getLoadBalancersList();
assertThat(loadBalancersList.size()).isEqualTo(1);
assertThat(loadBalancersList.get(0).getId()).isEqualTo(LB_3);
}
use of com.netflix.titus.grpc.protogen.LoadBalancerId in project titus-control-plane by Netflix.
the class AggregatingLoadBalancerServiceTest method getJobLoadBalancersWithOneFailingCell.
@Test
public void getJobLoadBalancersWithOneFailingCell() {
JobLoadBalancer jobLoadBalancer1 = new JobLoadBalancer(JOB_1, LB_1);
JobLoadBalancer jobLoadBalancer2 = new JobLoadBalancer(JOB_1, LB_2);
final CellWithLoadBalancers cellWithLoadBalancersOne = new CellWithLoadBalancers(Arrays.asList(jobLoadBalancer1, jobLoadBalancer2));
cellOne.getServiceRegistry().addService(cellWithLoadBalancersOne);
cellTwo.getServiceRegistry().addService(new CellWithFailingLoadBalancers(Status.INTERNAL));
final AssertableSubscriber<GetJobLoadBalancersResult> resultSubscriber = service.getLoadBalancers(JobId.newBuilder().setId(JOB_1).build(), JUNIT_REST_CALL_METADATA).test();
resultSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
resultSubscriber.assertNoErrors();
final List<GetJobLoadBalancersResult> onNextEvents = resultSubscriber.getOnNextEvents();
assertThat(onNextEvents).hasSize(1);
final List<LoadBalancerId> loadBalancersList = onNextEvents.get(0).getLoadBalancersList();
final List<String> resultLoadBalancers = loadBalancersList.stream().map(loadBalancerId -> loadBalancerId.getId()).collect(Collectors.toList());
assertThat(resultLoadBalancers).contains(LB_1, LB_2);
}
Aggregations