Search in sources :

Example 1 with GetAllLoadBalancersResult

use of com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult in project titus-control-plane by Netflix.

the class AggregatingLoadBalancerServiceTest method getAllLoadBalancersNoPagination.

@Test
public void getAllLoadBalancersNoPagination() {
    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<GetAllLoadBalancersResult> resultSubscriber = service.getAllLoadBalancers(GetAllLoadBalancersRequest.newBuilder().setPage(Page.newBuilder().setPageNumber(0).setPageSize(10)).build(), JUNIT_REST_CALL_METADATA).test();
    resultSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
    resultSubscriber.assertNoErrors();
    final List<GetAllLoadBalancersResult> onNextEvents = resultSubscriber.getOnNextEvents();
    assertThat(onNextEvents).hasSize(1);
    assertThat(onNextEvents.get(0).getJobLoadBalancersCount()).isEqualTo(2);
}
Also used : GetAllLoadBalancersResult(com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Test(org.junit.Test)

Example 2 with GetAllLoadBalancersResult

use of com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult in project titus-control-plane by Netflix.

the class LoadBalancerGrpcTest method testGetAllLoadBalancerPages.

@Test(timeout = TEST_TIMEOUT_MS)
public void testGetAllLoadBalancerPages() throws Exception {
    int numJobs = 75;
    int numLbs = 7;
    Map<String, Set<LoadBalancerId>> verificationMap = LoadBalancerTests.putLoadBalancersPerJob(numJobs, numLbs, putLoadBalancerWithJobId);
    int pageSize = 3;
    int currentPageNum = 0;
    GetAllLoadBalancersResult result;
    do {
        result = LoadBalancerTests.getAllLoadBalancers(buildPageSupplier(currentPageNum, pageSize), getAllLoadBalancers);
        result.getJobLoadBalancersList().forEach(getJobLoadBalancersResult -> {
            String jobId = getJobLoadBalancersResult.getJobId();
            assertThat(verificationMap.containsKey(jobId)).isTrue();
            getJobLoadBalancersResult.getLoadBalancersList().forEach(loadBalancerId -> {
                // Mark the load balancer as checked
                assertThat(verificationMap.get(jobId).remove(loadBalancerId)).isTrue();
            });
        });
        currentPageNum++;
    } while (result.getPagination().getHasMore());
    // Make sure that all of the data was checked
    verificationMap.forEach((jobId, loadBalancerSet) -> {
        assertThat(loadBalancerSet.isEmpty()).isTrue();
    });
}
Also used : Set(java.util.Set) GetAllLoadBalancersResult(com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 3 with GetAllLoadBalancersResult

use of com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult in project titus-control-plane by Netflix.

the class LoadBalancerResourceTest method getAllJobsTest.

@Test
public void getAllJobsTest() {
    GetAllLoadBalancersResult expectedResult = GetAllLoadBalancersResult.newBuilder().build();
    when(uriInfo.getQueryParameters()).thenReturn(getDefaultPageParameters());
    when(loadBalancerService.getAllLoadBalancers(any(), any())).thenReturn(Observable.just(expectedResult));
    GetAllLoadBalancersResult actualResult = loadBalancerResource.getAllLoadBalancers(uriInfo);
    assertEquals(expectedResult, actualResult);
}
Also used : GetAllLoadBalancersResult(com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult) Test(org.junit.Test)

Example 4 with GetAllLoadBalancersResult

use of com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult in project titus-control-plane by Netflix.

the class GrpcModelConverters method toGetAllLoadBalancersResult.

public static GetAllLoadBalancersResult toGetAllLoadBalancersResult(List<JobLoadBalancer> jobLoadBalancerList, Pagination runtimePagination) {
    GetAllLoadBalancersResult.Builder allLoadBalancersResult = GetAllLoadBalancersResult.newBuilder();
    allLoadBalancersResult.setPagination(toGrpcPagination(runtimePagination));
    // We expect the list to be in a sorted-by-jobId order and iterate as such
    GetJobLoadBalancersResult.Builder getJobLoadBalancersResultBuilder = GetJobLoadBalancersResult.newBuilder();
    Set<String> addedJobIds = new HashSet<>();
    for (JobLoadBalancer jobLoadBalancer : jobLoadBalancerList) {
        String jobId = jobLoadBalancer.getJobId();
        // Check if we're processing a new Job ID
        if (!addedJobIds.contains(jobId)) {
            // Add any previous JobID's result if it existed
            if (getJobLoadBalancersResultBuilder.getLoadBalancersBuilderList().size() > 0) {
                allLoadBalancersResult.addJobLoadBalancers(getJobLoadBalancersResultBuilder.build());
            }
            getJobLoadBalancersResultBuilder = GetJobLoadBalancersResult.newBuilder().setJobId(jobId);
            addedJobIds.add(jobId);
        }
        getJobLoadBalancersResultBuilder.addLoadBalancers(LoadBalancerId.newBuilder().setId(jobLoadBalancer.getLoadBalancerId()).build());
    }
    if (getJobLoadBalancersResultBuilder.getLoadBalancersBuilderList().size() > 0) {
        allLoadBalancersResult.addJobLoadBalancers(getJobLoadBalancersResultBuilder.build());
    }
    return allLoadBalancersResult.build();
}
Also used : GetAllLoadBalancersResult(com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult) GetJobLoadBalancersResult(com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) HashSet(java.util.HashSet)

Example 5 with GetAllLoadBalancersResult

use of com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult in project titus-control-plane by Netflix.

the class AggregatingLoadBalancerServiceTest method getLoadBalancersWithOneFailingCell.

@Test
public void getLoadBalancersWithOneFailingCell() {
    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<GetAllLoadBalancersResult> resultSubscriber = service.getAllLoadBalancers(GetAllLoadBalancersRequest.newBuilder().setPage(Page.newBuilder().setPageSize(10)).build(), JUNIT_REST_CALL_METADATA).test();
    resultSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
    resultSubscriber.assertNoValues();
    final List<Throwable> onErrorEvents = resultSubscriber.getOnErrorEvents();
    assertThat(onErrorEvents).hasSize(1);
    assertThat(Status.fromThrowable(onErrorEvents.get(0))).isEqualTo(Status.INTERNAL);
}
Also used : GetAllLoadBalancersResult(com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult) JobLoadBalancer(com.netflix.titus.api.loadbalancer.model.JobLoadBalancer) Test(org.junit.Test)

Aggregations

GetAllLoadBalancersResult (com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult)8 Test (org.junit.Test)6 JobLoadBalancer (com.netflix.titus.api.loadbalancer.model.JobLoadBalancer)3 GetAllLoadBalancersRequest (com.netflix.titus.grpc.protogen.GetAllLoadBalancersRequest)2 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)2 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)2 Set (java.util.Set)2 GetJobLoadBalancersResult (com.netflix.titus.grpc.protogen.GetJobLoadBalancersResult)1 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)1 HashSet (java.util.HashSet)1 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)1