@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()); }
final HealthCheckRequest.Builder builder = HealthCheckRequest.newBuilder(); assert builder != null; builder.setService("Tiller"); final HealthCheckResponseOrBuilder response = health.check(builder.build()); assert response != null; final ServingStatus status = response.getStatus();
final HealthCheckRequest.Builder builder = HealthCheckRequest.newBuilder(); assert builder != null; builder.setService("Tiller"); final HealthCheckResponseOrBuilder response = health.check(builder.build()); assert response != null; final ServingStatus status = response.getStatus();
@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()); }
@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()); }
@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 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); } }