use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.
the class AutoScalingGrpcTest method testGetNonexistentJob.
/**
* Test that a non-existent job returns an empty list of policies.
*
* @throws Exception
*/
@Test(timeout = TEST_TIMEOUT_MS)
public void testGetNonexistentJob() throws Exception {
String jobId = "Titus-0";
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(0);
}
use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.
the class JobScenarioBuilder method killJob.
public JobScenarioBuilder killJob() {
logger.info("[{}] Killing job {}...", discoverActiveTest(), jobId);
Stopwatch stopWatch = Stopwatch.createStarted();
TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
client.killJob(JobId.newBuilder().setId(jobId).build(), responseObserver);
rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));
logger.info("[{}] Job {} killed in {}ms", discoverActiveTest(), jobId, stopWatch.elapsed(TimeUnit.MILLISECONDS));
return this;
}
use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.
the class JobScenarioBuilder method updateJobCapacity.
public JobScenarioBuilder updateJobCapacity(Capacity capacity) {
logger.info("[{}] Changing job {} capacity to {}...", discoverActiveTest(), jobId, capacity);
Stopwatch stopWatch = Stopwatch.createStarted();
TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
client.updateJobCapacity(JobCapacityUpdate.newBuilder().setJobId(jobId).setCapacity(toGrpcCapacity(capacity)).build(), responseObserver);
rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));
expectJobUpdateEvent(job -> {
ServiceJobExt ext = (ServiceJobExt) job.getJobDescriptor().getExtensions();
return ext.getCapacity().equals(capacity);
}, "Job capacity update did not complete in time");
logger.info("[{}] Job {} scaled to new size in {}ms", discoverActiveTest(), jobId, stopWatch.elapsed(TimeUnit.MILLISECONDS));
return this;
}
use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.
the class JobScenarioBuilder method deleteJobAttributes.
public JobScenarioBuilder deleteJobAttributes(List<String> keys) {
logger.info("[{}] Deleting job {} attributes with keys: {}", discoverActiveTest(), jobId, keys);
Stopwatch stopWatch = Stopwatch.createStarted();
TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
client.deleteJobAttributes(JobAttributesDeleteRequest.newBuilder().setJobId(jobId).addAllKeys(keys).build(), responseObserver);
rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));
expectJobUpdateEvent(job -> {
Map<String, String> updatedAttributes = job.getJobDescriptor().getAttributes();
return !updatedAttributes.keySet().containsAll(keys);
}, "Job attributes update did not complete in time");
logger.info("[{}] Changing job {} attributes with keys: {} finished in {}ms", discoverActiveTest(), jobId, keys, stopWatch.elapsed(TimeUnit.MILLISECONDS));
return this;
}
use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.
the class JobScenarioBuilder method updateJobCapacityMin.
public JobScenarioBuilder updateJobCapacityMin(int min, int expectedMax, int expectedDesired) {
logger.info("[{}] Changing job {} capacity min to {}...", discoverActiveTest(), jobId, min);
Stopwatch stopWatch = Stopwatch.createStarted();
TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
client.updateJobCapacityWithOptionalAttributes(JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setMin(UInt32Value.newBuilder().setValue(min).build()).build()).build(), responseObserver);
rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));
expectJobUpdateEvent(job -> {
ServiceJobExt ext = (ServiceJobExt) job.getJobDescriptor().getExtensions();
Capacity capacity = ext.getCapacity();
return capacity.getMin() == min && capacity.getMax() == expectedMax && capacity.getDesired() == expectedDesired;
}, "Job capacity update did not complete in time");
logger.info("[{}] Job {} scaled to new min size in {}ms", discoverActiveTest(), jobId, stopWatch.elapsed(TimeUnit.MILLISECONDS));
return this;
}
Aggregations