util: Replace RR.EmptyPicker with FixedResultPicker · grpc/grpc-java@f20167d

@@ -46,15 +46,16 @@

4646

import io.grpc.EquivalentAddressGroup;

4747

import io.grpc.LoadBalancer;

4848

import io.grpc.LoadBalancer.CreateSubchannelArgs;

49+

import io.grpc.LoadBalancer.FixedResultPicker;

4950

import io.grpc.LoadBalancer.Helper;

51+

import io.grpc.LoadBalancer.PickResult;

5052

import io.grpc.LoadBalancer.PickSubchannelArgs;

5153

import io.grpc.LoadBalancer.ResolvedAddresses;

5254

import io.grpc.LoadBalancer.Subchannel;

5355

import io.grpc.LoadBalancer.SubchannelPicker;

5456

import io.grpc.Status;

5557

import io.grpc.internal.TestUtils;

5658

import io.grpc.util.MultiChildLoadBalancer.ChildLbState;

57-

import io.grpc.util.RoundRobinLoadBalancer.EmptyPicker;

5859

import io.grpc.util.RoundRobinLoadBalancer.ReadyPicker;

5960

import java.net.SocketAddress;

6061

import java.util.ArrayList;

8485

@RunWith(JUnit4.class)

8586

public class RoundRobinLoadBalancerTest {

8687

private static final Attributes.Key<String> MAJOR_KEY = Attributes.Key.create("major-key");

88+

private static final SubchannelPicker EMPTY_PICKER =

89+

new FixedResultPicker(PickResult.withNoResult());

87908891

@Rule public final MockitoRule mocks = MockitoJUnit.rule();

8992

@@ -248,7 +251,7 @@ public void pickAfterStateChange() throws Exception {

248251

ChildLbState childLbState = loadBalancer.getChildLbStates().iterator().next();

249252

Subchannel subchannel = subchannels.get(Arrays.asList(childLbState.getEag()));

250253251-

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), isA(EmptyPicker.class));

254+

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), eq(EMPTY_PICKER));

252255

assertThat(childLbState.getCurrentState()).isEqualTo(CONNECTING);

253256254257

deliverSubchannelState(subchannel, ConnectivityStateInfo.forNonError(READY));

@@ -261,7 +264,7 @@ public void pickAfterStateChange() throws Exception {

261264

ConnectivityStateInfo.forTransientFailure(error));

262265

assertThat(childLbState.getCurrentState()).isEqualTo(TRANSIENT_FAILURE);

263266

AbstractTestHelper.refreshInvokedAndUpdateBS(inOrder, CONNECTING, mockHelper, pickerCaptor);

264-

assertThat(pickerCaptor.getValue()).isInstanceOf(EmptyPicker.class);

267+

assertThat(pickerCaptor.getValue()).isEqualTo(EMPTY_PICKER);

265268266269

deliverSubchannelState(subchannel, ConnectivityStateInfo.forNonError(IDLE));

267270

inOrder.verify(mockHelper).refreshNameResolution();

@@ -277,7 +280,7 @@ public void ignoreShutdownSubchannelStateChange() {

277280

InOrder inOrder = inOrder(mockHelper);

278281

Status addressesAcceptanceStatus = acceptAddresses(servers, Attributes.EMPTY);

279282

assertThat(addressesAcceptanceStatus.isOk()).isTrue();

280-

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), isA(EmptyPicker.class));

283+

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), eq(EMPTY_PICKER));

281284282285

loadBalancer.shutdown();

283286

for (ChildLbState child : loadBalancer.getChildLbStates()) {

@@ -297,7 +300,7 @@ public void stayTransientFailureUntilReady() {

297300

Status addressesAcceptanceStatus = acceptAddresses(servers, Attributes.EMPTY);

298301

assertThat(addressesAcceptanceStatus.isOk()).isTrue();

299302300-

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), isA(EmptyPicker.class));

303+

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), eq(EMPTY_PICKER));

301304302305

Map<ChildLbState, Subchannel> childToSubChannelMap = new HashMap<>();

303306

// Simulate state transitions for each subchannel individually.

@@ -336,7 +339,7 @@ public void refreshNameResolutionWhenSubchannelConnectionBroken() {

336339

assertThat(addressesAcceptanceStatus.isOk()).isTrue();

337340338341

verify(mockHelper, times(3)).createSubchannel(any(CreateSubchannelArgs.class));

339-

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), isA(EmptyPicker.class));

342+

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), eq(EMPTY_PICKER));

340343341344

// Simulate state transitions for each subchannel individually.

342345

for (ChildLbState child : loadBalancer.getChildLbStates()) {

@@ -352,7 +355,7 @@ public void refreshNameResolutionWhenSubchannelConnectionBroken() {

352355

deliverSubchannelState(sc, ConnectivityStateInfo.forNonError(IDLE));

353356

inOrder.verify(mockHelper).refreshNameResolution();

354357

verify(sc, times(2)).requestConnection();

355-

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), isA(EmptyPicker.class));

358+

inOrder.verify(mockHelper).updateBalancingState(eq(CONNECTING), eq(EMPTY_PICKER));

356359

}

357360358361

AbstractTestHelper.verifyNoMoreMeaningfulInteractions(mockHelper);

@@ -461,7 +464,7 @@ public void subchannelStateIsolation() throws Exception {

461464

Iterator<SubchannelPicker> pickers = pickerCaptor.getAllValues().iterator();

462465

// The picker is incrementally updated as subchannels become READY

463466

assertEquals(CONNECTING, stateIterator.next());

464-

assertThat(pickers.next()).isInstanceOf(EmptyPicker.class);

467+

assertThat(pickers.next()).isEqualTo(EMPTY_PICKER);

465468

assertEquals(READY, stateIterator.next());

466469

assertThat(getList(pickers.next())).containsExactly(sc1);

467470

assertEquals(READY, stateIterator.next());

@@ -492,8 +495,8 @@ public void readyPicker_emptyList() {

492495493496

@Test

494497

public void internalPickerComparisons() {

495-

SubchannelPicker empty1 = new EmptyPicker();

496-

SubchannelPicker empty2 = new EmptyPicker();

498+

SubchannelPicker empty1 = new FixedResultPicker(PickResult.withNoResult());

499+

SubchannelPicker empty2 = new FixedResultPicker(PickResult.withNoResult());

497500498501

AtomicInteger seq = new AtomicInteger(0);

499502

acceptAddresses(servers, Attributes.EMPTY); // create subchannels