services: set the default serving state of all services to SERVING

This commit is contained in:
Carl Mastrangelo 2019-01-24 15:19:51 -08:00 committed by GitHub
parent aaa3a86dd2
commit 32fc0bcd38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -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) {

View File

@ -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 {

View File

@ -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();