use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.
the class InternalSubchannelTest method updateAddresses_intersecting_ready.
@Test
public void updateAddresses_intersecting_ready() {
SocketAddress addr1 = mock(SocketAddress.class);
SocketAddress addr2 = mock(SocketAddress.class);
SocketAddress addr3 = mock(SocketAddress.class);
createInternalSubchannel(addr1, addr2);
assertEquals(IDLE, internalSubchannel.getState());
// First address fails
assertNull(internalSubchannel.obtainActiveTransport());
assertExactCallbackInvokes("onStateChange:CONNECTING");
verify(mockTransportFactory).newClientTransport(eq(addr1), eq(createClientTransportOptions()), isA(TransportLogger.class));
transports.poll().listener.transportShutdown(Status.UNAVAILABLE);
assertEquals(CONNECTING, internalSubchannel.getState());
// Second address connects
verify(mockTransportFactory).newClientTransport(eq(addr2), eq(createClientTransportOptions()), isA(TransportLogger.class));
transports.peek().listener.transportReady();
assertExactCallbackInvokes("onStateChange:READY");
assertEquals(READY, internalSubchannel.getState());
// Update addresses
internalSubchannel.updateAddresses(Arrays.asList(new EquivalentAddressGroup(Arrays.asList(addr2, addr3))));
assertNoCallbackInvoke();
assertEquals(READY, internalSubchannel.getState());
verify(transports.peek().transport, never()).shutdown(any(Status.class));
verify(transports.peek().transport, never()).shutdownNow(any(Status.class));
// And new addresses chosen when re-connecting
transports.poll().listener.transportShutdown(Status.UNAVAILABLE);
assertExactCallbackInvokes("onStateChange:IDLE");
assertNull(internalSubchannel.obtainActiveTransport());
assertEquals(0, fakeClock.numPendingTasks());
verify(mockTransportFactory, times(2)).newClientTransport(eq(addr2), eq(createClientTransportOptions()), isA(TransportLogger.class));
transports.poll().listener.transportShutdown(Status.UNAVAILABLE);
verify(mockTransportFactory).newClientTransport(eq(addr3), eq(createClientTransportOptions()), isA(TransportLogger.class));
transports.poll().listener.transportShutdown(Status.UNAVAILABLE);
verifyNoMoreInteractions(mockTransportFactory);
// Drain retry, but don't care about result
fakeClock.forwardNanos(10);
}
use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.
the class InternalSubchannelTest method index_looping.
@Test
public void index_looping() {
Attributes.Key<String> key = Attributes.Key.create("some-key");
Attributes attr1 = Attributes.newBuilder().set(key, "1").build();
Attributes attr2 = Attributes.newBuilder().set(key, "2").build();
Attributes attr3 = Attributes.newBuilder().set(key, "3").build();
SocketAddress addr1 = new FakeSocketAddress();
SocketAddress addr2 = new FakeSocketAddress();
SocketAddress addr3 = new FakeSocketAddress();
SocketAddress addr4 = new FakeSocketAddress();
SocketAddress addr5 = new FakeSocketAddress();
Index index = new Index(Arrays.asList(new EquivalentAddressGroup(Arrays.asList(addr1, addr2), attr1), new EquivalentAddressGroup(Arrays.asList(addr3), attr2), new EquivalentAddressGroup(Arrays.asList(addr4, addr5), attr3)));
assertThat(index.getCurrentAddress()).isSameInstanceAs(addr1);
assertThat(index.getCurrentEagAttributes()).isSameInstanceAs(attr1);
assertThat(index.isAtBeginning()).isTrue();
assertThat(index.isValid()).isTrue();
index.increment();
assertThat(index.getCurrentAddress()).isSameInstanceAs(addr2);
assertThat(index.getCurrentEagAttributes()).isSameInstanceAs(attr1);
assertThat(index.isAtBeginning()).isFalse();
assertThat(index.isValid()).isTrue();
index.increment();
assertThat(index.getCurrentAddress()).isSameInstanceAs(addr3);
assertThat(index.getCurrentEagAttributes()).isSameInstanceAs(attr2);
assertThat(index.isAtBeginning()).isFalse();
assertThat(index.isValid()).isTrue();
index.increment();
assertThat(index.getCurrentAddress()).isSameInstanceAs(addr4);
assertThat(index.getCurrentEagAttributes()).isSameInstanceAs(attr3);
assertThat(index.isAtBeginning()).isFalse();
assertThat(index.isValid()).isTrue();
index.increment();
assertThat(index.getCurrentAddress()).isSameInstanceAs(addr5);
assertThat(index.getCurrentEagAttributes()).isSameInstanceAs(attr3);
assertThat(index.isAtBeginning()).isFalse();
assertThat(index.isValid()).isTrue();
index.increment();
assertThat(index.isAtBeginning()).isFalse();
assertThat(index.isValid()).isFalse();
index.reset();
assertThat(index.getCurrentAddress()).isSameInstanceAs(addr1);
assertThat(index.getCurrentEagAttributes()).isSameInstanceAs(attr1);
assertThat(index.isAtBeginning()).isTrue();
assertThat(index.isValid()).isTrue();
// We want to make sure both groupIndex and addressIndex are reset
index.increment();
index.increment();
index.increment();
index.increment();
assertThat(index.getCurrentAddress()).isSameInstanceAs(addr5);
assertThat(index.getCurrentEagAttributes()).isSameInstanceAs(attr3);
index.reset();
assertThat(index.getCurrentAddress()).isSameInstanceAs(addr1);
assertThat(index.getCurrentEagAttributes()).isSameInstanceAs(attr1);
}
use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.
the class InternalSubchannelTest method updateAddresses_eagListWithNull_throws.
@Test
public void updateAddresses_eagListWithNull_throws() {
SocketAddress addr = new FakeSocketAddress();
createInternalSubchannel(addr);
List<EquivalentAddressGroup> eags = Arrays.asList((EquivalentAddressGroup) null);
thrown.expect(NullPointerException.class);
internalSubchannel.updateAddresses(eags);
}
use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.
the class InternalSubchannelTest method updateAddresses_disjoint_connecting.
@Test
public void updateAddresses_disjoint_connecting() {
SocketAddress addr1 = mock(SocketAddress.class);
SocketAddress addr2 = mock(SocketAddress.class);
SocketAddress addr3 = mock(SocketAddress.class);
SocketAddress addr4 = mock(SocketAddress.class);
createInternalSubchannel(addr1, addr2);
assertEquals(IDLE, internalSubchannel.getState());
// First address fails
assertNull(internalSubchannel.obtainActiveTransport());
assertExactCallbackInvokes("onStateChange:CONNECTING");
verify(mockTransportFactory).newClientTransport(eq(addr1), eq(createClientTransportOptions()), isA(TransportLogger.class));
transports.poll().listener.transportShutdown(Status.UNAVAILABLE);
assertEquals(CONNECTING, internalSubchannel.getState());
// Second address connecting
verify(mockTransportFactory).newClientTransport(eq(addr2), eq(createClientTransportOptions()), isA(TransportLogger.class));
assertNoCallbackInvoke();
assertEquals(CONNECTING, internalSubchannel.getState());
// Update addresses
internalSubchannel.updateAddresses(Arrays.asList(new EquivalentAddressGroup(Arrays.asList(addr3, addr4))));
assertNoCallbackInvoke();
assertEquals(CONNECTING, internalSubchannel.getState());
// And new addresses chosen immediately
verify(transports.poll().transport).shutdown(any(Status.class));
assertNoCallbackInvoke();
assertEquals(CONNECTING, internalSubchannel.getState());
assertNull(internalSubchannel.obtainActiveTransport());
assertEquals(0, fakeClock.numPendingTasks());
verify(mockTransportFactory).newClientTransport(eq(addr3), eq(createClientTransportOptions()), isA(TransportLogger.class));
transports.poll().listener.transportShutdown(Status.UNAVAILABLE);
verify(mockTransportFactory).newClientTransport(eq(addr4), eq(createClientTransportOptions()), isA(TransportLogger.class));
transports.poll().listener.transportShutdown(Status.UNAVAILABLE);
verifyNoMoreInteractions(mockTransportFactory);
// Drain retry, but don't care about result
fakeClock.forwardNanos(10);
}
use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.
the class InternalSubchannelTest method updateAddresses_disjoint_readyTwice.
@Test
public void updateAddresses_disjoint_readyTwice() {
SocketAddress addr1 = mock(SocketAddress.class);
createInternalSubchannel(addr1);
assertEquals(IDLE, internalSubchannel.getState());
// Address connects
assertNull(internalSubchannel.obtainActiveTransport());
assertExactCallbackInvokes("onStateChange:CONNECTING");
verify(mockTransportFactory).newClientTransport(eq(addr1), eq(createClientTransportOptions()), isA(TransportLogger.class));
transports.peek().listener.transportReady();
assertExactCallbackInvokes("onStateChange:READY");
assertEquals(READY, internalSubchannel.getState());
// Update addresses
SocketAddress addr2 = mock(SocketAddress.class);
internalSubchannel.updateAddresses(Arrays.asList(new EquivalentAddressGroup(Arrays.asList(addr2))));
assertExactCallbackInvokes("onStateChange:IDLE");
assertEquals(IDLE, internalSubchannel.getState());
ConnectionClientTransport firstTransport = transports.poll().transport;
verify(firstTransport, never()).shutdown(any(Status.class));
// Address connects
assertNull(internalSubchannel.obtainActiveTransport());
assertExactCallbackInvokes("onStateChange:CONNECTING");
verify(mockTransportFactory).newClientTransport(eq(addr2), eq(createClientTransportOptions()), isA(TransportLogger.class));
transports.peek().listener.transportReady();
assertExactCallbackInvokes("onStateChange:READY");
assertEquals(READY, internalSubchannel.getState());
// Update addresses
SocketAddress addr3 = mock(SocketAddress.class);
internalSubchannel.updateAddresses(Arrays.asList(new EquivalentAddressGroup(Arrays.asList(addr3))));
assertExactCallbackInvokes("onStateChange:IDLE");
assertEquals(IDLE, internalSubchannel.getState());
// Earlier transport is shutdown eagerly
verify(firstTransport).shutdown(any(Status.class));
ConnectionClientTransport secondTransport = transports.peek().transport;
verify(secondTransport, never()).shutdown(any(Status.class));
internalSubchannel.shutdown(SHUTDOWN_REASON);
verify(secondTransport).shutdown(any(Status.class));
}
Aggregations