@Test
public void testFutureCallPollRPCTimeout() throws Exception {

  String opName = "testFutureCallPollRPCTimeout";
  pollingAlgorithm =
      OperationTimedPollAlgorithm.create(
          FAST_RECHECKING_SETTINGS
              .toBuilder()
              // Update the polling algorithm to set per-RPC timeouts instead of the default zero.
              //
              // This is non-standard, as these fields have been documented as "should be ignored"
              // for LRO polling. They are not actually ignored in code, so they changing them
              // here has an actual affect. This test verifies that they work as such, but in
              // practice generated clients set the RPC timeouts to 0 to be ignored.
              .setInitialRpcTimeout(Duration.ofMillis(100))
              .setMaxRpcTimeout(Duration.ofSeconds(1))
              .setRpcTimeoutMultiplier(2)
              .setTotalTimeout(Duration.ofSeconds(5L))
              .build(),
          clock);
  callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build();
  Color resp = getColor(0.5f);
  Currency meta1 = Currency.getInstance("UAH");
  Currency meta2 = Currency.getInstance("USD");
  OperationSnapshot initialOperation = getOperation(opName, null, null, null, false);
  OperationSnapshot resultOperation1 = getOperation(opName, null, null, meta1, false);
  OperationSnapshot resultOperation2 = getOperation(opName, null, null, meta1, false);
  OperationSnapshot resultOperation3 = getOperation(opName, resp, null, meta2, true);
  UnaryCallable<Integer, OperationSnapshot> initialCallable =
      mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation);
  LongRunningClient longRunningClient = Mockito.mock(LongRunningClient.class);
  @SuppressWarnings("unchecked")
  UnaryCallable<String, OperationSnapshot> getOpCallable = Mockito.mock(UnaryCallable.class);
  ArgumentCaptor<ApiCallContext> callContextCaptor =
      ArgumentCaptor.forClass(ApiCallContext.class);
  Mockito.when(longRunningClient.getOperationCallable()).thenReturn(getOpCallable);
  Mockito.when(getOpCallable.futureCall(Mockito.<String>any(), callContextCaptor.capture()))
      .thenReturn(ApiFutures.immediateFuture(resultOperation1))
      .thenReturn(ApiFutures.immediateFuture(resultOperation2))
      .thenReturn(ApiFutures.immediateFuture(resultOperation3));
  OperationCallable<Integer, Color, Currency> callable =
      FakeCallableFactory.createOperationCallable(
          initialCallable, callSettings, initialContext, longRunningClient);
  callable.futureCall(2, FakeCallContext.createDefault()).get(10, TimeUnit.SECONDS);
  List<Duration> actualTimeouts = Lists.newArrayList();
  for (ApiCallContext callContext : callContextCaptor.getAllValues()) {
    actualTimeouts.add(callContext.getTimeout());
  }
  List<Duration> expectedTimeouts =
      Lists.newArrayList(Duration.ofMillis(100), Duration.ofMillis(200), Duration.ofMillis(400));
  assertThat(actualTimeouts).isEqualTo(expectedTimeouts);
}