DnsNameResolver extends NameResolver { @Override public final synchronized void start(Listener listener) { Preconditions.checkState(this.listener == null, "already started"); timerService = SharedResourceHolder.get(timerServiceResource); executor = SharedResourceHolder.get(executorResource); this.listener = Preconditions.checkNotNull(listener, "listener"); resolve(); } DnsNameResolver(@Nullable String nsAuthority, String name, Attributes params,
      Resource<ScheduledExecutorService> timerServiceResource,
      Resource<ExecutorService> executorResource); @Override final String getServiceAuthority(); @Override final synchronized void start(Listener listener); @Override final synchronized void refresh(); @Override final synchronized void shutdown();  }
@Test public void retry() throws Exception { String name = "foo.googleapis.com"; UnknownHostException error = new UnknownHostException(name); InetAddress[] answer = createAddressList(2); MockResolver resolver = new MockResolver(name, 81, error, error, answer); resolver.start(mockListener); assertEquals(1, fakeExecutor.runDueTasks()); verify(mockListener).onError(statusCaptor.capture()); assertEquals(name, resolver.invocations.poll()); Status status = statusCaptor.getValue(); assertEquals(Status.Code.UNAVAILABLE, status.getCode()); assertSame(error, status.getCause()); assertEquals(1, fakeClock.numPendingTasks()); fakeClock.forwardMillis(TimeUnit.MINUTES.toMillis(1) - 1); assertEquals(1, fakeClock.numPendingTasks()); fakeClock.forwardMillis(1); assertEquals(1, fakeExecutor.runDueTasks()); verify(mockListener, times(2)).onError(statusCaptor.capture()); assertEquals(name, resolver.invocations.poll()); status = statusCaptor.getValue(); assertEquals(Status.Code.UNAVAILABLE, status.getCode()); assertSame(error, status.getCause()); assertEquals(1, fakeClock.numPendingTasks()); fakeClock.forwardMillis(TimeUnit.MINUTES.toMillis(1) - 1); assertEquals(1, fakeClock.numPendingTasks()); fakeClock.forwardMillis(1); assertEquals(0, fakeClock.numPendingTasks()); assertEquals(1, fakeExecutor.runDueTasks()); verify(mockListener).onUpdate(resultCaptor.capture(), any(Attributes.class)); assertEquals(name, resolver.invocations.poll()); assertAnswerMatches(answer, 81, resultCaptor.getValue()); verifyNoMoreInteractions(mockListener); }