Search in sources :

Example 6 with GetPolicyResult

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

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

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

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

Example 10 with GetPolicyResult

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

the class AutoScalingGrpcTest method getAllPolicies.

/**
 * Test that we can get multiple exceptions.
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void getAllPolicies() throws Exception {
    Set<ScalingPolicyID> policyIDSet = new HashSet<>();
    int numJobs = 2;
    for (int i = 1; i <= numJobs; i++) {
        PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest("Titus-" + i, PolicyType.StepScaling);
        TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
        client.setAutoScalingPolicy(putPolicyRequest, putResponse);
        ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
        assertThat(!scalingPolicyID.getId().isEmpty());
        policyIDSet.add(scalingPolicyID);
    }
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getAllScalingPolicies(Empty.newBuilder().build(), getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(numJobs);
    getPolicyResult.getItemsList().forEach(scalingPolicyResult -> {
        assertThat(policyIDSet.contains(scalingPolicyResult.getId())).isTrue();
    });
}
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) HashSet(java.util.HashSet) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Aggregations

GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)29 Test (org.junit.Test)28 ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)22 TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)14 ScalingPolicyResult (com.netflix.titus.grpc.protogen.ScalingPolicyResult)12 Empty (com.google.protobuf.Empty)7 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)7 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)7 JobId (com.netflix.titus.grpc.protogen.JobId)5 PutPolicyRequest (com.netflix.titus.grpc.protogen.PutPolicyRequest)5 AutoScalingResource (com.netflix.titus.runtime.endpoint.v3.rest.AutoScalingResource)5 DoubleValue (com.google.protobuf.DoubleValue)3 DeletePolicyRequest (com.netflix.titus.grpc.protogen.DeletePolicyRequest)3 HashSet (java.util.HashSet)3 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)3 UpdatePolicyRequest (com.netflix.titus.grpc.protogen.UpdatePolicyRequest)2 Set (java.util.Set)2 Response (javax.ws.rs.core.Response)2 ScalingPolicy (com.netflix.titus.grpc.protogen.ScalingPolicy)1 ApiOperation (io.swagger.annotations.ApiOperation)1