Search in sources :

Example 41 with TestStreamObserver

use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.

the class TaskRelocationIntegrationTest method findRelocationPlan.

private Optional<TaskRelocationPlan> findRelocationPlan(String taskId) {
    TaskRelocationPlans plans;
    try {
        TestStreamObserver<TaskRelocationPlans> events = new TestStreamObserver<>();
        client.getCurrentTaskRelocationPlans(TaskRelocationQuery.getDefaultInstance(), events);
        plans = events.getLast();
    } catch (Exception e) {
        if (e.getMessage().contains("Relocation workflow not ready yet")) {
            return Optional.empty();
        }
        throw new RuntimeException(e);
    }
    Optional<TaskRelocationPlan> taskPlan = plans.getPlansList().stream().filter(p -> p.getTaskId().equals(taskId)).findFirst();
    if (taskPlan.isPresent()) {
        return taskPlan;
    }
    // Check if already processed
    try {
        TestStreamObserver<TaskRelocationExecution> events = new TestStreamObserver<>();
        client.getTaskRelocationResult(RelocationTaskId.newBuilder().setId(taskId).build(), events);
        return Optional.of(events.getLast().getTaskRelocationPlan());
    } catch (Exception e) {
        Status status = Status.fromThrowable(e);
        if (status.getCode() == Status.Code.NOT_FOUND) {
            return Optional.empty();
        }
        throw new RuntimeException(e);
    }
}
Also used : TestDataFactory(com.netflix.titus.supplementary.relocation.TestDataFactory) TestDataFactory.newSelfManagedDisruptionBudget(com.netflix.titus.supplementary.relocation.TestDataFactory.newSelfManagedDisruptionBudget) Task(com.netflix.titus.api.jobmanager.model.job.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TimeoutException(java.util.concurrent.TimeoutException) Supplier(java.util.function.Supplier) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) RelocationConnectorStubs(com.netflix.titus.supplementary.relocation.RelocationConnectorStubs) Status(io.grpc.Status) ReadOnlyJobOperations(com.netflix.titus.api.jobmanager.service.ReadOnlyJobOperations) TaskRelocationReason(com.netflix.titus.api.relocation.model.TaskRelocationPlan.TaskRelocationReason) TaskRelocationQuery(com.netflix.titus.grpc.protogen.TaskRelocationQuery) Before(org.junit.Before) CollectionsExt.last(com.netflix.titus.common.util.CollectionsExt.last) Job(com.netflix.titus.api.jobmanager.model.job.Job) EventCase(com.netflix.titus.grpc.protogen.RelocationEvent.EventCase) TaskRelocationExecution(com.netflix.titus.grpc.protogen.TaskRelocationExecution) TaskRelocationPlans(com.netflix.titus.grpc.protogen.TaskRelocationPlans) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) TimeUnit(java.util.concurrent.TimeUnit) TaskRelocationPlan(com.netflix.titus.grpc.protogen.TaskRelocationPlan) Rule(org.junit.Rule) TaskRelocationStatus(com.netflix.titus.grpc.protogen.TaskRelocationStatus) Optional(java.util.Optional) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) Clock(com.netflix.titus.common.util.time.Clock) RelocationEvent(com.netflix.titus.grpc.protogen.RelocationEvent) TaskRelocationServiceGrpc(com.netflix.titus.grpc.protogen.TaskRelocationServiceGrpc) RelocationTaskId(com.netflix.titus.grpc.protogen.RelocationTaskId) MockEnvironment(org.springframework.mock.env.MockEnvironment) Status(io.grpc.Status) TaskRelocationStatus(com.netflix.titus.grpc.protogen.TaskRelocationStatus) TaskRelocationExecution(com.netflix.titus.grpc.protogen.TaskRelocationExecution) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) TaskRelocationPlans(com.netflix.titus.grpc.protogen.TaskRelocationPlans) TimeoutException(java.util.concurrent.TimeoutException) TaskRelocationPlan(com.netflix.titus.grpc.protogen.TaskRelocationPlan)

Example 42 with TestStreamObserver

use of com.netflix.titus.testkit.grpc.TestStreamObserver in project titus-control-plane by Netflix.

the class LoadBalancerTests method getAllLoadBalancers.

/**
 * Common testing helper that gets all load balancers for a given page range, ensures the gRPC
 * request was successful, and returns the page result.
 */
public static GetAllLoadBalancersResult getAllLoadBalancers(Supplier<Page> pageSupplier, BiConsumer<GetAllLoadBalancersRequest, TestStreamObserver<GetAllLoadBalancersResult>> getAllLoadBalancers) {
    GetAllLoadBalancersRequest request = GetAllLoadBalancersRequest.newBuilder().setPage(pageSupplier.get()).build();
    TestStreamObserver<GetAllLoadBalancersResult> getResponse = new TestStreamObserver<>();
    getAllLoadBalancers.accept(request, getResponse);
    GetAllLoadBalancersResult result = null;
    try {
        result = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        logger.error("Exception in getAllLoadBalancers", e);
        assert false;
    }
    assertThat(getResponse.hasError()).isFalse();
    return result;
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetAllLoadBalancersResult(com.netflix.titus.grpc.protogen.GetAllLoadBalancersResult) GetAllLoadBalancersRequest(com.netflix.titus.grpc.protogen.GetAllLoadBalancersRequest)

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