mirror of https://github.com/grpc/grpc-java.git
core: throw exception on resolution failure and no jndi resolver
This commit is contained in:
parent
c528df8ae8
commit
60b02c0b9c
|
@ -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 {
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue