use of com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult 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.GetJobLoadBalancersResult in project titus-control-plane by Netflix.
the class LoadBalancerTests method getLoadBalancersForJob.
/**
* Common testing helper that gets load balancers for a job, ensures the gRPC request was
* successful, and returns the load balancer ids as a set.
*/
public static Set<LoadBalancerId> getLoadBalancersForJob(String jobIdStr, BiConsumer<JobId, TestStreamObserver<GetJobLoadBalancersResult>> getJobLoadBalancers) {
JobId jobId = JobId.newBuilder().setId(jobIdStr).build();
TestStreamObserver<GetJobLoadBalancersResult> getResponse = new TestStreamObserver<>();
getJobLoadBalancers.accept(jobId, getResponse);
GetJobLoadBalancersResult result = null;
try {
result = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
} catch (Exception e) {
logger.error("Exception in getLoadBalancersForJob", e);
assert false;
}
assertThat(getResponse.hasError()).isFalse();
return new HashSet<>(result.getLoadBalancersList());
}
use of com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult in project titus-control-plane by Netflix.
the class LoadBalancerSpringResourceTest method testGetJobLoadBalancers.
@Test
public void testGetJobLoadBalancers() throws Exception {
JobId jobIdWrapper = JobId.newBuilder().setId(JOB_ID).build();
when(serviceMock.getLoadBalancers(jobIdWrapper, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(GET_JOB_LOAD_BALANCERS_RESULT));
GetJobLoadBalancersResult entity = SpringMockMvcUtil.doGet(mockMvc, String.format("/api/v3/loadBalancers/%s", JOB_ID), GetJobLoadBalancersResult.class);
assertThat(entity).isEqualTo(GET_JOB_LOAD_BALANCERS_RESULT);
verify(serviceMock, times(1)).getLoadBalancers(jobIdWrapper, JUNIT_REST_CALL_METADATA);
}
use of com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult in project titus-control-plane by Netflix.
the class AggregatingLoadBalancerServiceTest method getLoadBalancersForJob.
@Test
public void getLoadBalancersForJob() {
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(singletonList(jobLoadBalancer2));
cellOne.getServiceRegistry().addService(cellWithLoadBalancersOne);
cellTwo.getServiceRegistry().addService(cellWithLoadBalancersTwo);
final AssertableSubscriber<GetJobLoadBalancersResult> resultSubscriber = service.getLoadBalancers(JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
resultSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
resultSubscriber.assertNoErrors();
final List<GetJobLoadBalancersResult> onNextEvents = resultSubscriber.getOnNextEvents();
assertThat(onNextEvents.size()).isEqualTo(1);
assertThat(onNextEvents.get(0).getJobId()).isEqualTo(JOB_2);
assertThat(onNextEvents.get(0).getLoadBalancersCount()).isEqualTo(1);
assertThat(onNextEvents.get(0).getLoadBalancers(0).getId()).isEqualTo(LB_2);
}
use of com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult 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);
}
Aggregations