Search in sources :

Example 1 with RouteLookupRequest

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);
}
Also used : CachedRouteLookupResponse(io.grpc.rls.CachingRlsLbClient.CachedRouteLookupResponse) RouteLookupRequest(io.grpc.rls.RlsProtoData.RouteLookupRequest) Test(org.junit.Test)

Example 2 with RouteLookupRequest

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());
}
Also used : CachedRouteLookupResponse(io.grpc.rls.CachingRlsLbClient.CachedRouteLookupResponse) ChildPolicyWrapper(io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper) RouteLookupRequest(io.grpc.rls.RlsProtoData.RouteLookupRequest) Test(org.junit.Test)

Example 3 with RouteLookupRequest

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();
}
Also used : CachedRouteLookupResponse(io.grpc.rls.CachingRlsLbClient.CachedRouteLookupResponse) CacheEntry(io.grpc.rls.CachingRlsLbClient.CacheEntry) RouteLookupRequest(io.grpc.rls.RlsProtoData.RouteLookupRequest) Test(org.junit.Test)

Example 4 with RouteLookupRequest

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");
}
Also used : Metadata(io.grpc.Metadata) RouteLookupRequest(io.grpc.rls.RlsProtoData.RouteLookupRequest) Test(org.junit.Test)

Example 5 with RouteLookupRequest

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");
}
Also used : Metadata(io.grpc.Metadata) RouteLookupRequest(io.grpc.rls.RlsProtoData.RouteLookupRequest) Test(org.junit.Test)

Aggregations

RouteLookupRequest (io.grpc.rls.RlsProtoData.RouteLookupRequest)10 Test (org.junit.Test)10 Metadata (io.grpc.Metadata)6 CachedRouteLookupResponse (io.grpc.rls.CachingRlsLbClient.CachedRouteLookupResponse)5 CacheEntry (io.grpc.rls.CachingRlsLbClient.CacheEntry)2 InOrder (org.mockito.InOrder)2 ConnectivityState (io.grpc.ConnectivityState)1 PickResult (io.grpc.LoadBalancer.PickResult)1 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)1 PickSubchannelArgsImpl (io.grpc.internal.PickSubchannelArgsImpl)1 ChildPolicyWrapper (io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper)1 HashSet (java.util.HashSet)1