use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class CachingRlsLbClientTest method rls_withCustomRlsChannelServiceConfig.
@Test
public void rls_withCustomRlsChannelServiceConfig() throws Exception {
Map<String, ?> routeLookupChannelServiceConfig = ImmutableMap.of("loadBalancingConfig", ImmutableList.of(ImmutableMap.of("grpclb", ImmutableMap.of("childPolicy", ImmutableList.of(ImmutableMap.of("pick_first", ImmutableMap.of())), "serviceName", "service1"))));
LbPolicyConfiguration lbPolicyConfiguration = new LbPolicyConfiguration(ROUTE_LOOKUP_CONFIG, routeLookupChannelServiceConfig, childLbPolicy);
rlsLbClient = CachingRlsLbClient.newBuilder().setBackoffProvider(fakeBackoffProvider).setResolvedAddressesFactory(resolvedAddressFactory).setEvictionListener(evictionListener).setHelper(helper).setLbPolicyConfig(lbPolicyConfiguration).setThrottler(fakeThrottler).setTimeProvider(fakeTimeProvider).build();
RouteLookupRequest routeLookupRequest = RouteLookupRequest.create(ImmutableMap.of("server", "bigtable.googleapis.com", "service-key", "foo", "method-key", "bar"));
rlsServerImpl.setLookupTable(ImmutableMap.of(routeLookupRequest, RouteLookupResponse.create(ImmutableList.of("target"), "header")));
// initial request
CachedRouteLookupResponse resp = getInSyncContext(routeLookupRequest);
assertThat(resp.isPending()).isTrue();
// server response
fakeTimeProvider.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.hasData()).isTrue();
assertThat(rlsChannelOverriddenAuthority).isEqualTo("bigtable.googleapis.com:443");
assertThat(rlsChannelServiceConfig).isEqualTo(routeLookupChannelServiceConfig);
}
use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class CachingRlsLbClientTest method get_childPolicyWrapper_reusedForSameTarget.
@Test
public void get_childPolicyWrapper_reusedForSameTarget() throws Exception {
setUpRlsLbClient();
RouteLookupRequest routeLookupRequest = RouteLookupRequest.create(ImmutableMap.of("server", "bigtable.googleapis.com", "service-key", "foo", "method-key", "bar"));
RouteLookupRequest routeLookupRequest2 = RouteLookupRequest.create(ImmutableMap.of("server", "bigtable.googleapis.com", "service-key", "foo", "method-key", "baz"));
rlsServerImpl.setLookupTable(ImmutableMap.of(routeLookupRequest, RouteLookupResponse.create(ImmutableList.of("target"), "header"), routeLookupRequest2, RouteLookupResponse.create(ImmutableList.of("target"), "header2")));
CachedRouteLookupResponse resp = getInSyncContext(routeLookupRequest);
assertThat(resp.isPending()).isTrue();
fakeTimeProvider.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.hasData()).isTrue();
assertThat(resp.getHeaderData()).isEqualTo("header");
ChildPolicyWrapper childPolicyWrapper = resp.getChildPolicyWrapper();
assertThat(childPolicyWrapper.getTarget()).isEqualTo("target");
assertThat(childPolicyWrapper.getPicker()).isNotInstanceOf(RlsPicker.class);
// request2 has same target, it should reuse childPolicyWrapper
CachedRouteLookupResponse resp2 = getInSyncContext(routeLookupRequest2);
assertThat(resp2.isPending()).isTrue();
fakeTimeProvider.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
resp2 = getInSyncContext(routeLookupRequest2);
assertThat(resp2.hasData()).isTrue();
assertThat(resp2.getHeaderData()).isEqualTo("header2");
assertThat(resp2.getChildPolicyWrapper()).isEqualTo(resp.getChildPolicyWrapper());
}
use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class CachingRlsLbClientTest method get_throttledAndRecover.
@Test
public void get_throttledAndRecover() throws Exception {
setUpRlsLbClient();
RouteLookupRequest routeLookupRequest = RouteLookupRequest.create(ImmutableMap.of("server", "bigtable.googleapis.com", "service-key", "foo", "method-key", "bar"));
rlsServerImpl.setLookupTable(ImmutableMap.of(routeLookupRequest, RouteLookupResponse.create(ImmutableList.of("target"), "header")));
fakeThrottler.nextResult = true;
fakeBackoffProvider.nextPolicy = createBackoffPolicy(10, TimeUnit.MILLISECONDS);
CachedRouteLookupResponse resp = getInSyncContext(routeLookupRequest);
assertThat(resp.hasError()).isTrue();
fakeTimeProvider.forwardTime(10, TimeUnit.MILLISECONDS);
// initially backed off entry is backed off again
verify(evictionListener).onEviction(eq(routeLookupRequest), any(CacheEntry.class), eq(EvictionType.REPLACED));
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.hasError()).isTrue();
// let it pass throttler
fakeThrottler.nextResult = false;
fakeTimeProvider.forwardTime(10, TimeUnit.MILLISECONDS);
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.isPending()).isTrue();
// server responses
fakeTimeProvider.forwardTime(SERVER_LATENCY_MILLIS, TimeUnit.MILLISECONDS);
resp = getInSyncContext(routeLookupRequest);
assertThat(resp.hasData()).isTrue();
}
use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class RlsRequestFactoryTest method create_pathFallbackMatches_optionalHeaderMissing.
@Test
public void create_pathFallbackMatches_optionalHeaderMissing() {
Metadata metadata = new Metadata();
metadata.put(Metadata.Key.of("User", Metadata.ASCII_STRING_MARSHALLER), "test");
metadata.put(Metadata.Key.of("X-Google-Id", Metadata.ASCII_STRING_MARSHALLER), "123");
metadata.put(Metadata.Key.of("foo", Metadata.ASCII_STRING_MARSHALLER), "bar");
RouteLookupRequest request = factory.create("com.google.service1", "Update", metadata);
assertThat(request.keyMap()).containsExactly("user", "test", "service-2", "com.google.service1", "const-key-2", "const-value-2");
}
use of io.grpc.rls.RlsProtoData.RouteLookupRequest in project grpc-java by grpc.
the class RlsRequestFactoryTest method create_noMethodInRlsConfig.
@Test
public void create_noMethodInRlsConfig() {
Metadata metadata = new Metadata();
metadata.put(Metadata.Key.of("User", Metadata.ASCII_STRING_MARSHALLER), "test");
metadata.put(Metadata.Key.of("X-Google-Id", Metadata.ASCII_STRING_MARSHALLER), "123");
metadata.put(Metadata.Key.of("foo", Metadata.ASCII_STRING_MARSHALLER), "bar");
RouteLookupRequest request = factory.create("com.google.service3", "Update", metadata);
assertThat(request.keyMap()).containsExactly("user", "test", "const-key-4", "const-value-4");
}
Aggregations