use of com.netflix.titus.grpc.protogen.ScalingPolicyResult 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.ScalingPolicyResult in project titus-control-plane by Netflix.
the class AggregatingAutoScalingServiceTest method getPoliciesFromTwoCells.
@Test
public void getPoliciesFromTwoCells() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
ScalingPolicyResult policyTwoResult = ScalingPolicyResult.newBuilder().setId(policy2).build();
CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
CellWithPolicies cellTwoService = new CellWithPolicies(Collections.singletonList(policyTwoResult));
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(cellTwoService);
final AssertableSubscriber<GetPolicyResult> testSubscriber = service.getAllScalingPolicies(JUNIT_REST_CALL_METADATA).test();
testSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
List<GetPolicyResult> onNextEvents = testSubscriber.getOnNextEvents();
assertThat(onNextEvents).isNotNull();
assertThat(onNextEvents.size()).isEqualTo(1);
assertThat(onNextEvents.get(0).getItemsCount()).isEqualTo(2);
}
use of com.netflix.titus.grpc.protogen.ScalingPolicyResult in project titus-control-plane by Netflix.
the class AggregatingAutoScalingServiceTest method getPoliciesFromTwoCellsWithOneFailing.
@Test
public void getPoliciesFromTwoCellsWithOneFailing() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
CellWithFailingAutoscalingService badCell = new CellWithFailingAutoscalingService();
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(badCell);
final AssertableSubscriber<GetPolicyResult> testSubscriber = service.getAllScalingPolicies(JUNIT_REST_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoValues();
testSubscriber.assertError(StatusRuntimeException.class);
List<Throwable> onErrorEvents = testSubscriber.getOnErrorEvents();
assertThat(onErrorEvents.size()).isEqualTo(1);
}
use of com.netflix.titus.grpc.protogen.ScalingPolicyResult in project titus-control-plane by Netflix.
the class AggregatingAutoScalingServiceTest method getPoliciesForJobFromTwoCells.
@Test
public void getPoliciesForJobFromTwoCells() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).setJobId(JOB_1).build();
ScalingPolicyResult policyTwoResult = ScalingPolicyResult.newBuilder().setId(policy2).setJobId(JOB_2).build();
CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
CellWithPolicies cellTwoService = new CellWithPolicies(Collections.singletonList(policyTwoResult));
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(cellTwoService);
AssertableSubscriber<GetPolicyResult> testSubscriber = service.getJobScalingPolicies(JobId.newBuilder().setId(JOB_2).build(), JUNIT_REST_CALL_METADATA).test();
testSubscriber.awaitValueCount(1, 1, TimeUnit.SECONDS);
List<GetPolicyResult> onNextEvents = testSubscriber.getOnNextEvents();
assertThat(onNextEvents).isNotNull();
assertThat(onNextEvents.size()).isEqualTo(1);
assertThat(onNextEvents.get(0).getItemsCount()).isEqualTo(1);
assertThat(onNextEvents.get(0).getItems(0).getJobId()).isEqualTo(JOB_2);
// Bad policy id, currently each Cell returns an empty result
testSubscriber = service.getJobScalingPolicies(JobId.newBuilder().setId("badID").build(), JUNIT_REST_CALL_METADATA).test();
testSubscriber.awaitTerminalEvent(1, TimeUnit.SECONDS);
testSubscriber.assertNoErrors();
onNextEvents = testSubscriber.getOnNextEvents();
assertThat(onNextEvents).isNotNull();
assertThat(onNextEvents.size()).isEqualTo(1);
assertThat(onNextEvents.get(0).getItemsCount()).isEqualTo(0);
}
use of com.netflix.titus.grpc.protogen.ScalingPolicyResult in project titus-control-plane by Netflix.
the class AutoScalingResourceTest method getPolicyByIdFromTwoCells.
@Test
public void getPolicyByIdFromTwoCells() {
ScalingPolicyID policy1 = ScalingPolicyID.newBuilder().setId(POLICY_1).build();
ScalingPolicyID policy2 = ScalingPolicyID.newBuilder().setId(POLICY_2).build();
ScalingPolicyResult policyOneResult = ScalingPolicyResult.newBuilder().setId(policy1).build();
ScalingPolicyResult policyTwoResult = ScalingPolicyResult.newBuilder().setId(policy2).build();
CellWithPolicies cellOneService = new CellWithPolicies(Collections.singletonList(policyOneResult));
CellWithPolicies cellTwoService = new CellWithPolicies(Collections.singletonList(policyTwoResult));
cellOne.getServiceRegistry().addService(cellOneService);
cellTwo.getServiceRegistry().addService(cellTwoService);
final AutoScalingResource autoScalingResource = new AutoScalingResource(service, callMetadataResolver);
final GetPolicyResult scalingPolicy = autoScalingResource.getScalingPolicy(POLICY_2);
assertThat(scalingPolicy.getItemsCount()).isEqualTo(1);
assertThat(scalingPolicy.getItems(0).getId().getId()).isEqualTo(POLICY_2);
// bad id
Assertions.assertThatCode(() -> autoScalingResource.getScalingPolicy("badPolicyId")).hasCause(Status.CANCELLED.withDescription("server cancelled stream").asRuntimeException());
}
Aggregations