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);
}
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);
}
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;
}
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();
}
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);
}
Aggregations