Search in sources :

Example 26 with GetPolicyResult

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

the class AutoScalingSpringResourceTest method testGetAllScalingPolicies.

@Test
public void testGetAllScalingPolicies() throws Exception {
    when(serviceMock.getAllScalingPolicies(JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(GET_POLICY_RESULT));
    GetPolicyResult entity = SpringMockMvcUtil.doGet(mockMvc, "/api/v3/autoscaling/scalingPolicies", GetPolicyResult.class);
    assertThat(entity).isEqualTo(GET_POLICY_RESULT);
    verify(serviceMock, times(1)).getAllScalingPolicies(JUNIT_REST_CALL_METADATA);
}
Also used : GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 27 with GetPolicyResult

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

the class AutoScalingSpringResourceTest method testGetScalingPolicyForJob.

@Test
public void testGetScalingPolicyForJob() throws Exception {
    JobId jobId = JobId.newBuilder().setId("myJobId").build();
    when(serviceMock.getJobScalingPolicies(jobId, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(GET_POLICY_RESULT));
    GetPolicyResult entity = SpringMockMvcUtil.doGet(mockMvc, String.format("/api/v3/autoscaling/scalingPolicies/%s", jobId.getId()), GetPolicyResult.class);
    assertThat(entity).isEqualTo(GET_POLICY_RESULT);
    verify(serviceMock, times(1)).getJobScalingPolicies(jobId, JUNIT_REST_CALL_METADATA);
}
Also used : GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) JobId(com.netflix.titus.grpc.protogen.JobId) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 28 with GetPolicyResult

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

the class AutoScalingGrpcTest method testDeletePolicyById.

/**
 * Test that a policy can be deleted.
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void testDeletePolicyById() throws Exception {
    // Put a policy
    String jobId = "Titus-1";
    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());
    // Delete the policy
    TestStreamObserver<Empty> deletePolicyResult = new TestStreamObserver<>();
    DeletePolicyRequest deletePolicyRequest = DeletePolicyRequest.newBuilder().setId(scalingPolicyID).build();
    client.deleteAutoScalingPolicy(deletePolicyRequest, deletePolicyResult);
    deletePolicyResult.awaitDone();
    assertThat(deletePolicyResult.hasError()).isFalse();
    // Make sure it's set to Deleting or Deleted state
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getScalingPolicy(scalingPolicyID, getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    log.info("Got result {}", getPolicyResult);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
    assertThat(isDeletingState(getPolicyResult.getItems(0).getPolicyState()));
}
Also used : DeletePolicyRequest(com.netflix.titus.grpc.protogen.DeletePolicyRequest) PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) 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) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 29 with GetPolicyResult

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

the class AutoScalingGrpcTest method testUpdatePolicyConfigurationForTargetTracking.

/**
 * Test policy configuration update for target tracking policy
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void testUpdatePolicyConfigurationForTargetTracking() throws Exception {
    String jobId = "Titus-123";
    PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest(jobId, PolicyType.TargetTrackingScaling);
    TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
    client.setAutoScalingPolicy(putPolicyRequest, putResponse);
    ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(!scalingPolicyID.getId().isEmpty());
    TestStreamObserver<Empty> updateResponse = new TestStreamObserver<>();
    client.updateAutoScalingPolicy(AutoScalingTestUtils.generateUpdateTargetTrackingPolicyRequest(scalingPolicyID.getId(), 100.0), updateResponse);
    updateResponse.awaitDone();
    AutoScalingPolicyTests.waitForCondition(() -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        client.getScalingPolicy(scalingPolicyID, getResponse);
        try {
            GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
            return getPolicyResult.getItemsCount() == 1 && getPolicyResult.getItems(0).getScalingPolicy().getTargetPolicyDescriptor().getTargetValue().getValue() == 100.0;
        } catch (Exception ignored) {
        }
        return false;
    });
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getScalingPolicy(scalingPolicyID, getResponse);
    getResponse.awaitDone();
    GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
    DoubleValue targetValue = getPolicyResult.getItems(0).getScalingPolicy().getTargetPolicyDescriptor().getTargetValue();
    assertThat(targetValue.getValue()).isEqualTo(100.0);
}
Also used : PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) Empty(com.google.protobuf.Empty) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) DoubleValue(com.google.protobuf.DoubleValue) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) 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