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