Search in sources :

Example 21 with TestStreamObserver

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

the class DefaultAutoScalingServiceGrpcTest method testGetAllPolicies.

/**
 * Test getting all policies across multiple jobs
 *
 * @throws Exception
 */
@Test
public void testGetAllPolicies() throws Exception {
    int numJobs = 20;
    int numPoliciesPerJob = 5;
    Map<String, Set<ScalingPolicyID>> jobIdToPoliciesMap = putPoliciesPerJob(numJobs, numPoliciesPerJob, PolicyType.StepScaling);
    Empty request = Empty.newBuilder().build();
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    service.getAllScalingPolicies(request, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext();
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(numJobs * numPoliciesPerJob);
}
Also used : Empty(com.google.protobuf.Empty) HashSet(java.util.HashSet) Set(java.util.Set) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test)

Example 22 with TestStreamObserver

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

the class DefaultAutoScalingServiceGrpcTest method testDeletePolicyId.

/**
 * Tests deleting policies by Ref ID.
 *
 * @throws Exception
 */
@Test
public void testDeletePolicyId() throws Exception {
    String jobId = "Titus-123";
    ScalingPolicyID scalingPolicyID = putPolicyWithJobId(jobId, PolicyType.StepScaling);
    DeletePolicyRequest deletePolicyRequest = DeletePolicyRequest.newBuilder().setId(scalingPolicyID).build();
    TestStreamObserver<Empty> deleteResponse = new TestStreamObserver<>();
    service.deleteAutoScalingPolicy(deletePolicyRequest, deleteResponse);
    deleteResponse.awaitDone();
    AutoScalingPolicyTests.waitForCondition(() -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        service.getScalingPolicy(scalingPolicyID, getResponse);
        GetPolicyResult getPolicyResult = getResponse.takeNext();
        return getPolicyResult.getItemsCount() == 1 && getPolicyResult.getItems(0).getPolicyState().getState() == Deleted;
    });
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    service.getScalingPolicy(scalingPolicyID, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext();
    // Check that the policy still exists but the state is updated
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
    assertThat(getPolicyResult.getItems(0).getPolicyState().getState()).isEqualTo(Deleted);
}
Also used : DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) 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 23 with TestStreamObserver

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

the class DefaultAutoScalingServiceGrpcTest method testUpdatePolicyConfigurationForStepScaling.

@Test
public void testUpdatePolicyConfigurationForStepScaling() throws Exception {
    ScalingPolicyID policyId = putPolicyWithJobId("Job-1", PolicyType.StepScaling);
    TestStreamObserver<Empty> updateResponse = new TestStreamObserver<>();
    service.updateAutoScalingPolicy(AutoScalingTestUtils.generateUpdateStepScalingPolicyRequest(policyId.getId(), 100.0), updateResponse);
    updateResponse.awaitDone();
    AutoScalingPolicyTests.waitForCondition(() -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        service.getScalingPolicy(policyId, getResponse);
        GetPolicyResult getPolicyResult = getResponse.takeNext();
        return getPolicyResult.getItems(0).getScalingPolicy().getStepPolicyDescriptor().getAlarmConfig().getThreshold().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().getStepPolicyDescriptor().getAlarmConfig().getThreshold().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 24 with TestStreamObserver

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

the class DefaultAutoScalingServiceGrpcTest method testGetByPolicyId.

/**
 * Tests getting policies by Ref ID.
 *
 * @throws Exception
 */
@Test
public void testGetByPolicyId() throws Exception {
    String jobId = "Titus-123";
    ScalingPolicyID scalingPolicyID = putPolicyWithJobId(jobId, PolicyType.StepScaling);
    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 25 with TestStreamObserver

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

the class JobScenarioBuilder method updateJobCapacityDesired.

public JobScenarioBuilder updateJobCapacityDesired(int desired, int unchangedMin, int unchangedMax) {
    logger.info("[{}] Changing job {} capacity desired to {}...", discoverActiveTest(), jobId, desired);
    Stopwatch stopWatch = Stopwatch.createStarted();
    TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
    client.updateJobCapacityWithOptionalAttributes(JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setDesired(UInt32Value.newBuilder().setValue(desired).build()).build()).build(), responseObserver);
    rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));
    expectJobUpdateEvent(job -> {
        ServiceJobExt ext = (ServiceJobExt) job.getJobDescriptor().getExtensions();
        Capacity capacity = ext.getCapacity();
        return capacity.getDesired() == desired && capacity.getMin() == unchangedMin && capacity.getMax() == unchangedMax;
    }, "Job capacity update did not complete in time");
    logger.info("[{}] Job {} scaled to new desired size in {}ms", discoverActiveTest(), jobId, stopWatch.elapsed(TimeUnit.MILLISECONDS));
    return this;
}
Also used : Empty(com.google.protobuf.Empty) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GrpcJobManagementModelConverters.toGrpcCapacity(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcCapacity) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Stopwatch(com.google.common.base.Stopwatch)

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