core: throw exception on resolution failure and no jndi resolver

This commit is contained in:
Carl Mastrangelo 2018-10-15 16:59:02 -07:00 committed by GitHub
parent c528df8ae8
commit 60b02c0b9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.base.Verify;
import io.grpc.Attributes;
import io.grpc.EquivalentAddressGroup;
@ -355,7 +356,9 @@ final class DnsNameResolver extends NameResolver {
}
}
try {
if (addressesException != null && balancerAddressesException != null) {
if (addressesException != null
&& (balancerAddressesException != null || balancerAddresses.isEmpty())) {
Throwables.throwIfUnchecked(addressesException);
throw new RuntimeException(addressesException);
}
} finally {

View File

@ -42,6 +42,7 @@ import io.grpc.internal.DnsNameResolver.ResolutionResults;
import io.grpc.internal.DnsNameResolver.ResourceResolver;
import io.grpc.internal.DnsNameResolver.ResourceResolverFactory;
import io.grpc.internal.SharedResourceHolder.Resource;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@ -247,6 +248,23 @@ public class DnsNameResolverTest {
verify(mockResolver).resolveAddress(hostname);
}
@Test
public void resolveAll_nullResourceResolver_addressFailure() throws Exception {
final String hostname = "addr.fake";
AddressResolver mockResolver = mock(AddressResolver.class);
when(mockResolver.resolveAddress(Matchers.anyString()))
.thenThrow(new IOException("no addr"));
ResourceResolver resourceResolver = null;
boolean resovleSrv = true;
boolean resolveTxt = true;
thrown.expect(RuntimeException.class);
thrown.expectMessage("no addr");
DnsNameResolver.resolveAll(mockResolver, resourceResolver, resovleSrv, resolveTxt, hostname);
}
@Test
public void resolveAll_presentResourceResolver() throws Exception {
final String hostname = "addr.fake";