use of io.grpc.LoadBalancer.Subchannel in project grpc-java by grpc.
the class ManagedChannelImplTest method subchannelsWhenChannelShutdownNow.
@Test
public void subchannelsWhenChannelShutdownNow() {
createChannel(new FakeNameResolverFactory(true), NO_INTERCEPTOR);
Subchannel sub1 = helper.createSubchannel(addressGroup, Attributes.EMPTY);
Subchannel sub2 = helper.createSubchannel(addressGroup, Attributes.EMPTY);
sub1.requestConnection();
sub2.requestConnection();
assertEquals(2, transports.size());
MockClientTransportInfo ti1 = transports.poll();
MockClientTransportInfo ti2 = transports.poll();
ti1.listener.transportReady();
ti2.listener.transportReady();
channel.shutdownNow();
verify(ti1.transport).shutdownNow(any(Status.class));
verify(ti2.transport).shutdownNow(any(Status.class));
ti1.listener.transportShutdown(Status.UNAVAILABLE.withDescription("shutdown now"));
ti2.listener.transportShutdown(Status.UNAVAILABLE.withDescription("shutdown now"));
ti1.listener.transportTerminated();
assertFalse(channel.isTerminated());
ti2.listener.transportTerminated();
assertTrue(channel.isTerminated());
}
use of io.grpc.LoadBalancer.Subchannel in project grpc-java by grpc.
the class PickFirstLoadBalancerTest method pickAfterResolvedAndChanged.
@Test
public void pickAfterResolvedAndChanged() throws Exception {
SocketAddress socketAddr = new FakeSocketAddress("newserver");
List<SocketAddress> newSocketAddresses = Lists.newArrayList(socketAddr);
List<ResolvedServerInfoGroup> newServers = Lists.newArrayList(ResolvedServerInfoGroup.builder().add(new ResolvedServerInfo(socketAddr)).build());
final Subchannel oldSubchannel = mock(Subchannel.class);
final EquivalentAddressGroup oldEag = new EquivalentAddressGroup(socketAddresses);
when(oldSubchannel.getAddresses()).thenReturn(oldEag);
final Subchannel newSubchannel = mock(Subchannel.class);
final EquivalentAddressGroup newEag = new EquivalentAddressGroup(newSocketAddresses);
when(newSubchannel.getAddresses()).thenReturn(newEag);
when(mockHelper.createSubchannel(eq(oldEag), any(Attributes.class))).thenReturn(oldSubchannel);
when(mockHelper.createSubchannel(eq(newEag), any(Attributes.class))).thenReturn(newSubchannel);
InOrder inOrder = inOrder(mockHelper);
loadBalancer.handleResolvedAddresses(servers, affinity);
inOrder.verify(mockHelper).createSubchannel(eagCaptor.capture(), any(Attributes.class));
inOrder.verify(mockHelper).updatePicker(pickerCaptor.capture());
assertEquals(socketAddresses, eagCaptor.getValue().getAddresses());
loadBalancer.handleResolvedAddresses(newServers, affinity);
inOrder.verify(mockHelper).createSubchannel(eagCaptor.capture(), any(Attributes.class));
inOrder.verify(mockHelper).updatePicker(pickerCaptor.capture());
assertEquals(newSocketAddresses, eagCaptor.getValue().getAddresses());
Subchannel subchannel = pickerCaptor.getAllValues().get(0).pickSubchannel(mockArgs).getSubchannel();
assertEquals(oldSubchannel, subchannel);
Subchannel subchannel2 = pickerCaptor.getAllValues().get(1).pickSubchannel(mockArgs).getSubchannel();
assertEquals(newSubchannel, subchannel2);
verify(subchannel2, never()).shutdown();
verifyNoMoreInteractions(mockHelper);
}
Aggregations