Search in sources :

Example 1 with TestStreamObserver

use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.

the class AggregatingJobServiceGatewayTest method createJobRouteToCorrectStack.

@Test
public void createJobRouteToCorrectStack() {
    // Build service handlers for each cell
    cellToServiceMap.forEach((cell, grpcServerRule) -> grpcServerRule.getServiceRegistry().addService(new CellWithCachedJobsService(cell.getName())));
    // Expected assignments based on routing rules in setUp()
    Map<String, String> expectedAssignmentMap = ImmutableMap.of("app1", "one", "app2", "one", "app3", "two", "app4", "one");
    expectedAssignmentMap.forEach((appName, expectedCellName) -> {
        // Create the job and let it get routed
        JobDescriptor jobDescriptor = JobDescriptor.newBuilder().setApplicationName(appName).setCapacityGroup(appName + "CapGroup").build();
        String jobId = service.createJob(jobDescriptor, JobManagerConstants.UNDEFINED_CALL_METADATA).toBlocking().first();
        // Get a client to the test gRPC service for the cell that we expect got it
        // TODO(Andrew L): This can use findJob() instead once AggregatingService implements it
        Cell expectedCell = getCellWithName(expectedCellName).orElseThrow(() -> TitusServiceException.cellNotFound(expectedCellName));
        JobManagementServiceStub expectedCellClient = JobManagementServiceGrpc.newStub(cellToServiceMap.get(expectedCell).getChannel());
        // Check that the cell has it with the correct attribute
        TestStreamObserver<Job> findJobResponse = new TestStreamObserver<>();
        expectedCellClient.findJob(JobId.newBuilder().setId(jobId).build(), findJobResponse);
        assertThatCode(() -> {
            Job job = findJobResponse.takeNext(1, TimeUnit.SECONDS);
            assertThat(job.getJobDescriptor().getAttributesOrThrow(JOB_ATTRIBUTES_CELL).equals(expectedCellName));
        }).doesNotThrowAnyException();
    });
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) JobDescriptor(com.netflix.titus.grpc.protogen.JobDescriptor) Job(com.netflix.titus.grpc.protogen.Job) Cell(com.netflix.titus.api.federation.model.Cell) JobManagementServiceStub(com.netflix.titus.grpc.protogen.JobManagementServiceGrpc.JobManagementServiceStub) Test(org.junit.Test)

Example 2 with TestStreamObserver

use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.

the class DefaultAutoScalingServiceGrpcTest method testTargetTrackingPolicy.

/**
 * Tests setting and getting a Target Tracking Policy.
 *
 * @throws Exception
 */
@Test
public void testTargetTrackingPolicy() throws Exception {
    String jobId = "Titus-123";
    ScalingPolicyID scalingPolicyID = putPolicyWithJobId(jobId, PolicyType.TargetTrackingScaling);
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    service.getScalingPolicy(scalingPolicyID, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext();
    log.info("Got response {}", getPolicyResult);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
    assertThat(getPolicyResult.getItems(0).getId()).isEqualTo(scalingPolicyID);
    assertThat(getPolicyResult.getItems(0).getJobId()).isEqualTo(jobId);
}
Also used : ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test)

Example 3 with TestStreamObserver

use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.

the class DefaultAutoScalingServiceGrpcTest method testSetAndGetJobScalingPolicy.

/**
 * Tests setting and getting policies by Job ID.
 *
 * @throws Exception
 */
@Test
public void testSetAndGetJobScalingPolicy() throws Exception {
    int numJobs = 2;
    int numPoliciesPerJob = 3;
    Map<String, Set<ScalingPolicyID>> jobIdToPoliciesMap = putPoliciesPerJob(numJobs, numPoliciesPerJob, PolicyType.StepScaling);
    // For each job, check that all of the policies exist
    jobIdToPoliciesMap.forEach((jobId, policyIDSet) -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        JobId jobIdRequest = JobId.newBuilder().setId(jobId).build();
        service.getJobScalingPolicies(jobIdRequest, getResponse);
        GetPolicyResult getPolicyResult = getResponse.takeNext();
        assertThat(getPolicyResult.getItemsCount()).isEqualTo(numPoliciesPerJob);
        for (int i = 0; i < getPolicyResult.getItemsCount(); i++) {
            ScalingPolicyResult scalingPolicyResult = getPolicyResult.getItems(i);
            assertThat(policyIDSet.contains(scalingPolicyResult.getId())).isTrue();
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) ScalingPolicyResult(com.netflix.titus.grpc.protogen.ScalingPolicyResult) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) JobId(com.netflix.titus.grpc.protogen.JobId) Test(org.junit.Test)

Example 4 with TestStreamObserver

use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.

the class DefaultAutoScalingServiceGrpcTest method testUpdatePolicyConfigurationForTargetTracking.

@Test
public void testUpdatePolicyConfigurationForTargetTracking() throws Exception {
    ScalingPolicyID policyId = putPolicyWithJobId("Job-1", PolicyType.TargetTrackingScaling);
    TestStreamObserver<Empty> updateResponse = new TestStreamObserver<>();
    service.updateAutoScalingPolicy(AutoScalingTestUtils.generateUpdateTargetTrackingPolicyRequest(policyId.getId(), 100.0), updateResponse);
    AutoScalingPolicyTests.waitForCondition(() -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        service.getScalingPolicy(policyId, getResponse);
        GetPolicyResult getPolicyResult = getResponse.takeNext();
        return getPolicyResult.getItems(0).getScalingPolicy().getTargetPolicyDescriptor().getTargetValue().getValue() == 100.0 && getPolicyResult.getItems(0).getPolicyState().getState() == Applied;
    });
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    service.getScalingPolicy(policyId, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext();
    assertThat(getPolicyResult.getItems(0).getScalingPolicy().getTargetPolicyDescriptor().getTargetValue().getValue()).isEqualTo(100.0);
    assertThat(getPolicyResult.getItems(0).getPolicyState().getState()).isEqualTo(Applied);
}
Also used : Empty(com.google.protobuf.Empty) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test)

Example 5 with TestStreamObserver

use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.

the class DefaultAutoScalingServiceGrpcTest method putPolicyWithJobId.

private ScalingPolicyID putPolicyWithJobId(String jobId, PolicyType policyType) {
    PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest(jobId, policyType);
    TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
    service.setAutoScalingPolicy(putPolicyRequest, putResponse);
    log.info("Put policy {}", putPolicyRequest);
    ScalingPolicyID scalingPolicyID = putResponse.takeNext();
    assertThat(scalingPolicyID.getId()).isNotEmpty();
    return scalingPolicyID;
}
Also used : PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver)

Aggregations

TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)42 Empty (com.google.protobuf.Empty)24 Test (org.junit.Test)19 GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)14 Stopwatch (com.google.common.base.Stopwatch)13 ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)12 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)11 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)9 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)6 PutPolicyRequest (com.netflix.titus.grpc.protogen.PutPolicyRequest)6 JobId (com.netflix.titus.grpc.protogen.JobId)5 HashSet (java.util.HashSet)4 Capacity (com.netflix.titus.api.jobmanager.model.job.Capacity)3 GrpcJobManagementModelConverters.toGrpcCapacity (com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcCapacity)3 DoubleValue (com.google.protobuf.DoubleValue)2 Job (com.netflix.titus.api.jobmanager.model.job.Job)2 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)2 Task (com.netflix.titus.api.jobmanager.model.job.Task)2 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)2 DeletePolicyRequest (com.netflix.titus.grpc.protogen.DeletePolicyRequest)2