Search in sources :

Example 26 with TestStreamObserver

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;
}
Also used : Empty(com.google.protobuf.Empty) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GrpcJobManagementModelConverters.toGrpcCapacity(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcCapacity) Capacity(com.netflix.titus.api.jobmanager.model.job.Capacity) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Stopwatch(com.google.common.base.Stopwatch)

Example 27 with TestStreamObserver

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;
}
Also used : Empty(com.google.protobuf.Empty) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 28 with TestStreamObserver

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;
}
Also used : Empty(com.google.protobuf.Empty) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) JobDescriptor(com.netflix.titus.api.jobmanager.model.job.JobDescriptor) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) StatusRuntimeException(io.grpc.StatusRuntimeException) GrpcJobManagementModelConverters.toCoreJob(com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toCoreJob) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 29 with TestStreamObserver

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;
}
Also used : Empty(com.google.protobuf.Empty) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) Stopwatch(com.google.common.base.Stopwatch)

Example 30 with TestStreamObserver

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;
}
Also used : Empty(com.google.protobuf.Empty) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) Stopwatch(com.google.common.base.Stopwatch)

Aggregations

TestStreamObserver (com.netflix.titus.testkit.grpc.TestStreamObserver)42 Empty (com.google.protobuf.Empty)24 Test (org.junit.Test)19 GetPolicyResult (com.netflix.titus.grpc.protogen.GetPolicyResult)14 Stopwatch (com.google.common.base.Stopwatch)13 ScalingPolicyID (com.netflix.titus.grpc.protogen.ScalingPolicyID)12 IntegrationTest (com.netflix.titus.testkit.junit.category.IntegrationTest)11 BaseIntegrationTest (com.netflix.titus.master.integration.BaseIntegrationTest)9 ServiceJobExt (com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt)6 PutPolicyRequest (com.netflix.titus.grpc.protogen.PutPolicyRequest)6 JobId (com.netflix.titus.grpc.protogen.JobId)5 HashSet (java.util.HashSet)4 Capacity (com.netflix.titus.api.jobmanager.model.job.Capacity)3 GrpcJobManagementModelConverters.toGrpcCapacity (com.netflix.titus.runtime.endpoint.v3.grpc.GrpcJobManagementModelConverters.toGrpcCapacity)3 DoubleValue (com.google.protobuf.DoubleValue)2 Job (com.netflix.titus.api.jobmanager.model.job.Job)2 JobDescriptor (com.netflix.titus.api.jobmanager.model.job.JobDescriptor)2 Task (com.netflix.titus.api.jobmanager.model.job.Task)2 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)2 DeletePolicyRequest (com.netflix.titus.grpc.protogen.DeletePolicyRequest)2