当前位置: 首页>>代码示例>>Java>>正文


Java HealthCheckResponse类代码示例

本文整理汇总了Java中io.grpc.health.v1.HealthCheckResponse的典型用法代码示例。如果您正苦于以下问题:Java HealthCheckResponse类的具体用法?Java HealthCheckResponse怎么用?Java HealthCheckResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HealthCheckResponse类属于io.grpc.health.v1包,在下文中一共展示了HealthCheckResponse类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkValidStatus

import io.grpc.health.v1.HealthCheckResponse; //导入依赖的package包/类
@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));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:HealthStatusManagerTest.java

示例2: checkStatusNotFound

import io.grpc.health.v1.HealthCheckResponse; //导入依赖的package包/类
@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.Code.NOT_FOUND, exception.getValue().getStatus().getCode());

  verify(observer, never()).onCompleted();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:20,代码来源:HealthStatusManagerTest.java

示例3: notFoundForClearedStatus

import io.grpc.health.v1.HealthCheckResponse; //导入依赖的package包/类
@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.Code.NOT_FOUND, exception.getValue().getStatus().getCode());

  verify(observer, never()).onCompleted();
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:HealthStatusManagerTest.java

示例4: testHealthCheck

import io.grpc.health.v1.HealthCheckResponse; //导入依赖的package包/类
@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);
}
 
开发者ID:LogNet,项目名称:grpc-spring-boot-starter,代码行数:9,代码来源:DemoAppTest.java

示例5: run

import io.grpc.health.v1.HealthCheckResponse; //导入依赖的package包/类
@Override
public void run(String... args) throws Exception {
    log.info("Starting gRPC Server ...");

    Collection<ServerInterceptor> globalInterceptors = getBeanNamesByTypeWithAnnotation(GRpcGlobalInterceptor.class, ServerInterceptor.class)
            .map(name -> applicationContext.getBeanFactory().getBean(name, ServerInterceptor.class))
            .collect(Collectors.toList());




    // Adding health service
    serverBuilder.addService(healthStatusManager.getHealthService());

    // find and register all GRpcService-enabled beans
    getBeanNamesByTypeWithAnnotation(GRpcService.class, BindableService.class)
            .forEach(name -> {
                BindableService srv = applicationContext.getBeanFactory().getBean(name, BindableService.class);
                ServerServiceDefinition serviceDefinition = srv.bindService();
                GRpcService gRpcServiceAnn = applicationContext.findAnnotationOnBean(name, GRpcService.class);
                serviceDefinition = bindInterceptors(serviceDefinition, gRpcServiceAnn, globalInterceptors);
                serverBuilder.addService(serviceDefinition);
                String serviceName = serviceDefinition.getServiceDescriptor().getName();
                healthStatusManager.setStatus(serviceName, HealthCheckResponse.ServingStatus.SERVING);

                log.info("'{}' service has been registered.", srv.getClass().getName());

            });

    configurer.configure(serverBuilder);
    server = serverBuilder.build().start();
    applicationContext.publishEvent(new GRpcServerInitializedEvent(server));

    log.info("gRPC Server started, listening on port {}.", server.getPort());
    startDaemonAwaitThread();

}
 
开发者ID:LogNet,项目名称:grpc-spring-boot-starter,代码行数:38,代码来源:GRpcServerRunner.java

示例6: check

import io.grpc.health.v1.HealthCheckResponse; //导入依赖的package包/类
@Override
public void check(HealthCheckRequest request,
    StreamObserver<HealthCheckResponse> responseObserver) {
  ServingStatus status = getStatus(request.getService());
  if (status == null) {
    responseObserver.onError(new StatusException(
        Status.NOT_FOUND.withDescription("unknown service " + request.getService())));
  } else {
    HealthCheckResponse response = HealthCheckResponse.newBuilder().setStatus(status).build();
    responseObserver.onNext(response);
    responseObserver.onCompleted();
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:14,代码来源:HealthServiceImpl.java


注:本文中的io.grpc.health.v1.HealthCheckResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。