6666import io .grpc .inprocess .InProcessServerBuilder ;
6767import io .grpc .internal .FakeClock ;
6868import io .grpc .internal .JsonParser ;
69+ import io .grpc .internal .PickFirstLoadBalancerProvider ;
6970import io .grpc .internal .PickSubchannelArgsImpl ;
7071import io .grpc .lookup .v1 .RouteLookupServiceGrpc ;
7172import io .grpc .rls .RlsLoadBalancer .CachingRlsLbClientBuilderProvider ;
@@ -206,7 +207,8 @@ public void lb_serverStatusCodeConversion() throws Exception {
206207 subchannel .updateState (ConnectivityStateInfo .forNonError (ConnectivityState .READY ));
207208 res = picker .pickSubchannel (fakeSearchMethodArgs );
208209 assertThat (res .getStatus ().getCode ()).isEqualTo (Status .Code .OK );
209- verifyLongCounterAdd ("grpc.lb.rls.target_picks" , 1 , 1 , "wilderness" , "complete" );
210+ int expectedTimes = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
211+ verifyLongCounterAdd ("grpc.lb.rls.target_picks" , expectedTimes , 1 , "wilderness" , "complete" );
210212
211213 // Check on conversion
212214 Throwable cause = new Throwable ("cause" );
@@ -238,6 +240,8 @@ public void lb_working_withDefaultTarget_rlsResponding() throws Exception {
238240 .updateBalancingState (eq (ConnectivityState .CONNECTING ), any (SubchannelPicker .class ));
239241 inOrder .verify (helper , atLeast (0 )).getSynchronizationContext ();
240242 inOrder .verify (helper , atLeast (0 )).getScheduledExecutorService ();
243+ inOrder .verify (helper , atLeast (0 )).getMetricRecorder ();
244+ inOrder .verify (helper , atLeast (0 )).getChannelTarget ();
241245 inOrder .verifyNoMoreInteractions ();
242246
243247 assertThat (res .getStatus ().isOk ()).isTrue ();
@@ -252,7 +256,8 @@ public void lb_working_withDefaultTarget_rlsResponding() throws Exception {
252256 res = picker .pickSubchannel (searchSubchannelArgs );
253257 assertThat (subchannelIsReady (res .getSubchannel ())).isTrue ();
254258 assertThat (res .getSubchannel ()).isSameInstanceAs (searchSubchannel );
255- verifyLongCounterAdd ("grpc.lb.rls.target_picks" , 1 , 1 , "wilderness" , "complete" );
259+ int expectedTimes = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
260+ verifyLongCounterAdd ("grpc.lb.rls.target_picks" , expectedTimes , 1 , "wilderness" , "complete" );
256261
257262 // rescue should be pending status although the overall channel state is READY
258263 res = picker .pickSubchannel (rescueSubchannelArgs );
@@ -323,18 +328,22 @@ public void lb_working_withDefaultTarget_noRlsResponse() throws Exception {
323328 inOrder .verify (helper ).getMetricRecorder ();
324329 inOrder .verify (helper ).getChannelTarget ();
325330 inOrder .verifyNoMoreInteractions ();
326- verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , 1 , 1 , "defaultTarget" , "complete" );
331+ int times = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
332+ verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , times , 1 ,
333+ "defaultTarget" , "complete" );
327334 verifyNoMoreInteractions (mockMetricRecorder );
328335
329336 Subchannel subchannel = picker .pickSubchannel (searchSubchannelArgs ).getSubchannel ();
330337 assertThat (subchannelIsReady (subchannel )).isTrue ();
331338 assertThat (subchannel ).isSameInstanceAs (fallbackSubchannel );
332- verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , 2 , 1 , "defaultTarget" , "complete" );
339+ verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , ++times , 1 , "defaultTarget" ,
340+ "complete" );
333341
334342 subchannel = picker .pickSubchannel (searchSubchannelArgs ).getSubchannel ();
335343 assertThat (subchannelIsReady (subchannel )).isTrue ();
336344 assertThat (subchannel ).isSameInstanceAs (fallbackSubchannel );
337- verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , 3 , 1 , "defaultTarget" , "complete" );
345+ verifyLongCounterAdd ("grpc.lb.rls.default_target_picks" , ++times , 1 , "defaultTarget" ,
346+ "complete" );
338347
339348 // Make sure that when RLS starts communicating that default stops being used
340349 fakeThrottler .nextResult = false ;
@@ -345,7 +354,8 @@ public void lb_working_withDefaultTarget_noRlsResponse() throws Exception {
345354 (FakeSubchannel ) markReadyAndGetPickResult (inOrder , searchSubchannelArgs ).getSubchannel ();
346355 assertThat (searchSubchannel ).isNotNull ();
347356 assertThat (searchSubchannel ).isNotSameInstanceAs (fallbackSubchannel );
348- verifyLongCounterAdd ("grpc.lb.rls.target_picks" , 1 , 1 , "wilderness" , "complete" );
357+ times = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
358+ verifyLongCounterAdd ("grpc.lb.rls.target_picks" , times , 1 , "wilderness" , "complete" );
349359
350360 // create rescue subchannel
351361 picker .pickSubchannel (rescueSubchannelArgs );
@@ -389,6 +399,8 @@ public void lb_working_withoutDefaultTarget() throws Exception {
389399 .updateBalancingState (eq (ConnectivityState .CONNECTING ), any (SubchannelPicker .class ));
390400 inOrder .verify (helper , atLeast (0 )).getSynchronizationContext ();
391401 inOrder .verify (helper , atLeast (0 )).getScheduledExecutorService ();
402+ inOrder .verify (helper , atLeast (0 )).getMetricRecorder ();
403+ inOrder .verify (helper , atLeast (0 )).getChannelTarget ();
392404 inOrder .verifyNoMoreInteractions ();
393405 assertThat (res .getStatus ().isOk ()).isTrue ();
394406
@@ -425,7 +437,8 @@ public void lb_working_withoutDefaultTarget() throws Exception {
425437 res = picker .pickSubchannel (newPickSubchannelArgs (fakeSearchMethod ));
426438 assertThat (res .getStatus ().isOk ()).isFalse ();
427439 assertThat (subchannelIsReady (res .getSubchannel ())).isFalse ();
428- verifyLongCounterAdd ("grpc.lb.rls.target_picks" , 1 , 1 , "wilderness" , "complete" );
440+ int expectedTimes = PickFirstLoadBalancerProvider .isEnabledNewPickFirst () ? 1 : 2 ;
441+ verifyLongCounterAdd ("grpc.lb.rls.target_picks" , expectedTimes , 1 , "wilderness" , "complete" );
429442
430443 res = picker .pickSubchannel (newPickSubchannelArgs (fakeRescueMethod ));
431444 assertThat (subchannelIsReady (res .getSubchannel ())).isTrue ();
0 commit comments