use of io.grpc.NameResolver.ResolutionResult 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();
}
use of io.grpc.NameResolver.ResolutionResult 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();
}
Aggregations