88import io .grpc .health .v1 .HealthCheckRequest ;
99import io .grpc .health .v1 .HealthCheckResponse ;
1010import io .grpc .health .v1 .HealthGrpc ;
11- import io .grpc .protobuf .services .ProtoReflectionService ;
1211import io .grpc .reflection .v1alpha .ServerReflectionGrpc ;
1312import io .grpc .reflection .v1alpha .ServerReflectionRequest ;
1413import io .grpc .reflection .v1alpha .ServerReflectionResponse ;
2221import org .mockito .Mockito ;
2322import org .springframework .beans .factory .annotation .Autowired ;
2423import org .springframework .beans .factory .annotation .Qualifier ;
25- import org .springframework .beans .factory .annotation .Value ;
26-
2724import org .springframework .boot .test .context .SpringBootTest ;
2825import org .springframework .boot .test .rule .OutputCapture ;
2926import org .springframework .boot .test .web .client .TestRestTemplate ;
3027import org .springframework .http .HttpStatus ;
3128import org .springframework .http .ResponseEntity ;
3229import org .springframework .test .context .junit4 .SpringRunner ;
3330
34- import java .net .URI ;
3531import java .util .ArrayList ;
3632import java .util .List ;
33+ import java .util .concurrent .CountDownLatch ;
3734import java .util .concurrent .ExecutionException ;
35+ import java .util .concurrent .TimeUnit ;
3836
3937import static org .hamcrest .CoreMatchers .containsString ;
4038import static org .hamcrest .CoreMatchers .not ;
@@ -106,6 +104,7 @@ public void testDefaultConfigurer(){
106104 public void testReflection () throws InterruptedException {
107105 List <String > discoveredServiceNames = new ArrayList <>();
108106 ServerReflectionRequest request = ServerReflectionRequest .newBuilder ().setListServices ("services" ).setHost ("localhost" ).build ();
107+ CountDownLatch latch = new CountDownLatch (1 );
109108 ServerReflectionGrpc .newStub (channel ).serverReflectionInfo (new StreamObserver <ServerReflectionResponse >() {
110109 @ Override
111110 public void onNext (ServerReflectionResponse value ) {
@@ -122,10 +121,11 @@ public void onError(Throwable t) {
122121
123122 @ Override
124123 public void onCompleted () {
125-
124+ latch . countDown ();
126125 }
127126 }).onNext (request );
128- Thread .sleep (1000l );
127+
128+ latch .await (1 , TimeUnit .SECONDS );
129129 assertFalse (discoveredServiceNames .isEmpty ());
130130 }
131131
0 commit comments