■ ■ ■ ■ ■ ■
plugin/src/test/java/com/google/tsunami/plugin/PluginServiceClientTest.java
| skipped 35 lines |
36 | 36 | | import com.google.tsunami.proto.TargetInfo; |
37 | 37 | | import com.google.tsunami.proto.TransportProtocol; |
38 | 38 | | import io.grpc.Deadline; |
| 39 | + | import io.grpc.health.v1.HealthCheckRequest; |
| 40 | + | import io.grpc.health.v1.HealthCheckResponse; |
| 41 | + | import io.grpc.health.v1.HealthCheckResponse.ServingStatus; |
| 42 | + | import io.grpc.health.v1.HealthGrpc.HealthImplBase; |
39 | 43 | | import io.grpc.inprocess.InProcessChannelBuilder; |
40 | 44 | | import io.grpc.inprocess.InProcessServerBuilder; |
41 | 45 | | import io.grpc.stub.StreamObserver; |
| skipped 179 lines |
221 | 225 | | |
222 | 226 | | assertThat(listPlugins.isDone()).isTrue(); |
223 | 227 | | assertThat(listPlugins.get().getPluginsList()).containsExactlyElementsIn(plugins); |
| 228 | + | } |
| 229 | + | |
| 230 | + | @Test |
| 231 | + | public void checkHealth_returnServingHealthResponse() throws Exception { |
| 232 | + | HealthCheckRequest request = HealthCheckRequest.getDefaultInstance(); |
| 233 | + | |
| 234 | + | HealthImplBase healthImpl = |
| 235 | + | new HealthImplBase() { |
| 236 | + | @Override |
| 237 | + | public void check( |
| 238 | + | HealthCheckRequest request, StreamObserver<HealthCheckResponse> responseObserver) { |
| 239 | + | responseObserver.onNext( |
| 240 | + | HealthCheckResponse.newBuilder().setStatus(ServingStatus.SERVING).build()); |
| 241 | + | responseObserver.onCompleted(); |
| 242 | + | } |
| 243 | + | }; |
| 244 | + | serviceRegistry.addService(healthImpl); |
| 245 | + | |
| 246 | + | ListenableFuture<HealthCheckResponse> health = |
| 247 | + | pluginService.checkHealthWithDeadline(request, DEADLINE_DEFAULT); |
| 248 | + | |
| 249 | + | assertThat(health.isDone()).isTrue(); |
| 250 | + | assertThat(health.get().getStatus()).isEqualTo(ServingStatus.SERVING); |
| 251 | + | } |
| 252 | + | |
| 253 | + | @Test |
| 254 | + | public void checkHealth_returnNotServingHealthResponse() throws Exception { |
| 255 | + | HealthCheckRequest request = HealthCheckRequest.getDefaultInstance(); |
| 256 | + | |
| 257 | + | HealthImplBase healthImpl = |
| 258 | + | new HealthImplBase() { |
| 259 | + | @Override |
| 260 | + | public void check( |
| 261 | + | HealthCheckRequest request, StreamObserver<HealthCheckResponse> responseObserver) { |
| 262 | + | responseObserver.onNext( |
| 263 | + | HealthCheckResponse.newBuilder().setStatus(ServingStatus.NOT_SERVING).build()); |
| 264 | + | responseObserver.onCompleted(); |
| 265 | + | } |
| 266 | + | }; |
| 267 | + | serviceRegistry.addService(healthImpl); |
| 268 | + | |
| 269 | + | ListenableFuture<HealthCheckResponse> health = |
| 270 | + | pluginService.checkHealthWithDeadline(request, DEADLINE_DEFAULT); |
| 271 | + | |
| 272 | + | assertThat(health.isDone()).isTrue(); |
| 273 | + | assertThat(health.get().getStatus()).isEqualTo(ServingStatus.NOT_SERVING); |
224 | 274 | | } |
225 | 275 | | |
226 | 276 | | private void assertRunResponseContainsAllRunRequestParameters( |
| skipped 41 lines |