use of io.grpc.internal.FakeClock.ScheduledTask in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method onlyLogicalDnsCluster_refreshNameResolutionRaceWithResolutionError.
@Test
public void onlyLogicalDnsCluster_refreshNameResolutionRaceWithResolutionError() {
InOrder inOrder = Mockito.inOrder(backoffPolicyProvider, backoffPolicy1, backoffPolicy2);
ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(logicalDnsDiscoveryMechanism), roundRobin);
deliverLbConfig(config);
FakeNameResolver resolver = assertResolverCreated("/" + DNS_HOST_NAME);
assertThat(childBalancers).isEmpty();
EquivalentAddressGroup endpoint = makeAddress("endpoint-addr");
resolver.deliverEndpointAddresses(Collections.singletonList(endpoint));
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
assertAddressesEqual(Collections.singletonList(endpoint), childBalancer.addresses);
assertThat(resolver.refreshCount).isEqualTo(0);
verify(helper).ignoreRefreshNameResolutionCheck();
childBalancer.helper.refreshNameResolution();
assertThat(resolver.refreshCount).isEqualTo(1);
resolver.deliverError(Status.UNAVAILABLE.withDescription("I am lost"));
inOrder.verify(backoffPolicyProvider).get();
inOrder.verify(backoffPolicy1).nextBackoffNanos();
assertThat(fakeClock.getPendingTasks()).hasSize(1);
ScheduledTask task = Iterables.getOnlyElement(fakeClock.getPendingTasks());
assertThat(task.getDelay(TimeUnit.SECONDS)).isEqualTo(1L);
fakeClock.forwardTime(100L, TimeUnit.MILLISECONDS);
childBalancer.helper.refreshNameResolution();
assertThat(resolver.refreshCount).isEqualTo(2);
assertThat(task.isCancelled()).isTrue();
assertThat(fakeClock.getPendingTasks()).isEmpty();
resolver.deliverError(Status.UNAVAILABLE.withDescription("I am still lost"));
// active refresh resets backoff sequence
inOrder.verify(backoffPolicyProvider).get();
inOrder.verify(backoffPolicy2).nextBackoffNanos();
task = Iterables.getOnlyElement(fakeClock.getPendingTasks());
assertThat(task.getDelay(TimeUnit.SECONDS)).isEqualTo(5L);
fakeClock.forwardTime(5L, TimeUnit.SECONDS);
assertThat(resolver.refreshCount).isEqualTo(3);
inOrder.verifyNoMoreInteractions();
}
Aggregations