Search in sources :

Example 6 with ScalingPolicyID

use of com.netflix.titus.grpc.protogen.ScalingPolicyID 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 7 with ScalingPolicyID

use of com.netflix.titus.grpc.protogen.ScalingPolicyID 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 8 with ScalingPolicyID

use of com.netflix.titus.grpc.protogen.ScalingPolicyID 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)

Example 9 with ScalingPolicyID

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

the class AutoScalingGrpcTest method testGetNonexistentPolicy.

/**
 * Test that a non-exitent policy returns an empty list of policies.
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
// GRPC request/response semantics requires that a value is always returned
@Ignore
public void testGetNonexistentPolicy() throws Exception {
    ScalingPolicyID scalingPolicyID = ScalingPolicyID.newBuilder().setId("deadbeef").build();
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getScalingPolicy(scalingPolicyID, getResponse);
    getResponse.awaitDone();
    assertThat(getResponse.getEmittedItems().size()).isEqualTo(0);
    assertThat(getResponse.hasError()).isFalse();
}
Also used : ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Ignore(org.junit.Ignore) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 10 with ScalingPolicyID

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

the class AutoScalingGrpcTest method testGetPolicyById.

/**
 * Test that we can retrieve a policy by a specific ID.
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void testGetPolicyById() throws Exception {
    String jobId = "Titus-123";
    PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest(jobId, PolicyType.StepScaling);
    TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
    client.setAutoScalingPolicy(putPolicyRequest, putResponse);
    ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(!scalingPolicyID.getId().isEmpty());
    log.info("Put policy {} with ID {}", putPolicyRequest, scalingPolicyID);
    JobId getPolicyRequest = JobId.newBuilder().setId(jobId).build();
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getJobScalingPolicies(getPolicyRequest, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    log.info("Got result {}", getPolicyResult);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
    assertThat(getPolicyResult.getItems(0).getId()).isEqualTo(scalingPolicyID);
    assertThat(getPolicyResult.getItems(0).getJobId()).isEqualTo(jobId);
}
Also used : PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) JobId(com.netflix.titus.grpc.protogen.JobId) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Aggregations

ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)32 GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)24 Test (org.junit.Test)24 ScalingPolicyResult (com.netflix.titus.grpc.protogen.ScalingPolicyResult)13 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)12 PutPolicyRequest (com.netflix.titus.grpc.protogen.PutPolicyRequest)9 Empty (com.google.protobuf.Empty)8 DeletePolicyRequest (com.netflix.titus.grpc.protogen.DeletePolicyRequest)7 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)6 AutoScalingResource (com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource)6 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)6 UpdatePolicyRequest (com.netflix.titus.grpc.protogen.UpdatePolicyRequest)4 ApiOperation (io.swagger.annotations.ApiOperation)4 DoubleValue (com.google.protobuf.DoubleValue)3 JobId (com.netflix.titus.grpc.protogen.JobId)3 Cell (com.netflix.titus.api.federation.model.Cell)2 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)2 CellConnectorUtil.callToCell (com.netflix.titus.federation.service.CellConnectorUtil.callToCell)2 GrpcConfiguration (com.netflix.titus.federation.startup.GrpcConfiguration)2 AutoScalingServiceGrpc (com.netflix.titus.grpc.protogen.AutoScalingServiceGrpc)2