mirror of https://github.com/grpc/grpc-java.git
services: set the default serving state of all services to SERVING
This commit is contained in:
parent
aaa3a86dd2
commit
32fc0bcd38
|
|
@ -59,6 +59,11 @@ final class HealthServiceImpl extends HealthGrpc.HealthImplBase {
|
|||
private final HashMap<String, IdentityHashMap<StreamObserver<HealthCheckResponse>, Boolean>>
|
||||
watchers = new HashMap<>();
|
||||
|
||||
HealthServiceImpl() {
|
||||
// Copy of what Go and C++ do.
|
||||
statusMap.put(HealthStatusManager.SERVICE_NAME_ALL_SERVICES, ServingStatus.SERVING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check(HealthCheckRequest request,
|
||||
StreamObserver<HealthCheckResponse> responseObserver) {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ import io.grpc.health.v1.HealthCheckResponse.ServingStatus;
|
|||
* created in the constructor of {@code HealthStatusManager}, and it can be retrieved by the
|
||||
* {@link #getHealthService()} method.
|
||||
* The health status manager can update the health statuses of the server.
|
||||
*
|
||||
* <p>The default, empty-string, service name, {@link #SERVICE_NAME_ALL_SERVICES}, is initialized to
|
||||
* {@link ServingStatus#SERVING}.
|
||||
*/
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/4696")
|
||||
public final class HealthStatusManager {
|
||||
|
|
|
|||
|
|
@ -133,6 +133,19 @@ public class HealthStatusManagerTest {
|
|||
assertThat(resp.getStatus()).isEqualTo(ServingStatus.NOT_SERVING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultIsServing() throws Exception {
|
||||
HealthCheckRequest request =
|
||||
HealthCheckRequest.newBuilder().setService(HealthStatusManager.SERVICE_NAME_ALL_SERVICES)
|
||||
.build();
|
||||
|
||||
HealthCheckResponse response =
|
||||
blockingStub.withDeadlineAfter(5, TimeUnit.SECONDS).check(request);
|
||||
|
||||
assertThat(response).isEqualTo(
|
||||
HealthCheckResponse.newBuilder().setStatus(ServingStatus.SERVING).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHealthService_getterReturnsTheSameHealthRefAfterUpdate() throws Exception {
|
||||
BindableService health = manager.getHealthService();
|
||||
|
|
|
|||
Loading…
Reference in New Issue