7070import io .grpc .inprocess .InProcessServerBuilder ;
7171import io .grpc .internal .FakeClock ;
7272import io .grpc .internal .JsonParser ;
73+ import io .grpc .internal .PickFirstLoadBalancerProvider ;
7374import io .grpc .internal .PickSubchannelArgsImpl ;
7475import io .grpc .internal .testing .StreamRecorder ;
7576import io .grpc .lookup .v1 .RouteLookupServiceGrpc ;
@@ -212,7 +213,8 @@ public void lb_serverStatusCodeConversion() throws Exception {
212213 subchannel .updateState (ConnectivityStateInfo .forNonError (ConnectivityState .READY ));
213214 res = picker .pickSubchannel (fakeSearchMethodArgs );
214215 assertThat (res .getStatus ().getCode ()).isEqualTo (Status .Code .OK );
215- verifyLongCounterAdd ("grpc.lb.rls.target_picks" , 1 , 1 , "wilderness" , "complete" );
216+ int expectedTimes = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
217+ verifyLongCounterAdd ("grpc.lb.rls.target_picks" , expectedTimes , 1 , "wilderness" , "complete" );
216218
217219 // Check on conversion
218220 Throwable cause = new Throwable ("cause" );
@@ -244,6 +246,8 @@ public void lb_working_withDefaultTarget_rlsResponding() throws Exception {
244246 .updateBalancingState (eq (ConnectivityState .CONNECTING ), any (SubchannelPicker .class ));
245247 inOrder .verify (helper , atLeast (0 )).getSynchronizationContext ();
246248 inOrder .verify (helper , atLeast (0 )).getScheduledExecutorService ();
249+ inOrder .verify (helper , atLeast (0 )).getMetricRecorder ();
250+ inOrder .verify (helper , atLeast (0 )).getChannelTarget ();
247251 inOrder .verifyNoMoreInteractions ();
248252
249253 assertThat (res .getStatus ().isOk ()).isTrue ();
@@ -258,7 +262,8 @@ public void lb_working_withDefaultTarget_rlsResponding() throws Exception {
258262 res = picker .pickSubchannel (searchSubchannelArgs );
259263 assertThat (subchannelIsReady (res .getSubchannel ())).isTrue ();
260264 assertThat (res .getSubchannel ()).isSameInstanceAs (searchSubchannel );
261- verifyLongCounterAdd ("grpc.lb.rls.target_picks" , 1 , 1 , "wilderness" , "complete" );
265+ int expectedTimes = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
266+ verifyLongCounterAdd ("grpc.lb.rls.target_picks" , expectedTimes , 1 , "wilderness" , "complete" );
262267
263268 // rescue should be pending status although the overall channel state is READY
264269 res = picker .pickSubchannel (rescueSubchannelArgs );
@@ -367,18 +372,22 @@ public void lb_working_withDefaultTarget_noRlsResponse() throws Exception {
367372 inOrder .verify (helper ).getMetricRecorder ();
368373 inOrder .verify (helper ).getChannelTarget ();
369374 inOrder .verifyNoMoreInteractions ();
370- verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , 1 , 1 , "defaultTarget" , "complete" );
375+ int times = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
376+ verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , times , 1 ,
377+ "defaultTarget" , "complete" );
371378 verifyNoMoreInteractions (mockMetricRecorder );
372379
373380 Subchannel subchannel = picker .pickSubchannel (searchSubchannelArgs ).getSubchannel ();
374381 assertThat (subchannelIsReady (subchannel )).isTrue ();
375382 assertThat (subchannel ).isSameInstanceAs (fallbackSubchannel );
376- verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , 2 , 1 , "defaultTarget" , "complete" );
383+ verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , ++times , 1 , "defaultTarget" ,
384+ "complete" );
377385
378386 subchannel = picker .pickSubchannel (searchSubchannelArgs ).getSubchannel ();
379387 assertThat (subchannelIsReady (subchannel )).isTrue ();
380388 assertThat (subchannel ).isSameInstanceAs (fallbackSubchannel );
381- verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , 3 , 1 , "defaultTarget" , "complete" );
389+ verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , ++times , 1 , "defaultTarget" ,
390+ "complete" );
382391
383392 // Make sure that when RLS starts communicating that default stops being used
384393 fakeThrottler .nextResult = false ;
@@ -389,7 +398,8 @@ public void lb_working_withDefaultTarget_noRlsResponse() throws Exception {
389398 (FakeSubchannel ) markReadyAndGetPickResult (inOrder , searchSubchannelArgs ).getSubchannel ();
390399 assertThat (searchSubchannel ).isNotNull ();
391400 assertThat (searchSubchannel ).isNotSameInstanceAs (fallbackSubchannel );
392- verifyLongCounterAdd ("grpc.lb.rls.target_picks" , 1 , 1 , "wilderness" , "complete" );
401+ times = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
402+ verifyLongCounterAdd ("grpc.lb.rls.target_picks" , times , 1 , "wilderness" , "complete" );
393403
394404 // create rescue subchannel
395405 picker .pickSubchannel (rescueSubchannelArgs );
@@ -433,6 +443,8 @@ public void lb_working_withoutDefaultTarget() throws Exception {
433443 .updateBalancingState (eq (ConnectivityState .CONNECTING ), any (SubchannelPicker .class ));
434444 inOrder .verify (helper , atLeast (0 )).getSynchronizationContext ();
435445 inOrder .verify (helper , atLeast (0 )).getScheduledExecutorService ();
446+ inOrder .verify (helper , atLeast (0 )).getMetricRecorder ();
447+ inOrder .verify (helper , atLeast (0 )).getChannelTarget ();
436448 inOrder .verifyNoMoreInteractions ();
437449 assertThat (res .getStatus ().isOk ()).isTrue ();
438450
@@ -469,7 +481,8 @@ public void lb_working_withoutDefaultTarget() throws Exception {
469481 res = picker .pickSubchannel (newPickSubchannelArgs (fakeSearchMethod ));
470482 assertThat (res .getStatus ().isOk ()).isFalse ();
471483 assertThat (subchannelIsReady (res .getSubchannel ())).isFalse ();
472- verifyLongCounterAdd ("grpc.lb.rls.target_picks" , 1 , 1 , "wilderness" , "complete" );
484+ int expectedTimes = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
485+ verifyLongCounterAdd ("grpc.lb.rls.target_picks" , expectedTimes , 1 , "wilderness" , "complete" );
473486
474487 res = picker .pickSubchannel (newPickSubchannelArgs (fakeRescueMethod ));
475488 assertThat (subchannelIsReady (res .getSubchannel ())).isTrue ();
0 commit comments