Search in sources :

Example 1 with HealthCheckResponse

use of io.servicetalk.health.v1.HealthCheckResponse in project client-java by tikv.

the class AbstractGRPCClient method checkHealth.

protected boolean checkHealth(String addressStr, HostMapping hostMapping) {
    ManagedChannel channel = channelFactory.getChannel(addressStr, hostMapping);
    HealthGrpc.HealthBlockingStub stub = HealthGrpc.newBlockingStub(channel).withDeadlineAfter(getTimeout(), TimeUnit.MILLISECONDS);
    HealthCheckRequest req = HealthCheckRequest.newBuilder().build();
    try {
        HealthCheckResponse resp = stub.check(req);
        if (resp.getStatus() != HealthCheckResponse.ServingStatus.SERVING) {
            return false;
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : HealthGrpc(io.grpc.health.v1.HealthGrpc) HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) ManagedChannel(io.grpc.ManagedChannel) HealthCheckRequest(io.grpc.health.v1.HealthCheckRequest)

Example 2 with HealthCheckResponse

use of io.servicetalk.health.v1.HealthCheckResponse in project zeebe by camunda.

the class GatewayGrpcHealthIT method shouldReturnServingStatusWhenGatewayIsStarted.

@ParameterizedTest
@ValueSource(strings = { GatewayGrpc.SERVICE_NAME, HealthStatusManager.SERVICE_NAME_ALL_SERVICES })
void shouldReturnServingStatusWhenGatewayIsStarted(final String serviceName) {
    // given
    final ManagedChannel channel = NettyChannelBuilder.forTarget(zeebeGatewayContainer.getExternalGatewayAddress()).usePlaintext().build();
    final HealthCheckResponse response;
    // when
    try {
        final var client = HealthGrpc.newBlockingStub(channel);
        response = client.check(HealthCheckRequest.newBuilder().setService(serviceName).build());
    } finally {
        channel.shutdownNow();
    }
    // then
    assertThat(response.getStatus()).isEqualTo(ServingStatus.SERVING);
}
Also used : HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) ManagedChannel(io.grpc.ManagedChannel) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with HealthCheckResponse

use of io.servicetalk.health.v1.HealthCheckResponse in project grpc-spring-boot-starter by yidongnan.

the class GrpcHealthServiceDefaultAutoConfigurationTest method checkResult.

void checkResult(final AwaitableStreamObserver<HealthCheckResponse> resultObserver) {
    final HealthCheckResponse response = assertDoesNotThrow(resultObserver::getSingle);
    assertEquals(ServingStatus.SERVING, response.getStatus());
}
Also used : HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse)

Example 4 with HealthCheckResponse

use of io.servicetalk.health.v1.HealthCheckResponse in project helidon by oracle.

the class HealthServiceImplTest method shouldRequestCheckForUnknownService.

@Test
public void shouldRequestCheckForUnknownService() {
    HealthServiceImpl healthService = HealthServiceImpl.create();
    String serviceName = "unknown";
    HealthCheckRequest request = HealthCheckRequest.newBuilder().setService(serviceName).build();
    TestStreamObserver<HealthCheckResponse> observer = new TestStreamObserver<>();
    healthService.check(request, observer);
    assertThat(observer.awaitTerminalEvent(), is(true));
    observer.assertError(this::isNotFoundError);
}
Also used : HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) HealthCheckRequest(io.grpc.health.v1.HealthCheckRequest) Test(org.junit.jupiter.api.Test)

Example 5 with HealthCheckResponse

use of io.servicetalk.health.v1.HealthCheckResponse in project helidon by oracle.

the class HealthServiceImplTest method shouldRequestCheckForUpService.

@Test
public void shouldRequestCheckForUpService() {
    HealthServiceImpl healthService = HealthServiceImpl.create();
    String serviceName = "foo";
    HealthCheck check = ConstantHealthCheck.up(serviceName);
    HealthCheckRequest request = HealthCheckRequest.newBuilder().setService(serviceName).build();
    TestStreamObserver<HealthCheckResponse> observer = new TestStreamObserver<>();
    healthService.add(serviceName, check);
    healthService.check(request, observer);
    assertThat(observer.awaitTerminalEvent(), is(true));
    observer.assertComplete().assertNoErrors().assertValueCount(1);
    List<HealthCheckResponse> responses = observer.values();
    assertThat(responses.size(), is(1));
    HealthCheckResponse response = responses.get(0);
    assertThat(response.getStatus(), is(HealthCheckResponse.ServingStatus.SERVING));
}
Also used : HealthCheckResponse(io.grpc.health.v1.HealthCheckResponse) HealthCheck(org.eclipse.microprofile.health.HealthCheck) HealthCheckRequest(io.grpc.health.v1.HealthCheckRequest) Test(org.junit.jupiter.api.Test)

Aggregations

HealthCheckResponse (io.grpc.health.v1.HealthCheckResponse)30 HealthCheckRequest (io.grpc.health.v1.HealthCheckRequest)14 Test (org.junit.jupiter.api.Test)10 Test (org.junit.Test)8 ManagedChannel (io.grpc.ManagedChannel)7 StatusException (io.grpc.StatusException)5 HealthCheckResponse (io.servicetalk.health.v1.HealthCheckResponse)5 Health (io.servicetalk.health.v1.Health)4 HealthCheck (org.eclipse.microprofile.health.HealthCheck)4 ServingStatus (io.grpc.health.v1.HealthCheckResponse.ServingStatus)3 HealthGrpc (io.grpc.health.v1.HealthGrpc)3 ServerContext (io.servicetalk.transport.api.ServerContext)3 InetSocketAddress (java.net.InetSocketAddress)3 StreamObserver (io.grpc.stub.StreamObserver)2 GrpcStatusException (io.servicetalk.grpc.api.GrpcStatusException)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 ResponseStatusException (org.springframework.web.server.ResponseStatusException)2 Channel (io.grpc.Channel)1 Context (io.grpc.Context)1