18
18
19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
import static io .grpc .ConnectivityState .CONNECTING ;
21
+ import static io .grpc .ConnectivityState .IDLE ;
21
22
import static io .grpc .ConnectivityState .READY ;
22
23
import static io .grpc .ConnectivityState .TRANSIENT_FAILURE ;
23
24
import static io .grpc .util .GracefulSwitchLoadBalancer .BUFFER_PICKER ;
32
33
import static org .mockito .Mockito .when ;
33
34
34
35
import com .google .common .testing .EqualsTester ;
36
+ import io .grpc .ConnectivityState ;
35
37
import io .grpc .ConnectivityStateInfo ;
36
38
import io .grpc .EquivalentAddressGroup ;
37
39
import io .grpc .LoadBalancer ;
@@ -363,7 +365,21 @@ public void createSubchannelForwarded() {
363
365
}
364
366
365
367
@ Test
366
- public void updateBalancingStateIsGraceful () {
368
+ public void updateBalancingStateIsGraceful_Ready () {
369
+ updateBalancingStateIsGraceful (READY );
370
+ }
371
+
372
+ @ Test
373
+ public void updateBalancingStateIsGraceful_TransientFailure () {
374
+ updateBalancingStateIsGraceful (TRANSIENT_FAILURE );
375
+ }
376
+
377
+ @ Test
378
+ public void updateBalancingStateIsGraceful_Idle () {
379
+ updateBalancingStateIsGraceful (IDLE );
380
+ }
381
+
382
+ public void updateBalancingStateIsGraceful (ConnectivityState swapsOnState ) {
367
383
assertIsOk (gracefulSwitchLb .acceptResolvedAddresses (addressesBuilder ()
368
384
.setLoadBalancingPolicyConfig (createConfig (lbPolicies [0 ], new Object ()))
369
385
.build ()));
@@ -392,11 +408,11 @@ public void updateBalancingStateIsGraceful() {
392
408
helper2 .updateBalancingState (CONNECTING , picker );
393
409
verify (mockHelper , never ()).updateBalancingState (CONNECTING , picker );
394
410
395
- // lb2 reports READY
411
+ // lb2 reports swapsOnState
396
412
SubchannelPicker picker2 = mock (SubchannelPicker .class );
397
- helper2 .updateBalancingState (READY , picker2 );
413
+ helper2 .updateBalancingState (swapsOnState , picker2 );
398
414
verify (lb0 ).shutdown ();
399
- verify (mockHelper ).updateBalancingState (READY , picker2 );
415
+ verify (mockHelper ).updateBalancingState (swapsOnState , picker2 );
400
416
401
417
assertIsOk (gracefulSwitchLb .acceptResolvedAddresses (addressesBuilder ()
402
418
.setLoadBalancingPolicyConfig (createConfig (lbPolicies [3 ], new Object ()))
@@ -407,7 +423,7 @@ public void updateBalancingStateIsGraceful() {
407
423
helper3 .updateBalancingState (CONNECTING , picker3 );
408
424
verify (mockHelper , never ()).updateBalancingState (CONNECTING , picker3 );
409
425
410
- // lb2 out of READY
426
+ // lb2 out of swapsOnState
411
427
picker2 = mock (SubchannelPicker .class );
412
428
helper2 .updateBalancingState (CONNECTING , picker2 );
413
429
verify (mockHelper , never ()).updateBalancingState (CONNECTING , picker2 );
0 commit comments