Search in sources :

Example 11 with TestStreamObserver

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);
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) JobId(com.netflix.titus.grpc.protogen.JobId) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 12 with TestStreamObserver

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

Example 13 with TestStreamObserver

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

Example 14 with TestStreamObserver

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

Example 15 with TestStreamObserver

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;
}
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)

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