@Override public void onFailure(Throwable throwable) { if (throwable instanceof CancellationException) { tracer.operationCancelled(); } else { tracer.operationFailed(throwable); } }
@Override public void onFailure(Throwable throwable) { if (throwable instanceof CancellationException) { tracer.operationCancelled(); } else { tracer.operationFailed(throwable); } }
@Override public void onError(Throwable t) { // Only mark explicit user cancellations. Since the retry logic can also throw // CancellationException, we can't simply check that t is an instance of a // CancellationException. if (wasCancelled.get()) { tracer.operationCancelled(); } else { tracer.operationFailed(t); } innerObserver.onError(t); }
@Test public void testOperationCancelled() { innerResult.cancel(true); tracedUnaryCallable.futureCall("test", callContext); verify(tracer, times(1)).operationCancelled(); }
@Test public void testCancellation() { ApiFuture<String> future = ApiFutures.immediateCancelledFuture(); ApiFutures.addCallback( future, new TraceFinisher<String>(mockTracer), MoreExecutors.directExecutor()); verify(mockTracer, times(1)).operationCancelled(); }