Search in sources :

Example 1 with ReadyPicker

use of io.grpc.util.RoundRobinLoadBalancer.ReadyPicker in project grpc-java by grpc.

the class RoundRobinLoadBalancerTest method pickerRoundRobin.

@Test
public void pickerRoundRobin() throws Exception {
    Subchannel subchannel = mock(Subchannel.class);
    Subchannel subchannel1 = mock(Subchannel.class);
    Subchannel subchannel2 = mock(Subchannel.class);
    ReadyPicker picker = new ReadyPicker(Collections.unmodifiableList(Lists.newArrayList(subchannel, subchannel1, subchannel2)), 0);
    assertThat(picker.getList()).containsExactly(subchannel, subchannel1, subchannel2);
    assertEquals(subchannel, picker.pickSubchannel(mockArgs).getSubchannel());
    assertEquals(subchannel1, picker.pickSubchannel(mockArgs).getSubchannel());
    assertEquals(subchannel2, picker.pickSubchannel(mockArgs).getSubchannel());
    assertEquals(subchannel, picker.pickSubchannel(mockArgs).getSubchannel());
}
Also used : Subchannel(io.grpc.LoadBalancer.Subchannel) ReadyPicker(io.grpc.util.RoundRobinLoadBalancer.ReadyPicker) Test(org.junit.Test)

Example 2 with ReadyPicker

use of io.grpc.util.RoundRobinLoadBalancer.ReadyPicker in project grpc-java by grpc.

the class RoundRobinLoadBalancerTest method internalPickerComparisons.

@Test
public void internalPickerComparisons() {
    EmptyPicker emptyOk1 = new EmptyPicker(Status.OK);
    EmptyPicker emptyOk2 = new EmptyPicker(Status.OK.withDescription("different OK"));
    EmptyPicker emptyErr = new EmptyPicker(Status.UNKNOWN.withDescription("¯\\_(ツ)_//¯"));
    Iterator<Subchannel> subchannelIterator = subchannels.values().iterator();
    Subchannel sc1 = subchannelIterator.next();
    Subchannel sc2 = subchannelIterator.next();
    ReadyPicker ready1 = new ReadyPicker(Arrays.asList(sc1, sc2), 0);
    ReadyPicker ready2 = new ReadyPicker(Arrays.asList(sc1), 0);
    ReadyPicker ready3 = new ReadyPicker(Arrays.asList(sc2, sc1), 1);
    ReadyPicker ready4 = new ReadyPicker(Arrays.asList(sc1, sc2), 1);
    ReadyPicker ready5 = new ReadyPicker(Arrays.asList(sc2, sc1), 0);
    assertTrue(emptyOk1.isEquivalentTo(emptyOk2));
    assertFalse(emptyOk1.isEquivalentTo(emptyErr));
    assertFalse(ready1.isEquivalentTo(ready2));
    assertTrue(ready1.isEquivalentTo(ready3));
    assertTrue(ready3.isEquivalentTo(ready4));
    assertTrue(ready4.isEquivalentTo(ready5));
    assertFalse(emptyOk1.isEquivalentTo(ready1));
    assertFalse(ready1.isEquivalentTo(emptyOk1));
}
Also used : EmptyPicker(io.grpc.util.RoundRobinLoadBalancer.EmptyPicker) Subchannel(io.grpc.LoadBalancer.Subchannel) ReadyPicker(io.grpc.util.RoundRobinLoadBalancer.ReadyPicker) Test(org.junit.Test)

Aggregations

Subchannel (io.grpc.LoadBalancer.Subchannel)2 ReadyPicker (io.grpc.util.RoundRobinLoadBalancer.ReadyPicker)2 Test (org.junit.Test)2 EmptyPicker (io.grpc.util.RoundRobinLoadBalancer.EmptyPicker)1