Search in sources :

Example 21 with AddressResolver

use of io.grpc.internal.DnsNameResolver.AddressResolver in project grpc-java by grpc.

the class GrpclbNameResolverTest method resolve_nullResourceResolver.

@Test
public void resolve_nullResourceResolver() throws Exception {
    InetAddress backendAddr = InetAddress.getByAddress(new byte[] { 127, 0, 0, 0 });
    AddressResolver mockAddressResolver = mock(AddressResolver.class);
    when(mockAddressResolver.resolveAddress(anyString())).thenReturn(Collections.singletonList(backendAddr));
    ResourceResolver resourceResolver = null;
    resolver.setAddressResolver(mockAddressResolver);
    resolver.setResourceResolver(resourceResolver);
    resolver.start(mockListener);
    assertThat(fakeClock.runDueTasks()).isEqualTo(1);
    verify(mockListener).onResult(resultCaptor.capture());
    ResolutionResult result = resultCaptor.getValue();
    assertThat(result.getAddresses()).containsExactly(new EquivalentAddressGroup(new InetSocketAddress(backendAddr, DEFAULT_PORT)));
    assertThat(result.getAttributes()).isEqualTo(Attributes.EMPTY);
    assertThat(result.getServiceConfig()).isNull();
}
Also used : AddressResolver(io.grpc.internal.DnsNameResolver.AddressResolver) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) InetSocketAddress(java.net.InetSocketAddress) ResolutionResult(io.grpc.NameResolver.ResolutionResult) ResourceResolver(io.grpc.internal.DnsNameResolver.ResourceResolver) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 22 with AddressResolver

use of io.grpc.internal.DnsNameResolver.AddressResolver in project grpc-java by grpc.

the class GrpclbNameResolverTest method resolve_emptyResult.

@Test
public void resolve_emptyResult() {
    resolver.setAddressResolver(new AddressResolver() {

        @Override
        public List<InetAddress> resolveAddress(String host) throws Exception {
            return Collections.emptyList();
        }
    });
    resolver.setResourceResolver(new ResourceResolver() {

        @Override
        public List<String> resolveTxt(String host) throws Exception {
            return Collections.emptyList();
        }

        @Override
        public List<SrvRecord> resolveSrv(String host) throws Exception {
            return Collections.emptyList();
        }
    });
    resolver.start(mockListener);
    assertThat(fakeClock.runDueTasks()).isEqualTo(1);
    verify(mockListener).onResult(resultCaptor.capture());
    ResolutionResult result = resultCaptor.getValue();
    assertThat(result.getAddresses()).isEmpty();
    assertThat(result.getAttributes()).isEqualTo(Attributes.EMPTY);
    assertThat(result.getServiceConfig()).isNull();
}
Also used : AddressResolver(io.grpc.internal.DnsNameResolver.AddressResolver) ResolutionResult(io.grpc.NameResolver.ResolutionResult) ResourceResolver(io.grpc.internal.DnsNameResolver.ResourceResolver) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Test(org.junit.Test)

Aggregations

AddressResolver (io.grpc.internal.DnsNameResolver.AddressResolver)22 Test (org.junit.Test)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)16 InetAddress (java.net.InetAddress)15 ResourceResolver (io.grpc.internal.DnsNameResolver.ResourceResolver)12 ResolutionResult (io.grpc.NameResolver.ResolutionResult)10 InetSocketAddress (java.net.InetSocketAddress)9 IOException (java.io.IOException)8 UnknownHostException (java.net.UnknownHostException)6 JndiResourceResolver (io.grpc.internal.JndiResourceResolverFactory.JndiResourceResolver)5 FakeTicker (com.google.common.testing.FakeTicker)4 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)4 Status (io.grpc.Status)4 NameResolver (io.grpc.NameResolver)2 SrvRecord (io.grpc.internal.DnsNameResolver.SrvRecord)2 List (java.util.List)2 ExpectedException (org.junit.rules.ExpectedException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ChannelLogger (io.grpc.ChannelLogger)1 HttpConnectProxiedSocketAddress (io.grpc.HttpConnectProxiedSocketAddress)1