use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.
the class JobScenarioBuilder method updateJobCapacityMax.
public JobScenarioBuilder updateJobCapacityMax(int max, int expectedMin, int expectedDesired) {
logger.info("[{}] Changing job {} capacity max to {}...", discoverActiveTest(), jobId, max);
Stopwatch stopWatch = Stopwatch.createStarted();
TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
client.updateJobCapacityWithOptionalAttributes(JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setMax(UInt32Value.newBuilder().setValue(max).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.getMax() == max && capacity.getMin() == expectedMin && capacity.getDesired() == expectedDesired;
}, "Job capacity update did not complete in time");
logger.info("[{}] Job {} scaled to new max 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 updateJobCapacityMaxInvalid.
public JobScenarioBuilder updateJobCapacityMaxInvalid(int targetMax) {
logger.info("[{}] Changing job {} capacity max to {}...", discoverActiveTest(), jobId, targetMax);
TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
client.updateJobCapacityWithOptionalAttributes(JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setMax(UInt32Value.newBuilder().setValue(targetMax).build()).build()).build(), responseObserver);
await().timeout(TIMEOUT_MS, TimeUnit.MILLISECONDS).until(responseObserver::hasError);
Throwable error = responseObserver.getError();
assertThat(error).isNotNull();
assertThat(error).isInstanceOf(StatusRuntimeException.class);
StatusRuntimeException statusRuntimeException = (StatusRuntimeException) error;
assertThat(statusRuntimeException.getStatus().getCode() == Status.Code.INVALID_ARGUMENT).isTrue();
return this;
}
use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.
the class JobScenarioBuilder method updateJobCapacityDesiredInvalid.
public JobScenarioBuilder updateJobCapacityDesiredInvalid(int targetDesired, int currentDesired) {
logger.info("[{}] Changing job {} capacity desired to {}...", discoverActiveTest(), jobId, targetDesired);
TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
client.updateJobCapacityWithOptionalAttributes(JobCapacityUpdateWithOptionalAttributes.newBuilder().setJobId(jobId).setJobCapacityWithOptionalAttributes(JobCapacityWithOptionalAttributes.newBuilder().setDesired(UInt32Value.newBuilder().setValue(targetDesired).build()).build()).build(), responseObserver);
await().timeout(TIMEOUT_MS, TimeUnit.MILLISECONDS).until(responseObserver::hasError);
Throwable error = responseObserver.getError();
assertThat(error).isNotNull();
assertThat(error).isInstanceOf(StatusRuntimeException.class);
StatusRuntimeException statusRuntimeException = (StatusRuntimeException) error;
assertThat(statusRuntimeException.getStatus().getCode() == Status.Code.INVALID_ARGUMENT).isTrue();
// Make sure desired count is unchanged
Job job = getJob();
JobDescriptor.JobDescriptorExt ext = job.getJobDescriptor().getExtensions();
int currentCapacity = ext instanceof BatchJobExt ? ((BatchJobExt) ext).getSize() : ((ServiceJobExt) ext).getCapacity().getDesired();
assertThat(currentCapacity).isEqualTo(currentDesired);
return this;
}
use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.
the class JobScenarioBuilder method updateJobAttributes.
public JobScenarioBuilder updateJobAttributes(Map<String, String> attributes) {
logger.info("[{}] Updating job {} attributes with {}", discoverActiveTest(), jobId, attributes);
Stopwatch stopWatch = Stopwatch.createStarted();
TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
client.updateJobAttributes(JobAttributesUpdate.newBuilder().setJobId(jobId).putAllAttributes(attributes).build(), responseObserver);
rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));
expectJobUpdateEvent(job -> {
Map<String, String> updatedAttributes = job.getJobDescriptor().getAttributes();
return updatedAttributes.entrySet().containsAll(attributes.entrySet());
}, "Job attributes update did not complete in time");
logger.info("[{}] Changing job {} attributes with {} finished in {}ms", discoverActiveTest(), jobId, attributes, 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 updateJobDisruptionBudget.
public JobScenarioBuilder updateJobDisruptionBudget(DisruptionBudget disruptionBudget) {
logger.info("[{}] Changing job {} disruption budget to {}...", discoverActiveTest(), jobId, disruptionBudget);
Stopwatch stopWatch = Stopwatch.createStarted();
TestStreamObserver<Empty> responseObserver = new TestStreamObserver<>();
client.updateJobDisruptionBudget(JobDisruptionBudgetUpdate.newBuilder().setJobId(jobId).setDisruptionBudget(toGrpcDisruptionBudget(disruptionBudget)).build(), responseObserver);
rethrow(() -> responseObserver.awaitDone(TIMEOUT_MS, TimeUnit.MILLISECONDS));
expectJobUpdateEvent(job -> job.getJobDescriptor().getDisruptionBudget().equals(disruptionBudget), "Job disruption budget update did not complete in time");
logger.info("[{}] Changing job {} disruption budget to {} finished in {}ms", discoverActiveTest(), jobId, disruptionBudget, stopWatch.elapsed(TimeUnit.MILLISECONDS));
return this;
}
Aggregations