61
61
import java .util .ArrayList ;
62
62
import java .util .Arrays ;
63
63
import java .util .Collections ;
64
- import java .util .HashMap ;
65
64
import java .util .Iterator ;
66
65
import java .util .List ;
67
66
import java .util .Map ;
@@ -207,10 +206,6 @@ public void pickAfterResolvedUpdatedHosts() throws Exception {
207
206
assertThat (childLbState .getResolvedAddresses ().getAttributes ().get (IS_PETIOLE_POLICY ))
208
207
.isTrue ();
209
208
}
210
- assertThat (loadBalancer .getChildLbStateEag (removedEag ).getCurrentPicker ().pickSubchannel (null )
211
- .getSubchannel ()).isEqualTo (removedSubchannel );
212
- assertThat (loadBalancer .getChildLbStateEag (oldEag1 ).getCurrentPicker ().pickSubchannel (null )
213
- .getSubchannel ()).isEqualTo (oldSubchannel );
214
209
215
210
// This time with Attributes
216
211
List <EquivalentAddressGroup > latestServers = Lists .newArrayList (oldEag2 , newEag );
@@ -225,12 +220,6 @@ public void pickAfterResolvedUpdatedHosts() throws Exception {
225
220
226
221
deliverSubchannelState (newSubchannel , ConnectivityStateInfo .forNonError (READY ));
227
222
228
- assertThat (loadBalancer .getChildLbStates ().size ()).isEqualTo (2 );
229
- assertThat (loadBalancer .getChildLbStateEag (newEag ).getCurrentPicker ()
230
- .pickSubchannel (null ).getSubchannel ()).isEqualTo (newSubchannel );
231
- assertThat (loadBalancer .getChildLbStateEag (oldEag2 ).getCurrentPicker ()
232
- .pickSubchannel (null ).getSubchannel ()).isEqualTo (oldSubchannel );
233
-
234
223
verify (mockHelper , times (6 )).createSubchannel (any (CreateSubchannelArgs .class ));
235
224
inOrder .verify (mockHelper , times (2 )).updateBalancingState (eq (READY ), pickerCaptor .capture ());
236
225
@@ -243,35 +232,35 @@ public void pickAfterResolvedUpdatedHosts() throws Exception {
243
232
@ Test
244
233
public void pickAfterStateChange () throws Exception {
245
234
InOrder inOrder = inOrder (mockHelper );
246
- Status addressesAcceptanceStatus = acceptAddresses (servers , Attributes .EMPTY );
235
+ Status addressesAcceptanceStatus =
236
+ acceptAddresses (Arrays .asList (servers .get (0 )), Attributes .EMPTY );
247
237
assertThat (addressesAcceptanceStatus .isOk ()).isTrue ();
238
+ inOrder .verify (mockHelper ).createSubchannel (any (CreateSubchannelArgs .class ));
248
239
249
240
// TODO figure out if this method testing the right things
250
241
251
- ChildLbState childLbState = loadBalancer . getChildLbStates (). iterator (). next ( );
252
- Subchannel subchannel = subchannels .get ( Arrays . asList ( childLbState . getEag ()) );
242
+ assertThat ( subchannels ). hasSize ( 1 );
243
+ Subchannel subchannel = subchannels .values (). iterator (). next ( );
253
244
254
245
inOrder .verify (mockHelper ).updateBalancingState (eq (CONNECTING ), eq (EMPTY_PICKER ));
255
- assertThat (childLbState .getCurrentState ()).isEqualTo (CONNECTING );
256
246
257
247
deliverSubchannelState (subchannel , ConnectivityStateInfo .forNonError (READY ));
258
248
inOrder .verify (mockHelper ).updateBalancingState (eq (READY ), pickerCaptor .capture ());
259
249
assertThat (pickerCaptor .getValue ()).isInstanceOf (ReadyPicker .class );
260
- assertThat (childLbState .getCurrentState ()).isEqualTo (READY );
261
250
262
251
Status error = Status .UNKNOWN .withDescription ("¯\\ _(ツ)_//¯" );
263
252
deliverSubchannelState (subchannel ,
264
253
ConnectivityStateInfo .forTransientFailure (error ));
265
- assertThat ( childLbState . getCurrentState ()). isEqualTo ( TRANSIENT_FAILURE );
266
- AbstractTestHelper . refreshInvokedAndUpdateBS ( inOrder , CONNECTING , mockHelper , pickerCaptor );
267
- assertThat (pickerCaptor .getValue ()). isEqualTo (EMPTY_PICKER );
254
+ AbstractTestHelper . refreshInvokedAndUpdateBS (
255
+ inOrder , TRANSIENT_FAILURE , mockHelper , pickerCaptor );
256
+ assertThat (pickerCaptor .getValue (). pickSubchannel ( mockArgs ). getStatus ()). isEqualTo (error );
268
257
269
258
deliverSubchannelState (subchannel , ConnectivityStateInfo .forNonError (IDLE ));
270
259
inOrder .verify (mockHelper ).refreshNameResolution ();
271
- assertThat (childLbState .getCurrentState ()).isEqualTo (TRANSIENT_FAILURE );
260
+ inOrder .verify (mockHelper , never ())
261
+ .updateBalancingState (eq (TRANSIENT_FAILURE ), any (SubchannelPicker .class ));
272
262
273
263
verify (subchannel , atLeastOnce ()).requestConnection ();
274
- verify (mockHelper , times (3 )).createSubchannel (any (CreateSubchannelArgs .class ));
275
264
AbstractTestHelper .verifyNoMoreMeaningfulInteractions (mockHelper );
276
265
}
277
266
@@ -282,10 +271,10 @@ public void ignoreShutdownSubchannelStateChange() {
282
271
assertThat (addressesAcceptanceStatus .isOk ()).isTrue ();
283
272
inOrder .verify (mockHelper ).updateBalancingState (eq (CONNECTING ), eq (EMPTY_PICKER ));
284
273
274
+ List <Subchannel > savedSubchannels = new ArrayList <>(subchannels .values ());
285
275
loadBalancer .shutdown ();
286
- for (ChildLbState child : loadBalancer .getChildLbStates ()) {
287
- Subchannel sc = child .getCurrentPicker ().pickSubchannel (null ).getSubchannel ();
288
- verify (child ).shutdown ();
276
+ for (Subchannel sc : savedSubchannels ) {
277
+ verify (sc ).shutdown ();
289
278
// When the subchannel is being shut down, a SHUTDOWN connectivity state is delivered
290
279
// back to the subchannel state listener.
291
280
deliverSubchannelState (sc , ConnectivityStateInfo .forNonError (SHUTDOWN ));
@@ -300,34 +289,27 @@ public void stayTransientFailureUntilReady() {
300
289
Status addressesAcceptanceStatus = acceptAddresses (servers , Attributes .EMPTY );
301
290
assertThat (addressesAcceptanceStatus .isOk ()).isTrue ();
302
291
292
+ inOrder .verify (mockHelper , times (3 )).createSubchannel (any (CreateSubchannelArgs .class ));
303
293
inOrder .verify (mockHelper ).updateBalancingState (eq (CONNECTING ), eq (EMPTY_PICKER ));
304
294
305
- Map <ChildLbState , Subchannel > childToSubChannelMap = new HashMap <>();
306
295
// Simulate state transitions for each subchannel individually.
307
- for ( ChildLbState child : loadBalancer .getChildLbStates ()) {
308
- Subchannel sc = subchannels .get (Arrays .asList (child .getEag ()));
309
- childToSubChannelMap .put (child , sc );
296
+ for (Subchannel sc : subchannels .values ()) {
310
297
Status error = Status .UNKNOWN .withDescription ("connection broken" );
311
298
deliverSubchannelState (
312
299
sc ,
313
300
ConnectivityStateInfo .forTransientFailure (error ));
314
- assertEquals (TRANSIENT_FAILURE , child .getCurrentState ());
315
301
deliverSubchannelState (
316
302
sc ,
317
303
ConnectivityStateInfo .forNonError (CONNECTING ));
318
- assertEquals (TRANSIENT_FAILURE , child .getCurrentState ());
319
304
}
320
305
inOrder .verify (mockHelper ).updateBalancingState (eq (TRANSIENT_FAILURE ), isA (ReadyPicker .class ));
321
306
inOrder .verify (mockHelper , atLeast (0 )).refreshNameResolution ();
322
307
inOrder .verifyNoMoreInteractions ();
323
308
324
- ChildLbState child = loadBalancer .getChildLbStates ().iterator ().next ();
325
- Subchannel subchannel = childToSubChannelMap .get (child );
309
+ Subchannel subchannel = subchannels .values ().iterator ().next ();
326
310
deliverSubchannelState (subchannel , ConnectivityStateInfo .forNonError (READY ));
327
- assertThat (child .getCurrentState ()).isEqualTo (READY );
328
311
inOrder .verify (mockHelper ).updateBalancingState (eq (READY ), isA (ReadyPicker .class ));
329
312
330
- verify (mockHelper , times (3 )).createSubchannel (any (CreateSubchannelArgs .class ));
331
313
inOrder .verify (mockHelper , atLeast (0 )).refreshNameResolution ();
332
314
inOrder .verifyNoMoreInteractions ();
333
315
}
@@ -342,8 +324,7 @@ public void refreshNameResolutionWhenSubchannelConnectionBroken() {
342
324
inOrder .verify (mockHelper ).updateBalancingState (eq (CONNECTING ), eq (EMPTY_PICKER ));
343
325
344
326
// Simulate state transitions for each subchannel individually.
345
- for (ChildLbState child : loadBalancer .getChildLbStates ()) {
346
- Subchannel sc = subchannels .get (Arrays .asList (child .getEag ()));
327
+ for (Subchannel sc : subchannels .values ()) {
347
328
verify (sc ).requestConnection ();
348
329
deliverSubchannelState (sc , ConnectivityStateInfo .forNonError (CONNECTING ));
349
330
Status error = Status .UNKNOWN .withDescription ("connection broken" );
0 commit comments