use of com.netflix.titus.grpc.protogen.GetPolicyResult 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);
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult 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);
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult 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);
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult 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);
}
use of com.netflix.titus.grpc.protogen.GetPolicyResult in project titus-control-plane by Netflix.
the class AutoScalingSpringResourceTest method testGetScalingPolicy.
@Test
public void testGetScalingPolicy() throws Exception {
when(serviceMock.getScalingPolicy(SCALING_POLICY_ID, JUNIT_REST_CALL_METADATA)).thenReturn(Observable.just(GET_POLICY_RESULT));
GetPolicyResult entity = SpringMockMvcUtil.doGet(mockMvc, String.format("/api/v3/autoscaling/scalingPolicy/%s", SCALING_POLICY_ID.getId()), GetPolicyResult.class);
assertThat(entity).isEqualTo(GET_POLICY_RESULT);
verify(serviceMock, times(1)).getScalingPolicy(SCALING_POLICY_ID, JUNIT_REST_CALL_METADATA);
}
Aggregations