Search in sources :

Example 1 with GetJobLoadBalancersResult

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);
}
Also used : LoadBalancerId(com.netflix.titus.grpc.protogen.LoadBalancerId) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) GetJobLoadBalancersResult(com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult) Test(org.junit.Test)

Example 2 with GetJobLoadBalancersResult

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());
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetJobLoadBalancersResult(com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult) JobId(com.netflix.titus.grpc.protogen.JobId) HashSet(java.util.HashSet)

Example 3 with GetJobLoadBalancersResult

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);
}
Also used : GetJobLoadBalancersResult(com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult) JobId(com.netflix.titus.grpc.protogen.JobId) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 4 with GetJobLoadBalancersResult

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);
}
Also used : GetJobLoadBalancersResult(com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Test(org.junit.Test)

Example 5 with GetJobLoadBalancersResult

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);
}
Also used : GetJobLoadBalancersResult(com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult) LoadBalancerId(com.netflix.titus.grpc.protogen.LoadBalancerId) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Test(org.junit.Test)

Aggregations

GetJobLoadBalancersResult (com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult)7 Test (org.junit.Test)6 JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)4 JobId (com.netflix.titus.grpc.protogen.JobId)3 LoadBalancerId (com.netflix.titus.grpc.protogen.LoadBalancerId)3 Cell (com.netflix.titus.api.federation.model.Cell)1 GrpcConfiguration (com.netflix.titus.federation.startup.GrpcConfiguration)1 AddLoadBalancerRequest (com.netflix.titus.grpc.protogen.AddLoadBalancerRequest)1 GetAllLoadBalancersRequest (com.netflix.titus.grpc.protogen.GetAllLoadBalancersRequest)1 GetAllLoadBalancersResult (com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult)1 Page (com.netflix.titus.grpc.protogen.Page)1 RemoveLoadBalancerRequest (com.netflix.titus.grpc.protogen.RemoveLoadBalancerRequest)1 AnonymousCallMetadataResolver (com.netflix.titus.runtime.endpoint.metadata.AnonymousCallMetadataResolver)1 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)1 JUNIT_REST_CALL_METADATA (com.netflix.titus.testkit.junit.spring.SpringMockMvcUtil.JUNIT_REST_CALL_METADATA)1 ManagedChannel (io.grpc.ManagedChannel)1 Status (io.grpc.Status)1 GrpcServerRule (io.grpc.testing.GrpcServerRule)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1