use of io.grpc.InternalConfigSelector in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_resourceUpdatedBeforeCallStarted.
@SuppressWarnings("unchecked")
@Test
public void resolved_resourceUpdatedBeforeCallStarted() {
InternalConfigSelector configSelector = resolveToClusters();
reset(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
xdsClient.deliverLdsUpdate(Arrays.asList(Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster("another-cluster", Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(20L), null), ImmutableMap.<String, FilterConfig>of()), Route.forAction(RouteMatch.withPathExactOnly(call2.getFullMethodNameForPath()), RouteAction.forCluster(cluster2, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.<String, FilterConfig>of())));
// Two consecutive service config updates: one for removing clcuster1,
// one for adding "another=cluster".
verify(mockListener, times(2)).onResult(resolutionResultCaptor.capture());
ResolutionResult result = resolutionResultCaptor.getValue();
assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster2, "another-cluster"), (Map<String, ?>) result.getServiceConfig().getConfig());
assertThat(result.getAttributes().get(InternalConfigSelector.KEY)).isSameInstanceAs(configSelector);
assertCallSelectClusterResult(call1, configSelector, "another-cluster", 20.0);
verifyNoMoreInteractions(mockListener);
}
use of io.grpc.InternalConfigSelector in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_faultConfigOverrideInLdsAndInRdsUpdate.
@Test
public void resolved_faultConfigOverrideInLdsAndInRdsUpdate() {
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
// 50%
when(mockRandom.nextInt(1000_000)).thenReturn(500_000);
FaultConfig httpFilterFaultConfig = FaultConfig.create(null, FaultAbort.forStatus(Status.UNAUTHENTICATED, FaultConfig.FractionalPercent.perMillion(1000_000)), null);
xdsClient.deliverLdsUpdateForRdsNameWithFaultInjection(RDS_RESOURCE_NAME, httpFilterFaultConfig);
// Route fault config override
FaultConfig routeFaultConfig = FaultConfig.create(null, FaultAbort.forStatus(Status.UNKNOWN, FaultConfig.FractionalPercent.perMillion(1000_000)), null);
xdsClient.deliverRdsUpdateWithFaultInjection(RDS_RESOURCE_NAME, null, routeFaultConfig, null);
verify(mockListener).onResult(resolutionResultCaptor.capture());
ResolutionResult result = resolutionResultCaptor.getValue();
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
ClientCall.Listener<Void> observer = startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
;
verifyRpcFailed(observer, Status.UNKNOWN.withDescription("RPC terminated due to fault injection"));
}
use of io.grpc.InternalConfigSelector in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_faultAbortAndDelayInLdsUpdateInLdsUpdate.
@Test
public void resolved_faultAbortAndDelayInLdsUpdateInLdsUpdate() {
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)), FaultAbort.forStatus(Status.UNAUTHENTICATED.withDescription("unauthenticated"), FaultConfig.FractionalPercent.perMillion(1000_000)), null);
xdsClient.deliverLdsUpdateWithFaultInjection(cluster1, httpFilterFaultConfig, null, null, null);
verify(mockListener).onResult(resolutionResultCaptor.capture());
ResolutionResult result = resolutionResultCaptor.getValue();
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
ClientCall.Listener<Void> observer = startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
verifyRpcDelayedThenAborted(observer, 5000L, Status.UNAUTHENTICATED.withDescription("RPC terminated due to fault injection: unauthenticated"));
}
use of io.grpc.InternalConfigSelector in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_rpcHashingByChannelId.
@Test
public void resolved_rpcHashingByChannelId() {
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
xdsClient.deliverLdsUpdate(Collections.singletonList(Route.forAction(RouteMatch.withPathExactOnly("/" + TestMethodDescriptors.voidMethod().getFullMethodName()), RouteAction.forCluster(cluster1, Collections.singletonList(HashPolicy.forChannelId(false)), null, null), ImmutableMap.<String, FilterConfig>of())));
verify(mockListener).onResult(resolutionResultCaptor.capture());
InternalConfigSelector configSelector = resolutionResultCaptor.getValue().getAttributes().get(InternalConfigSelector.KEY);
// First call, with header "custom-key": "value1".
startNewCall(TestMethodDescriptors.voidMethod(), configSelector, ImmutableMap.of("custom-key", "value1"), CallOptions.DEFAULT);
long hash1 = testCall.callOptions.getOption(XdsNameResolver.RPC_HASH_KEY);
// Second call, with no custom header.
startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
long hash2 = testCall.callOptions.getOption(XdsNameResolver.RPC_HASH_KEY);
// A different resolver/Channel.
resolver.shutdown();
reset(mockListener);
resolver = new XdsNameResolver(null, AUTHORITY, serviceConfigParser, syncContext, scheduler, xdsClientPoolFactory, mockRandom, FilterRegistry.getDefaultRegistry(), null);
resolver.start(mockListener);
xdsClient = (FakeXdsClient) resolver.getXdsClient();
xdsClient.deliverLdsUpdate(Collections.singletonList(Route.forAction(RouteMatch.withPathExactOnly("/" + TestMethodDescriptors.voidMethod().getFullMethodName()), RouteAction.forCluster(cluster1, Collections.singletonList(HashPolicy.forChannelId(false)), null, null), ImmutableMap.<String, FilterConfig>of())));
verify(mockListener).onResult(resolutionResultCaptor.capture());
configSelector = resolutionResultCaptor.getValue().getAttributes().get(InternalConfigSelector.KEY);
// Third call, with no custom header.
startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
long hash3 = testCall.callOptions.getOption(XdsNameResolver.RPC_HASH_KEY);
assertThat(hash2).isEqualTo(hash1);
assertThat(hash3).isNotEqualTo(hash1);
}
use of io.grpc.InternalConfigSelector 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. "));
}
Aggregations