Search in sources :

Example 11 with ResourceResolver

use of io.grpc.internal.DnsNameResolver.ResourceResolver 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 12 with ResourceResolver

use of io.grpc.internal.DnsNameResolver.ResourceResolver 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)12 ResourceResolver (io.grpc.internal.DnsNameResolver.ResourceResolver)12 Test (org.junit.Test)12 ResolutionResult (io.grpc.NameResolver.ResolutionResult)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 IOException (java.io.IOException)7 InetAddress (java.net.InetAddress)7 InetSocketAddress (java.net.InetSocketAddress)7 UnknownHostException (java.net.UnknownHostException)6 JndiResourceResolver (io.grpc.internal.JndiResourceResolverFactory.JndiResourceResolver)5 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)3 Status (io.grpc.Status)3 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 NameResolver (io.grpc.NameResolver)1 ConfigOrError (io.grpc.NameResolver.ConfigOrError)1 ServiceConfigParser (io.grpc.NameResolver.ServiceConfigParser)1 ArrayList (java.util.ArrayList)1