@Override public ApiFuture<MetadataT> peekMetadata() { ApiFuture<OperationSnapshot> future = pollingFuture.peekAttemptResult(); synchronized (lock) { if (peekedAttemptResult == future) { return peekedPollResult; } peekedAttemptResult = future; peekedPollResult = ApiFutures.transform(peekedAttemptResult, metadataTransformer, directExecutor()); return peekedPollResult; } }
@Override public ApiFuture<MetadataT> peekMetadata() { ApiFuture<OperationSnapshot> future = pollingFuture.peekAttemptResult(); synchronized (lock) { if (peekedAttemptResult == future) { return peekedPollResult; } peekedAttemptResult = future; peekedPollResult = ApiFutures.transform(peekedAttemptResult, metadataTransformer, directExecutor()); return peekedPollResult; } }
future.peekAttemptResult().get(3, TimeUnit.SECONDS); } catch (ExecutionException e) { exception = e.getCause(); assertSame(future.peekAttemptResult(), future.peekAttemptResult()); assertTrue(future.peekAttemptResult().isDone()); assertFalse(future.peekAttemptResult().isCancelled()); ApiFuture<?> peekedAttempt = future.peekAttemptResult(); assertFalse(future.cancel(false)); assertSame(gottentAttempt, future.getAttemptResult()); assertSame(peekedAttempt, future.peekAttemptResult()); try { future.get(3, TimeUnit.SECONDS);
void assertFutureSuccess(RetryingFuture<String> future) throws ExecutionException, InterruptedException, TimeoutException { assertEquals("SUCCESS", future.get(3, TimeUnit.SECONDS)); assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertEquals("SUCCESS", future.peekAttemptResult().get(3, TimeUnit.SECONDS)); assertSame(future.peekAttemptResult(), future.peekAttemptResult()); assertTrue(future.peekAttemptResult().isDone()); assertFalse(future.peekAttemptResult().isCancelled()); assertEquals("SUCCESS", future.getAttemptResult().get(3, TimeUnit.SECONDS)); assertSame(future.getAttemptResult(), future.getAttemptResult()); assertTrue(future.getAttemptResult().isDone()); assertFalse(future.getAttemptResult().isCancelled()); String res = future.get(); ApiFuture<?> gottentAttempt = future.getAttemptResult(); ApiFuture<?> peekedAttempt = future.peekAttemptResult(); // testing completed immutability assertFalse(future.cancel(true)); assertFalse(future.cancel(false)); assertSame(gottentAttempt, future.getAttemptResult()); assertSame(peekedAttempt, future.peekAttemptResult()); assertSame(res, future.get()); assertTrue(future.isDone()); assertFalse(future.isCancelled()); }
@Test public void testSuccessWithFailuresPeekGetAttempt() throws Exception { FailingCallable callable = new FailingCallable(5, "SUCCESS", tracer); RetryingExecutorWithContext<String> executor = getExecutor(getAlgorithm(FAST_RETRY_SETTINGS, 0, null)); RetryingFuture<String> future = executor.createFuture(callable, retryingContext); assertNull(future.peekAttemptResult()); assertSame(future.peekAttemptResult(), future.peekAttemptResult()); assertFalse(future.getAttemptResult().isDone()); assertFalse(future.getAttemptResult().isCancelled()); Exception exception = null; try { future.get(1L, TimeUnit.MILLISECONDS); } catch (TimeoutException e) { exception = e; } assertNotNull(exception); future.setAttemptFuture(executor.submit(future)); assertFutureSuccess(future); assertEquals(5, future.getAttemptSettings().getAttemptCount()); }
assertTrue(future.getAttemptResult().isCancelled()); try { future.peekAttemptResult().get(3, TimeUnit.SECONDS); } catch (CancellationException e) { exception = e; assertSame(future.peekAttemptResult(), future.peekAttemptResult()); assertTrue(future.peekAttemptResult().isDone()); assertTrue(future.peekAttemptResult().isCancelled()); ApiFuture<?> peekedAttempt = future.peekAttemptResult(); assertFalse(future.cancel(false)); assertSame(gottentAttempt, future.getAttemptResult()); assertSame(peekedAttempt, future.peekAttemptResult()); try { future.get(3, TimeUnit.SECONDS);
RetryingFuture<String> future = executor.createFuture(callable, retryingContext); assertNull(future.peekAttemptResult()); assertSame(future.peekAttemptResult(), future.peekAttemptResult()); assertFalse(future.getAttemptResult().isDone()); assertFalse(future.getAttemptResult().isCancelled()); ApiFuture<String> attemptResult = future.peekAttemptResult(); if (attemptResult != null) { assertTrue(attemptResult.isDone());
RetryingFuture<String> future = executor.createFuture(callable, retryingContext); assertNull(future.peekAttemptResult()); assertSame(future.getAttemptResult(), future.getAttemptResult()); assertFalse(future.getAttemptResult().isDone()); assertFalse(attemptResult.cancel(true)); attemptResult.get(); assertNotNull(future.peekAttemptResult()); } catch (ExecutionException e) { exception = (CustomException) e.getCause();
RetryingFuture<String> future = executor.createFuture(callable, retryingContext); assertNull(future.peekAttemptResult()); assertSame(future.getAttemptResult(), future.getAttemptResult()); assertFalse(future.getAttemptResult().isDone()); try { attemptResult.get(); assertNotNull(future.peekAttemptResult()); } catch (CancellationException e) { cancellationException = e;