Skip to content

Commit 183c22b

Browse files
committed
replace usage of var and status imports
1 parent 134e004 commit 183c22b

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

grpc-server-spring-boot-starter/src/main/java/net/devh/boot/grpc/server/health/ActuatorGrpcHealth.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616

1717
package net.devh.boot.grpc.server.health;
1818

19-
import java.util.Objects;
2019

20+
import static io.grpc.Status.NOT_FOUND;
21+
22+
import org.springframework.boot.actuate.health.HealthComponent;
2123
import org.springframework.boot.actuate.health.HealthEndpoint;
24+
import org.springframework.boot.actuate.health.Status;
2225

23-
import io.grpc.Status;
2426
import io.grpc.StatusException;
2527
import io.grpc.health.v1.HealthCheckRequest;
2628
import io.grpc.health.v1.HealthCheckResponse;
@@ -37,20 +39,20 @@ public ActuatorGrpcHealth(HealthEndpoint healthEndpoint) {
3739
public void check(HealthCheckRequest request, StreamObserver<HealthCheckResponse> responseObserver) {
3840

3941
if (!request.getService().isEmpty()) {
40-
var health = healthEndpoint.healthForPath(request.getService());
42+
HealthComponent health = healthEndpoint.healthForPath(request.getService());
4143
if (health == null) {
42-
responseObserver.onError(new StatusException(
43-
Status.NOT_FOUND.withDescription("unknown service " + request.getService())));
44+
responseObserver.onError(
45+
new StatusException(NOT_FOUND.withDescription("unknown service " + request.getService())));
4446
return;
4547
}
46-
var status = health.getStatus();
48+
Status status = health.getStatus();
4749
HealthCheckResponse.ServingStatus result = resolveStatus(status);
4850
HealthCheckResponse response = HealthCheckResponse.newBuilder().setStatus(result).build();
4951
responseObserver.onNext(response);
5052
responseObserver.onCompleted();
5153
} else {
5254

53-
var status = healthEndpoint.health().getStatus();
55+
Status status = healthEndpoint.health().getStatus();
5456
HealthCheckResponse.ServingStatus result = resolveStatus(status);
5557
HealthCheckResponse response = HealthCheckResponse.newBuilder().setStatus(result).build();
5658
responseObserver.onNext(response);
@@ -59,12 +61,11 @@ public void check(HealthCheckRequest request, StreamObserver<HealthCheckResponse
5961

6062
}
6163

62-
private HealthCheckResponse.ServingStatus resolveStatus(org.springframework.boot.actuate.health.Status status) {
63-
if (Objects.equals(org.springframework.boot.actuate.health.Status.UP.getCode(), status.getCode())) {
64+
private HealthCheckResponse.ServingStatus resolveStatus(Status status) {
65+
if (Status.UP.equals(status)) {
6466
return HealthCheckResponse.ServingStatus.SERVING;
6567
}
66-
if (Objects.equals(org.springframework.boot.actuate.health.Status.DOWN.getCode(), status.getCode()) || Objects
67-
.equals(org.springframework.boot.actuate.health.Status.OUT_OF_SERVICE.getCode(), status.getCode())) {
68+
if (Status.DOWN.equals(status) || Status.OUT_OF_SERVICE.equals(status)) {
6869
return HealthCheckResponse.ServingStatus.NOT_SERVING;
6970
}
7071
return HealthCheckResponse.ServingStatus.UNKNOWN;

grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceTrueActuatorConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void testNotFoundService() throws InterruptedException {
119119
.setService("someservice")
120120
.build(), resultObserver);
121121

122-
var error = resultObserver.getError();
122+
Throwable error = resultObserver.getError();
123123
assertInstanceOf(StatusRuntimeException.class, error);
124124
assertEquals(Status.NOT_FOUND.getCode(), ((StatusRuntimeException) error).getStatus().getCode());
125125
} finally {

grpc-server-spring-boot-starter/src/test/java/net/devh/boot/grpc/server/health/ActuatorGrpcHealthTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ void testSpecificServiceNotFound() {
9797

9898
assertEquals(0, response.getValues().size());
9999

100-
var error = response.getError();
100+
Throwable error = response.getError();
101101
assertNotNull(error);
102102
assertInstanceOf(StatusException.class, error);
103103

104-
var statusException = (StatusException) error;
104+
StatusException statusException = (StatusException) error;
105105
assertEquals(io.grpc.Status.NOT_FOUND.getCode(), statusException.getStatus().getCode());
106106
}
107107

0 commit comments

Comments
 (0)