Search in sources :

Example 1 with HealthCheckRequest

use of io.grpc.health.v1.HealthCheckRequest in project grpc-java by grpc.

the class HealthStatusManagerTest method checkStatusNotFound.

@Test
public void checkStatusNotFound() throws Exception {
    //setup
    manager.setStatus("", status);
    HealthCheckRequest request = HealthCheckRequest.newBuilder().setService("invalid").build();
    @SuppressWarnings("unchecked") StreamObserver<HealthCheckResponse> observer = mock(StreamObserver.class);
    //test
    health.check(request, observer);
    //verify
    ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
    verify(observer, times(1)).onError(exception.capture());
    assertEquals(Status.NOT_FOUND, exception.getValue().getStatus());
    verify(observer, never()).onCompleted();
}
Also used : StatusException(io.grpc.StatusException) HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) HealthCheckRequest(io.grpc.health.v1.HealthCheckRequest) Test(org.junit.Test)

Example 2 with HealthCheckRequest

use of io.grpc.health.v1.HealthCheckRequest in project grpc-java by grpc.

the class HealthStatusManagerTest method checkValidStatus.

@Test
public void checkValidStatus() throws Exception {
    //setup
    manager.setStatus("", status);
    HealthCheckRequest request = HealthCheckRequest.newBuilder().setService("").build();
    @SuppressWarnings("unchecked") StreamObserver<HealthCheckResponse> observer = mock(StreamObserver.class);
    //test
    health.check(request, observer);
    //verify
    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onNext(any(HealthCheckResponse.class));
    inOrder.verify(observer, times(1)).onCompleted();
    verify(observer, never()).onError(any(Throwable.class));
}
Also used : InOrder(org.mockito.InOrder) HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) HealthCheckRequest(io.grpc.health.v1.HealthCheckRequest) Test(org.junit.Test)

Example 3 with HealthCheckRequest

use of io.grpc.health.v1.HealthCheckRequest in project grpc-java by grpc.

the class HealthStatusManagerTest method notFoundForClearedStatus.

@Test
public void notFoundForClearedStatus() throws Exception {
    //setup
    manager.setStatus("", status);
    manager.clearStatus("");
    HealthCheckRequest request = HealthCheckRequest.newBuilder().setService("").build();
    @SuppressWarnings("unchecked") StreamObserver<HealthCheckResponse> observer = mock(StreamObserver.class);
    //test
    health.check(request, observer);
    //verify
    ArgumentCaptor<StatusException> exception = ArgumentCaptor.forClass(StatusException.class);
    verify(observer, times(1)).onError(exception.capture());
    assertEquals(Status.NOT_FOUND, exception.getValue().getStatus());
    verify(observer, never()).onCompleted();
}
Also used : StatusException(io.grpc.StatusException) HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) HealthCheckRequest(io.grpc.health.v1.HealthCheckRequest) Test(org.junit.Test)

Example 4 with HealthCheckRequest

use of io.grpc.health.v1.HealthCheckRequest in project grpc-java by grpc.

the class HealthServiceImpl method check.

@Override
public void check(HealthCheckRequest request, StreamObserver<HealthCheckResponse> responseObserver) {
    ServingStatus status = getStatus(request.getService());
    if (status == null) {
        responseObserver.onError(new StatusException(Status.NOT_FOUND));
    } else {
        HealthCheckResponse response = HealthCheckResponse.newBuilder().setStatus(status).build();
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}
Also used : StatusException(io.grpc.StatusException) ServingStatus(io.grpc.health.v1.HealthCheckResponse.ServingStatus) HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse)

Aggregations

HealthCheckResponse (io.grpc.health.v1.HealthCheckResponse)4 StatusException (io.grpc.StatusException)3 HealthCheckRequest (io.grpc.health.v1.HealthCheckRequest)3 Test (org.junit.Test)3 ServingStatus (io.grpc.health.v1.HealthCheckResponse.ServingStatus)1 InOrder (org.mockito.InOrder)1