use of io.grpc.NameResolver.ResolutionResult in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_faultDelayInLdsUpdate_callWithEarlyDeadline.
@Test
public void resolved_faultDelayInLdsUpdate_callWithEarlyDeadline() {
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
// 50%
when(mockRandom.nextInt(1000_000)).thenReturn(500_000);
FaultConfig httpFilterFaultConfig = FaultConfig.create(FaultDelay.forFixedDelay(5000L, FaultConfig.FractionalPercent.perMillion(1000_000)), null, null);
xdsClient.deliverLdsUpdateWithFaultInjection(cluster1, httpFilterFaultConfig, null, null, null);
verify(mockListener).onResult(resolutionResultCaptor.capture());
ResolutionResult result = resolutionResultCaptor.getValue();
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
Deadline.Ticker fakeTicker = new Deadline.Ticker() {
@Override
public long nanoTime() {
return fakeClock.getTicker().read();
}
};
ClientCall.Listener<Void> observer = startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT.withDeadline(Deadline.after(4000, TimeUnit.NANOSECONDS, fakeTicker)));
assertThat(testCall).isNull();
verifyRpcDelayedThenAborted(observer, 4000L, Status.DEADLINE_EXCEEDED.withDescription("Deadline exceeded after up to 5000 ns of fault-injected delay:" + " Deadline exceeded after 0.000004000s. "));
}
use of io.grpc.NameResolver.ResolutionResult in project grpc-java by grpc.
the class ManagedChannelImplTest method channelTracing_nameResolvedEvent_zeorAndNonzeroBackends.
@Test
public void channelTracing_nameResolvedEvent_zeorAndNonzeroBackends() throws Exception {
timer.forwardNanos(1234);
channelBuilder.maxTraceEvents(10);
List<EquivalentAddressGroup> servers = new ArrayList<>();
servers.add(new EquivalentAddressGroup(socketAddress));
FakeNameResolverFactory nameResolverFactory = new FakeNameResolverFactory.Builder(expectedUri).setServers(servers).build();
channelBuilder.nameResolverFactory(nameResolverFactory);
createChannel();
int prevSize = getStats(channel).channelTrace.events.size();
ResolutionResult resolutionResult1 = ResolutionResult.newBuilder().setAddresses(Collections.singletonList(new EquivalentAddressGroup(Arrays.asList(new SocketAddress() {
}, new SocketAddress() {
})))).build();
nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult1);
assertThat(getStats(channel).channelTrace.events).hasSize(prevSize);
prevSize = getStats(channel).channelTrace.events.size();
nameResolverFactory.resolvers.get(0).listener.onError(Status.INTERNAL);
assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
prevSize = getStats(channel).channelTrace.events.size();
nameResolverFactory.resolvers.get(0).listener.onError(Status.INTERNAL);
assertThat(getStats(channel).channelTrace.events).hasSize(prevSize);
prevSize = getStats(channel).channelTrace.events.size();
ResolutionResult resolutionResult2 = ResolutionResult.newBuilder().setAddresses(Collections.singletonList(new EquivalentAddressGroup(Arrays.asList(new SocketAddress() {
}, new SocketAddress() {
})))).build();
nameResolverFactory.resolvers.get(0).listener.onResult(resolutionResult2);
assertThat(getStats(channel).channelTrace.events).hasSize(prevSize + 1);
}
use of io.grpc.NameResolver.ResolutionResult in project grpc-java by grpc.
the class ManagedChannelImplIdlenessTest method deliverResolutionResult.
private void deliverResolutionResult() {
verify(mockNameResolver).start(nameResolverListenerCaptor.capture());
// Simulate new address resolved to make sure the LoadBalancer is correctly linked to
// the NameResolver.
ResolutionResult resolutionResult = ResolutionResult.newBuilder().setAddresses(servers).setAttributes(Attributes.EMPTY).build();
nameResolverListenerCaptor.getValue().onResult(resolutionResult);
executor.runDueTasks();
}
use of io.grpc.NameResolver.ResolutionResult in project grpc-java by grpc.
the class DnsNameResolverTest method resolve_emptyResult.
@Test
public void resolve_emptyResult() throws Exception {
DnsNameResolver.enableTxt = true;
DnsNameResolver nr = newResolver("dns:///addr.fake:1234", 443);
nr.setAddressResolver(new AddressResolver() {
@Override
public List<InetAddress> resolveAddress(String host) throws Exception {
return Collections.emptyList();
}
});
ResourceResolver mockResourceResolver = mock(ResourceResolver.class);
when(mockResourceResolver.resolveTxt(anyString())).thenReturn(Collections.<String>emptyList());
nr.setResourceResolver(mockResourceResolver);
nr.start(mockListener);
assertThat(fakeExecutor.runDueTasks()).isEqualTo(1);
ArgumentCaptor<ResolutionResult> ac = ArgumentCaptor.forClass(ResolutionResult.class);
verify(mockListener).onResult(ac.capture());
verifyNoMoreInteractions(mockListener);
assertThat(ac.getValue().getAddresses()).isEmpty();
assertThat(ac.getValue().getAttributes()).isEqualTo(Attributes.EMPTY);
assertThat(ac.getValue().getServiceConfig()).isNull();
verify(mockResourceResolver, never()).resolveSrv(anyString());
}
use of io.grpc.NameResolver.ResolutionResult in project grpc-java by grpc.
the class DnsNameResolverTest method resolve_serviceConfigLookupFails_nullServiceConfig.
@Test
public void resolve_serviceConfigLookupFails_nullServiceConfig() throws Exception {
DnsNameResolver.enableTxt = true;
InetAddress backendAddr = InetAddresses.fromInteger(0x7f000001);
AddressResolver mockAddressResolver = mock(AddressResolver.class);
when(mockAddressResolver.resolveAddress(anyString())).thenReturn(Collections.singletonList(backendAddr));
String name = "foo.googleapis.com";
ResourceResolver mockResourceResolver = mock(ResourceResolver.class);
when(mockResourceResolver.resolveTxt(anyString())).thenThrow(new Exception("something like javax.naming.NamingException"));
DnsNameResolver resolver = newResolver(name, 81);
resolver.setAddressResolver(mockAddressResolver);
resolver.setResourceResolver(mockResourceResolver);
resolver.start(mockListener);
assertEquals(1, fakeExecutor.runDueTasks());
verify(mockListener).onResult(resultCaptor.capture());
ResolutionResult result = resultCaptor.getValue();
InetSocketAddress resolvedBackendAddr = (InetSocketAddress) Iterables.getOnlyElement(Iterables.getOnlyElement(result.getAddresses()).getAddresses());
assertThat(resolvedBackendAddr.getAddress()).isEqualTo(backendAddr);
verify(mockAddressResolver).resolveAddress(name);
assertThat(result.getAttributes()).isEqualTo(Attributes.EMPTY);
assertThat(result.getServiceConfig()).isNull();
verify(mockResourceResolver).resolveTxt(anyString());
}
Aggregations