@Test
public void testEarlyTermination() throws Exception {

  ApiFuture<String> result = callable.futureCall("request");
  MockServerStreamingCall<String, String> call = upstream.popLastCall();
  // callable should request a single element on start
  Truth.assertThat(call.getController().isAutoFlowControlEnabled()).isFalse();
  Truth.assertThat(call.getController().popLastPull()).isEqualTo(1);
  // Then the user promptly cancels it
  result.cancel(true);
  // The cancellation should propagate to the inner callable
  Truth.assertThat(call.getController().isCancelled()).isTrue();
  // Then we fake a cancellation going the other way (it will be wrapped in StatusRuntimeException
  // for grpc)
  call.getController()
      .getObserver()
      .onError(new RuntimeException("Some other upstream cancellation notice"));
  Throwable actualError = null;
  try {
    result.get(1, TimeUnit.SECONDS);
  } catch (Throwable e) {
    actualError = e;
  }
  // However, that exception will be ignored and will be replaced by a generic
  // CancellationException
  Truth.assertThat(actualError).isInstanceOf(CancellationException.class);
}