|
59 | 59 | import io.grpc.MetricRecorder.BatchRecorder; |
60 | 60 | import io.grpc.MetricRecorder.Registration; |
61 | 61 | import io.grpc.NameResolver.ConfigOrError; |
| 62 | +import io.grpc.Server; |
62 | 63 | import io.grpc.Status; |
63 | 64 | import io.grpc.Status.Code; |
64 | 65 | import io.grpc.SynchronizationContext; |
@@ -170,6 +171,7 @@ public void uncaughtException(Thread t, Throwable e) { |
170 | 171 | private CachingRlsLbClient rlsLbClient; |
171 | 172 | private Map<String, ?> rlsChannelServiceConfig; |
172 | 173 | private String rlsChannelOverriddenAuthority; |
| 174 | + private Server server; |
173 | 175 |
|
174 | 176 | private void setUpRlsLbClient() { |
175 | 177 | fakeThrottler.resetCounts(); |
@@ -336,6 +338,33 @@ public void get_throttledAndRecover() throws Exception { |
336 | 338 | assertThat(fakeHelper.lastPicker.toString()).isEqualTo("RlsPicker{target=service1}"); |
337 | 339 | } |
338 | 340 |
|
| 341 | + @Test |
| 342 | + public void controlPlaneTransientToReady_backOffEntriesRemovedAndPickerUpdated() throws Exception { |
| 343 | + setUpRlsLbClient(); |
| 344 | + RouteLookupRequest routeLookupRequest = RouteLookupRequest.create(ImmutableMap.of( |
| 345 | + "server", "bigtable.googleapis.com", "service-key", "foo", "method-key", "bar")); |
| 346 | + rlsServerImpl.setLookupTable( |
| 347 | + ImmutableMap.of( |
| 348 | + routeLookupRequest, |
| 349 | + RouteLookupResponse.create(ImmutableList.of("target"), "header"))); |
| 350 | + |
| 351 | + fakeThrottler.nextResult = true; |
| 352 | + fakeBackoffProvider.nextPolicy = createBackoffPolicy(10, TimeUnit.MILLISECONDS); |
| 353 | + |
| 354 | + CachedRouteLookupResponse resp = getInSyncContext(routeLookupRequest); |
| 355 | + |
| 356 | + assertThat(resp.hasError()).isTrue(); |
| 357 | + |
| 358 | + // let it pass throttler |
| 359 | + fakeThrottler.nextResult = false; |
| 360 | + fakeClock.forwardTime(10, TimeUnit.MILLISECONDS); |
| 361 | + // Backoff entry evicted from cache. |
| 362 | + verify(evictionListener) |
| 363 | + .onEviction(eq(routeLookupRequest), any(CacheEntry.class), eq(EvictionType.EXPLICIT)); |
| 364 | + // Assert that Rls LB policy picker was updated. |
| 365 | + assertThat(fakeHelper.lastPicker.toString()).isEqualTo("RlsPicker{target=service1}"); |
| 366 | + } |
| 367 | + |
339 | 368 | @Test |
340 | 369 | public void get_updatesLbState() throws Exception { |
341 | 370 | setUpRlsLbClient(); |
@@ -884,13 +913,13 @@ private final class FakeHelper extends Helper { |
884 | 913 | @Override |
885 | 914 | public ManagedChannelBuilder<?> createResolvingOobChannelBuilder( |
886 | 915 | String target, ChannelCredentials creds) { |
887 | | - try { |
888 | | - grpcCleanupRule.register( |
889 | | - InProcessServerBuilder.forName(target) |
890 | | - .addService(rlsServerImpl) |
891 | | - .directExecutor() |
892 | | - .build() |
893 | | - .start()); |
| 916 | + try { |
| 917 | + server = InProcessServerBuilder.forName(target) |
| 918 | + .addService(rlsServerImpl) |
| 919 | + .directExecutor() |
| 920 | + .build() |
| 921 | + .start(); |
| 922 | + grpcCleanupRule.register(server); |
894 | 923 | } catch (IOException e) { |
895 | 924 | throw new RuntimeException("cannot create server: " + target, e); |
896 | 925 | } |
|
0 commit comments