@Override public void check(HealthCheckRequest request, StreamObserver<HealthCheckResponse> responseObserver) { try { if (healthCheck.check().get().isHealthy()) { responseObserver.onNext( HealthCheckResponse.newBuilder().setStatus(HealthCheckResponse.ServingStatus.SERVING).build() ); } else { responseObserver.onNext( HealthCheckResponse.newBuilder().setStatus(HealthCheckResponse.ServingStatus.NOT_SERVING).build() ); } } catch (Exception ex) { GRPC_HELPER.onError(responseObserver, ex); } finally { responseObserver.onCompleted(); } } }
@Test public void testHealthCheck() throws ExecutionException, InterruptedException { final HealthCheckRequest healthCheckRequest = HealthCheckRequest.newBuilder().setService(GreeterGrpc.getServiceDescriptor().getName()).build(); final HealthGrpc.HealthFutureStub healthFutureStub = HealthGrpc.newFutureStub(channel); final HealthCheckResponse.ServingStatus servingStatus = healthFutureStub.check(healthCheckRequest).get().getStatus(); assertNotNull(servingStatus); assertEquals(servingStatus, HealthCheckResponse.ServingStatus.SERVING); } }
@Test public void healthServing() throws Exception { // Generate a unique in-process server name. String serverName = InProcessServerBuilder.generateName(); HealthCheckAggregator hca = mock(HealthCheckAggregator.class); CompletableFuture<HealthCheckStatus> hcsf = mock(CompletableFuture.class); HealthCheckStatus hcs = mock(HealthCheckStatus.class); when(hcs.isHealthy()).thenReturn(true); when(hcsf.get()).thenReturn(hcs); when(hca.check()).thenReturn(hcsf); HealthServiceImpl healthyService = new HealthServiceImpl(hca); addService(serverName, healthyService); HealthGrpc.HealthBlockingStub blockingStub = HealthGrpc.newBlockingStub( // Create a client channel and register for automatic graceful shutdown. grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build())); HealthCheckResponse reply = blockingStub.check(HealthCheckRequest.newBuilder().build()); assertEquals(HealthCheckResponse.ServingStatus.SERVING, reply.getStatus()); }
public Builder mergeFrom(io.grpc.health.v1.HealthProto.HealthCheckResponse other) { if (other == io.grpc.health.v1.HealthProto.HealthCheckResponse.getDefaultInstance()) return this; if (other.status_ != 0) { setStatusValue(other.getStatusValue()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
/** * <code>string service = 1;</code> */ public Builder clearService() { service_ = getDefaultInstance().getService(); onChanged(); return this; } /**
@java.lang.Override public io.grpc.health.v1.HealthProto.HealthCheckRequest build() { io.grpc.health.v1.HealthProto.HealthCheckRequest result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
@java.lang.Override public io.grpc.health.v1.HealthProto.HealthCheckResponse build() { io.grpc.health.v1.HealthProto.HealthCheckResponse result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
@java.lang.Override public io.grpc.health.v1.HealthProto.HealthCheckRequest buildPartial() { io.grpc.health.v1.HealthProto.HealthCheckRequest result = new io.grpc.health.v1.HealthProto.HealthCheckRequest(this); result.service_ = service_; onBuilt(); return result; }
@java.lang.Override public io.grpc.health.v1.HealthProto.HealthCheckResponse buildPartial() { io.grpc.health.v1.HealthProto.HealthCheckResponse result = new io.grpc.health.v1.HealthProto.HealthCheckResponse(this); result.status_ = status_; onBuilt(); return result; }
@Test public void testHealthCheck() throws ExecutionException, InterruptedException { final HealthCheckRequest healthCheckRequest = HealthCheckRequest.newBuilder().setService(GreeterGrpc.getServiceDescriptor().getName()).build(); final HealthGrpc.HealthFutureStub healthFutureStub = HealthGrpc.newFutureStub(channel); final HealthCheckResponse.ServingStatus servingStatus = healthFutureStub.check(healthCheckRequest).get().getStatus(); assertNotNull(servingStatus); assertEquals(servingStatus, HealthCheckResponse.ServingStatus.SERVING); } }
@Test public void healthNotServing() throws Exception { // Generate a unique in-process server name. String serverName = InProcessServerBuilder.generateName(); HealthCheckAggregator hca = mock(HealthCheckAggregator.class); CompletableFuture<HealthCheckStatus> hcsf = mock(CompletableFuture.class); HealthCheckStatus hcs = mock(HealthCheckStatus.class); when(hcs.isHealthy()).thenReturn(false); when(hcsf.get()).thenReturn(hcs); when(hca.check()).thenReturn(hcsf); HealthServiceImpl healthyService = new HealthServiceImpl(hca); addService(serverName, healthyService); HealthGrpc.HealthBlockingStub blockingStub = HealthGrpc.newBlockingStub( // Create a client channel and register for automatic graceful shutdown. grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build())); HealthCheckResponse reply = blockingStub.check(HealthCheckRequest.newBuilder().build()); assertEquals(HealthCheckResponse.ServingStatus.NOT_SERVING, reply.getStatus()); }
public Builder mergeFrom(io.grpc.health.v1.HealthProto.HealthCheckResponse other) { if (other == io.grpc.health.v1.HealthProto.HealthCheckResponse.getDefaultInstance()) return this; if (other.status_ != 0) { setStatusValue(other.getStatusValue()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
/** * <code>string service = 1;</code> */ public Builder clearService() { service_ = getDefaultInstance().getService(); onChanged(); return this; } /**
@java.lang.Override public io.grpc.health.v1.HealthProto.HealthCheckRequest build() { io.grpc.health.v1.HealthProto.HealthCheckRequest result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
@java.lang.Override public io.grpc.health.v1.HealthProto.HealthCheckResponse build() { io.grpc.health.v1.HealthProto.HealthCheckResponse result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
@java.lang.Override public io.grpc.health.v1.HealthProto.HealthCheckRequest buildPartial() { io.grpc.health.v1.HealthProto.HealthCheckRequest result = new io.grpc.health.v1.HealthProto.HealthCheckRequest(this); result.service_ = service_; onBuilt(); return result; }
@java.lang.Override public io.grpc.health.v1.HealthProto.HealthCheckResponse buildPartial() { io.grpc.health.v1.HealthProto.HealthCheckResponse result = new io.grpc.health.v1.HealthProto.HealthCheckResponse(this); result.status_ = status_; onBuilt(); return result; }
@Test public void healthException() throws Exception { // Generate a unique in-process server name. String serverName = InProcessServerBuilder.generateName(); HealthCheckAggregator hca = mock(HealthCheckAggregator.class); CompletableFuture<HealthCheckStatus> hcsf = mock(CompletableFuture.class); when(hcsf.get()).thenThrow(InterruptedException.class); when(hca.check()).thenReturn(hcsf); HealthServiceImpl healthyService = new HealthServiceImpl(hca); addService(serverName, healthyService); HealthGrpc.HealthBlockingStub blockingStub = HealthGrpc.newBlockingStub( // Create a client channel and register for automatic graceful shutdown. grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build())); thrown.expect(StatusRuntimeException.class); thrown.expect(hasProperty("status", is(Status.INTERNAL))); blockingStub.check(HealthCheckRequest.newBuilder().build()); }
/** * <code>string service = 1;</code> */ public Builder clearService() { service_ = getDefaultInstance().getService(); onChanged(); return this; } /**
@java.lang.Override public io.grpc.health.v1.HealthProto.HealthCheckRequest buildPartial() { io.grpc.health.v1.HealthProto.HealthCheckRequest result = new io.grpc.health.v1.HealthProto.HealthCheckRequest(this); result.service_ = service_; onBuilt(); return result; }