Search in sources :

Example 6 with TestStreamObserver

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

the class HealthTest method healthStatus.

@Test(timeout = TEST_TIMEOUT_MS)
public void healthStatus() throws Exception {
    TestStreamObserver<HealthCheckResponse> testStreamObserver = new TestStreamObserver<>();
    titusStackResource.getOperations().getHealthClient().check(HealthCheckRequest.newBuilder().build(), testStreamObserver);
    HealthCheckResponse response = testStreamObserver.takeNext(10, TimeUnit.SECONDS);
    assertThat(testStreamObserver.hasError()).isFalse();
    assertThat(response).isNotNull();
    assertThat(response.getStatus()).isEqualTo(SERVING);
    assertThat(response.getDetailsCount()).isGreaterThan(0);
    assertThat(response.getDetails(0).hasDetails()).isTrue();
    HealthCheckResponse.Details details = response.getDetails(0).getDetails();
    assertThat(details.getStatus()).isEqualTo(SERVING);
    assertThat(details.hasUptime()).isTrue();
    assertThat(details.hasElectionTimestamp()).isTrue();
    assertThat(details.hasActivationTime()).isTrue();
    assertThat(details.hasActivationTimestamp()).isTrue();
}
Also used : TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) HealthCheckResponse(com.netflix.titus.grpc.protogen.HealthCheckResponse) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 7 with TestStreamObserver

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

the class AutoScalingGrpcTest method testGetNonexistentPolicy.

/**
 * Test that a non-exitent policy returns an empty list of policies.
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
// GRPC request/response semantics requires that a value is always returned
@Ignore
public void testGetNonexistentPolicy() throws Exception {
    ScalingPolicyID scalingPolicyID = ScalingPolicyID.newBuilder().setId("deadbeef").build();
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getScalingPolicy(scalingPolicyID, getResponse);
    getResponse.awaitDone();
    assertThat(getResponse.getEmittedItems().size()).isEqualTo(0);
    assertThat(getResponse.hasError()).isFalse();
}
Also used : ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) Ignore(org.junit.Ignore) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 8 with TestStreamObserver

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

the class AutoScalingGrpcTest method testGetPolicyById.

/**
 * Test that we can retrieve a policy by a specific ID.
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void testGetPolicyById() throws Exception {
    String jobId = "Titus-123";
    PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest(jobId, PolicyType.StepScaling);
    TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
    client.setAutoScalingPolicy(putPolicyRequest, putResponse);
    ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(!scalingPolicyID.getId().isEmpty());
    log.info("Put policy {} with ID {}", putPolicyRequest, scalingPolicyID);
    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(1);
    assertThat(getPolicyResult.getItems(0).getId()).isEqualTo(scalingPolicyID);
    assertThat(getPolicyResult.getItems(0).getJobId()).isEqualTo(jobId);
}
Also used : PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) 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 9 with TestStreamObserver

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

the class AutoScalingGrpcTest method getAllPolicies.

/**
 * Test that we can get multiple exceptions.
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void getAllPolicies() throws Exception {
    Set<ScalingPolicyID> policyIDSet = new HashSet<>();
    int numJobs = 2;
    for (int i = 1; i <= numJobs; i++) {
        PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest("Titus-" + i, PolicyType.StepScaling);
        TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
        client.setAutoScalingPolicy(putPolicyRequest, putResponse);
        ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
        assertThat(!scalingPolicyID.getId().isEmpty());
        policyIDSet.add(scalingPolicyID);
    }
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getAllScalingPolicies(Empty.newBuilder().build(), getResponse);
    GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(numJobs);
    getPolicyResult.getItemsList().forEach(scalingPolicyResult -> {
        assertThat(policyIDSet.contains(scalingPolicyResult.getId())).isTrue();
    });
}
Also used : PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) HashSet(java.util.HashSet) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

Example 10 with TestStreamObserver

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

the class AutoScalingGrpcTest method testUpdatePolicyConfigurationForStepScaling.

/**
 * Test policy configuration update for target tracking policy
 *
 * @throws Exception
 */
@Test(timeout = TEST_TIMEOUT_MS)
public void testUpdatePolicyConfigurationForStepScaling() throws Exception {
    String jobId = "Titus-123";
    PutPolicyRequest putPolicyRequest = AutoScalingTestUtils.generatePutPolicyRequest(jobId, PolicyType.StepScaling);
    TestStreamObserver<ScalingPolicyID> putResponse = new TestStreamObserver<>();
    client.setAutoScalingPolicy(putPolicyRequest, putResponse);
    putResponse.awaitDone();
    ScalingPolicyID scalingPolicyID = putResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(!scalingPolicyID.getId().isEmpty());
    TestStreamObserver<Empty> updateResponse = new TestStreamObserver<>();
    client.updateAutoScalingPolicy(AutoScalingTestUtils.generateUpdateStepScalingPolicyRequest(scalingPolicyID.getId(), 100.0), updateResponse);
    updateResponse.awaitDone();
    AutoScalingPolicyTests.waitForCondition(() -> {
        TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
        client.getScalingPolicy(scalingPolicyID, getResponse);
        try {
            GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
            return getPolicyResult.getItemsCount() == 1 && getPolicyResult.getItems(0).getScalingPolicy().getStepPolicyDescriptor().getAlarmConfig().getThreshold().getValue() == 100.0;
        } catch (Exception ignored) {
        }
        return false;
    });
    TestStreamObserver<GetPolicyResult> getResponse = new TestStreamObserver<>();
    client.getScalingPolicy(scalingPolicyID, getResponse);
    getResponse.awaitDone();
    GetPolicyResult getPolicyResult = getResponse.takeNext(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    assertThat(getPolicyResult.getItemsCount()).isEqualTo(1);
    DoubleValue threshold = getPolicyResult.getItems(0).getScalingPolicy().getStepPolicyDescriptor().getAlarmConfig().getThreshold();
    assertThat(threshold.getValue()).isEqualTo(100.0);
}
Also used : PutPolicyRequest(com.netflix.titus.grpc.protogen.PutPolicyRequest) Empty(com.google.protobuf.Empty) ScalingPolicyID(com.netflix.titus.grpc.protogen.ScalingPolicyID) TestStreamObserver(com.netflix.titus.testkit.grpc.TestStreamObserver) DoubleValue(com.google.protobuf.DoubleValue) GetPolicyResult(com.netflix.titus.grpc.protogen.GetPolicyResult) BaseIntegrationTest(com.netflix.titus.master.integration.BaseIntegrationTest) IntegrationTest(com.netflix.titus.testkit.junit.category.IntegrationTest) Test(org.junit.Test)

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