Skip to content

Commit 434c07b

Browse files
committed
address comments
1 parent bd7aa4c commit 434c07b

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,11 @@ public boolean equals(Object other) {
11861186
public String toString() {
11871187
return "ChildLbPickerEntry(" + childPicker + ")";
11881188
}
1189+
1190+
@VisibleForTesting
1191+
SubchannelPicker getChildPicker() {
1192+
return childPicker;
1193+
}
11891194
}
11901195

11911196
@VisibleForTesting

grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import io.grpc.Status.Code;
7373
import io.grpc.SynchronizationContext;
7474
import io.grpc.grpclb.GrpclbState.BackendEntry;
75+
import io.grpc.grpclb.GrpclbState.ChildLbPickerEntry;
7576
import io.grpc.grpclb.GrpclbState.DropEntry;
7677
import io.grpc.grpclb.GrpclbState.ErrorEntry;
7778
import io.grpc.grpclb.GrpclbState.IdleSubchannelEntry;
@@ -1933,13 +1934,31 @@ public void grpclbWorking_pickFirstMode() throws Exception {
19331934
// One subchannel is created by the child LB
19341935
assertThat(mockSubchannels).hasSize(1);
19351936
Subchannel subchannel = mockSubchannels.poll();
1937+
verify(subchannel).requestConnection();
19361938
assertThat(picker0.dropList).containsExactly(null, null);
1939+
assertThat(picker0.pickList).hasSize(1);
1940+
assertThat(picker0.pickList.get(0)).isInstanceOf(ChildLbPickerEntry.class);
19371941

19381942
// READY
19391943
deliverSubchannelState(subchannel, ConnectivityStateInfo.forNonError(READY));
19401944
verify(helper, atLeast(1)).updateBalancingState(eq(READY), pickerCaptor.capture());
19411945
RoundRobinPicker picker1 = (RoundRobinPicker) pickerCaptor.getValue();
19421946
assertThat(picker1.dropList).containsExactly(null, null);
1947+
assertThat(picker1.pickList).hasSize(1);
1948+
ChildLbPickerEntry readyEntry = (ChildLbPickerEntry) picker1.pickList.get(0);
1949+
PickResult readyResult =
1950+
readyEntry.getChildPicker().pickSubchannel(mock(PickSubchannelArgs.class));
1951+
assertThat(readyResult.getSubchannel()).isEqualTo(subchannel);
1952+
1953+
Status error = Status.UNAVAILABLE.withDescription("Simulated connection error");
1954+
deliverSubchannelState(subchannel, ConnectivityStateInfo.forTransientFailure(error));
1955+
verify(helper, atLeast(1)).updateBalancingState(eq(TRANSIENT_FAILURE), pickerCaptor.capture());
1956+
RoundRobinPicker failurePicker = (RoundRobinPicker) pickerCaptor.getValue();
1957+
assertThat(failurePicker.pickList).hasSize(1);
1958+
ChildLbPickerEntry failureEntry = (ChildLbPickerEntry) failurePicker.pickList.get(0);
1959+
PickResult failureResult =
1960+
failureEntry.getChildPicker().pickSubchannel(mock(PickSubchannelArgs.class));
1961+
assertThat(failureResult.getStatus()).isEqualTo(error);
19431962

19441963
// New server list with drops
19451964
List<ServerEntry> backends2 = Arrays.asList(
@@ -2108,6 +2127,14 @@ private void pickFirstModeFallback(long timeout) throws Exception {
21082127
// READY
21092128
deliverSubchannelState(subchannel, ConnectivityStateInfo.forNonError(READY));
21102129
verify(helper, atLeast(1)).updateBalancingState(eq(READY), pickerCaptor.capture());
2130+
deliverSubchannelState(subchannel, ConnectivityStateInfo.forNonError(IDLE));
2131+
verify(helper, atLeast(1)).updateBalancingState(eq(IDLE), pickerCaptor.capture());
2132+
RoundRobinPicker pickerIdle = (RoundRobinPicker) pickerCaptor.getValue();
2133+
verify(subchannel, times(1)).requestConnection();
2134+
2135+
// Picking while IDLE should trigger a new connection request
2136+
pickerIdle.pickSubchannel(mock(PickSubchannelArgs.class));
2137+
verify(subchannel, times(2)).requestConnection();
21112138

21122139
// Finally, an LB response, which brings us out of fallback
21132140
List<ServerEntry> backends1 = Arrays.asList(

0 commit comments

Comments
 (0)