@@ -80,35 +80,54 @@ public void setUp() throws Exception {
8080
8181
8282 List <ServiceInstance > instances = discoveryClient .getInstances (serviceId );
83- assertThat (instances , Matchers .not (Matchers .empty ()));
8483
85- ServiceInstance serviceInstance = instances .get (0 );
84+ final ServiceRegistrationMode registrationMode = applicationContext .getBean (GRpcServerProperties .class )
85+ .getConsul ().getRegistrationMode ();
8686
87- channel = ManagedChannelBuilder .forAddress (serviceInstance .getHost (), serviceInstance .getPort ())
88- .usePlaintext ()
89- .build ();
87+ if (!ServiceRegistrationMode .NOOP .equals (registrationMode )) {
9088
91- final GreeterGrpc .GreeterFutureStub greeterFutureStub = GreeterGrpc .newFutureStub (channel );
92- final GreeterOuterClass .HelloRequest helloRequest = GreeterOuterClass .HelloRequest .newBuilder ().setName ("Bob" ).build ();
93- final String reply = greeterFutureStub .sayHello (helloRequest ).get ().getMessage ();
94- assertThat ("Reply should not be null" , reply , Matchers .notNullValue (String .class ));
89+
90+ assertThat (instances , Matchers .not (Matchers .empty ()));
91+
92+ ServiceInstance serviceInstance = instances .get (0 );
93+
94+ channel = ManagedChannelBuilder .forAddress (serviceInstance .getHost (), serviceInstance .getPort ())
95+ .usePlaintext ()
96+ .build ();
97+
98+ final GreeterGrpc .GreeterFutureStub greeterFutureStub = GreeterGrpc .newFutureStub (channel );
99+ final GreeterOuterClass .HelloRequest helloRequest = GreeterOuterClass .HelloRequest .newBuilder ().setName ("Bob" ).build ();
100+ final String reply = greeterFutureStub .sayHello (helloRequest ).get ().getMessage ();
101+ assertThat ("Reply should not be null" , reply , Matchers .notNullValue (String .class ));
102+ }
95103 }
96104
97105 @ After
98106 public void tearDown () throws Exception {
99- channel .shutdownNow ();
100- channel .awaitTermination (1 , TimeUnit .SECONDS );
107+ if (null !=channel ) {
108+ channel .shutdownNow ();
109+ channel .awaitTermination (1 , TimeUnit .SECONDS );
110+ }
101111 applicationContext .stop ();
102112 }
103113
104114 @ Test
105115 public void contextLoads () {
106116
107-
108- int expectedRegistrations = applicationContext .getBean (GRpcServerProperties .class )
117+ int minExpectedRegistrations ;
118+ switch ( applicationContext .getBean (GRpcServerProperties .class )
109119 .getConsul ()
110- .getRegistrationMode ().equals (ServiceRegistrationMode .STANDALONE_SERVICES ) ?
111- getServicesDefinitions ().size () : 1 ;
120+ .getRegistrationMode ()) {
121+ case STANDALONE_SERVICES :
122+ minExpectedRegistrations = getServicesDefinitions ().size ();
123+ break ;
124+ case NOOP :
125+ minExpectedRegistrations = 0 ;
126+ break ;
127+ default :
128+ minExpectedRegistrations = 1 ;
129+ }
130+
112131
113132 final List <HealthService > healthServices = Awaitility .await ()
114133 .atMost (Duration .ofSeconds (20 ))
@@ -119,7 +138,7 @@ public void contextLoads() {
119138 .build ())
120139 .getValue ()
121140
122- , Matchers .hasSize (Matchers .greaterThanOrEqualTo (expectedRegistrations )));
141+ , Matchers .hasSize (Matchers .greaterThanOrEqualTo (minExpectedRegistrations )));
123142
124143 doTest (healthServices );
125144
0 commit comments