Search in sources :

Example 1 with ChildPolicyWrapper

use of io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper in project grpc-java by grpc.

the class LbPolicyConfigurationTest method updateBalancingState_triggersListener.

@Test
public void updateBalancingState_triggersListener() {
    ChildPolicyWrapper childPolicyWrapper = factory.createOrGet("foo.google.com");
    ChildPolicyReportingHelper childPolicyReportingHelper = childPolicyWrapper.getHelper();
    SubchannelPicker childPicker = mock(SubchannelPicker.class);
    childPolicyReportingHelper.updateBalancingState(ConnectivityState.READY, childPicker);
    verify(childLbStatusListener).onStatusChanged(ConnectivityState.READY);
    assertThat(childPolicyWrapper.getPicker()).isEqualTo(childPicker);
    // picker governs childPickers will be reported to parent LB
    verify(helper).updateBalancingState(ConnectivityState.READY, picker);
}
Also used : SubchannelPicker(io.grpc.LoadBalancer.SubchannelPicker) ChildPolicyWrapper(io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper) ChildPolicyReportingHelper(io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper.ChildPolicyReportingHelper) Test(org.junit.Test)

Example 2 with ChildPolicyWrapper

use of io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper in project grpc-java by grpc.

the class LbPolicyConfigurationTest method childPolicyWrapper_refCounted.

@Test
public void childPolicyWrapper_refCounted() {
    String target = "target";
    ChildPolicyWrapper childPolicy = factory.createOrGet(target);
    assertThat(factory.childPolicyMap.keySet()).containsExactly(target);
    ChildPolicyWrapper childPolicy2 = factory.createOrGet(target);
    assertThat(factory.childPolicyMap.keySet()).containsExactly(target);
    assertThat(childPolicy2).isEqualTo(childPolicy);
    factory.release(childPolicy2);
    assertThat(factory.childPolicyMap.keySet()).containsExactly(target);
    factory.release(childPolicy);
    assertThat(factory.childPolicyMap).isEmpty();
    try {
        factory.release(childPolicy);
        fail("should not be able to access already released policy");
    } catch (IllegalStateException e) {
        assertThat(e).hasMessageThat().contains("already released");
    }
}
Also used : ChildPolicyWrapper(io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper) Test(org.junit.Test)

Example 3 with ChildPolicyWrapper

use of io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper 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)

Aggregations

ChildPolicyWrapper (io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper)3 Test (org.junit.Test)3 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)1 CachedRouteLookupResponse (io.grpc.rls.CachingRlsLbClient.CachedRouteLookupResponse)1 ChildPolicyReportingHelper (io.grpc.rls.LbPolicyConfiguration.ChildPolicyWrapper.ChildPolicyReportingHelper)1 RouteLookupRequest (io.grpc.rls.RlsProtoData.RouteLookupRequest)1