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);
}
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");
}
}
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());
}
Aggregations