use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.
the class AggregatingJobServiceGatewayTest method createJobRouteToCorrectStack.
@Test
public void createJobRouteToCorrectStack() {
// Build service handlers for each cell
cellToServiceMap.forEach((cell, grpcServerRule) -> grpcServerRule.getServiceRegistry().addService(new CellWithCachedJobsService(cell.getName())));
// Expected assignments based on routing rules in setUp()
Map<String, String> expectedAssignmentMap = ImmutableMap.of("app1", "one", "app2", "one", "app3", "two", "app4", "one");
expectedAssignmentMap.forEach((appName, expectedCellName) -> {
// Create the job and let it get routed
JobDescriptor jobDescriptor = JobDescriptor.newBuilder().setApplicationName(appName).setCapacityGroup(appName + "CapGroup").build();
String jobId = service.createJob(jobDescriptor, JobManagerConstants.UNDEFINED_CALL_METADATA).toBlocking().first();
// Get a client to the test gRPC service for the cell that we expect got it
// TODO(Andrew L): This can use findJob() instead once AggregatingService implements it
Cell expectedCell = getCellWithName(expectedCellName).orElseThrow(() -> TitusServiceException.cellNotFound(expectedCellName));
JobManagementServiceStub expectedCellClient = JobManagementServiceGrpc.newStub(cellToServiceMap.get(expectedCell).getChannel());
// Check that the cell has it with the correct attribute
TestStreamObserver<Job> findJobResponse = new TestStreamObserver<>();
expectedCellClient.findJob(JobId.newBuilder().setId(jobId).build(), findJobResponse);
assertThatCode(() -> {
Job job = findJobResponse.takeNext(1, TimeUnit.SECONDS);
assertThat(job.getJobDescriptor().getAttributesOrThrow(JOB_ATTRIBUTES_CELL).equals(expectedCellName));
}).doesNotThrowAnyException();
});
}
use of com.netflix.titus.testkit.grpc.TestStreamObserver 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.testkit.grpc.TestStreamObserver 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.testkit.grpc.TestStreamObserver 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.testkit.grpc.TestStreamObserver 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;
}
Aggregations