public synchronized ListenableFuture<?> getNotFullFuture() { // if we are full and the current not full future is already complete, create a new one if (bufferedBytes.get() > maxBufferedBytes && notFullFuture.isDone()) { notFullFuture = SettableFuture.create(); } return notFullFuture; }
public synchronized void release() { checkState(!freeFuture.isDone(), "Reference has already been freed"); count--; if (count == 0) { freeFuture.set(null); } } }
public IndexSnapshot getFinishedIndexSnapshot() { checkState(indexSnapshotFuture.isDone(), "Update request is not finished"); return MoreFutures.getFutureValue(indexSnapshotFuture); } }
public void pause() { if (!future.isDone()) { return; } future = SettableFuture.create(); }
public void testSetFuture_stackOverflow() { SettableFuture<String> orig = SettableFuture.create(); SettableFuture<String> prev = orig; for (int i = 0; i < 100000; i++) { SettableFuture<String> curr = SettableFuture.create(); prev.setFuture(curr); prev = curr; } // prev represents the 'innermost' future prev.set("done"); assertTrue(orig.isDone()); }
synchronized void setNoNewLookups() { if (noNewLookups) { return; } checkState(!lookupDoneFuture.isDone()); noNewLookups = true; checkAllLookupsDone(); }
public synchronized void decrementPendingLookupCount() { checkState(!lookupDoneFuture.isDone()); pendingLookupCount--; checkAllLookupsDone(); }
public void testTrustedGetFailure_NotCompleted() { SettableFuture<String> future = SettableFuture.create(); assertThat(future.isDone()).isFalse(); assertThat(future.tryInternalFastPathGetFailure()).isNull(); }
public void testSetFailureNull() throws Exception { try { future.setException(null); fail(); } catch (NullPointerException expected) { } assertFalse(future.isDone()); assertTrue(future.setException(new Exception("failure"))); tester.testFailedFuture("failure"); }
/** Tests the initial state of the future. */ public void testCreate() throws Exception { SettableFuture<Integer> future = SettableFuture.create(); assertFalse(future.isDone()); assertFalse(future.isCancelled()); }
public void testSetValue_simpleThreaded() throws Exception { SettableFuture<Integer> future = SettableFuture.create(); assertTrue(future.set(42)); // Later attempts to set the future should return false. assertFalse(future.set(23)); assertFalse(future.setException(new Exception("bar"))); assertFalse(future.setFuture(SettableFuture.<Integer>create())); // Check that the future has been set properly. assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertEquals(42, (int) future.get()); }
public void testAwaitDone_Future() { final SettableFuture<Void> future = SettableFuture.create(); Object x = new Object() { @Override protected void finalize() { future.set(null); } }; x = null; // Hint to the JIT that x is unreachable GcFinalization.awaitDone(future); assertTrue(future.isDone()); assertFalse(future.isCancelled()); }
public void testAwaitDone_Future_Cancel() { final SettableFuture<Void> future = SettableFuture.create(); Object x = new Object() { @Override protected void finalize() { future.cancel(false); } }; x = null; // Hint to the JIT that x is unreachable GcFinalization.awaitDone(future); assertTrue(future.isDone()); assertTrue(future.isCancelled()); }
public void testSetException() throws Exception { SettableFuture<Object> future = SettableFuture.create(); Exception e = new Exception("foobarbaz"); assertTrue(future.setException(e)); // Later attempts to set the future should return false. assertFalse(future.set(23)); assertFalse(future.setException(new Exception("quux"))); assertFalse(future.setFuture(SettableFuture.create())); // Check that the future has been set properly. assertTrue(future.isDone()); assertFalse(future.isCancelled()); try { future.get(); fail("Expected ExecutionException"); } catch (ExecutionException ee) { assertThat(ee).hasCauseThat().isSameAs(e); } }
public void testAllAsList_failure() throws Exception { SingleCallListener listener = new SingleCallListener(); SettableFuture<String> future1 = SettableFuture.create(); SettableFuture<String> future2 = SettableFuture.create(); @SuppressWarnings("unchecked") // array is never modified ListenableFuture<List<String>> compound = allAsList(future1, future2); compound.addListener(listener, directExecutor()); listener.expectCall(); Throwable exception = new Throwable("failed1"); future1.setException(exception); assertTrue(compound.isDone()); assertTrue(listener.wasCalled()); assertFalse(future2.isDone()); try { getDone(compound); fail(); } catch (ExecutionException expected) { assertSame(exception, expected.getCause()); } }
public void testAllAsList_cancelled() throws Exception { SingleCallListener listener = new SingleCallListener(); SettableFuture<String> future1 = SettableFuture.create(); SettableFuture<String> future2 = SettableFuture.create(); @SuppressWarnings("unchecked") // array is never modified ListenableFuture<List<String>> compound = allAsList(future1, future2); compound.addListener(listener, directExecutor()); listener.expectCall(); future1.cancel(true); assertTrue(compound.isDone()); assertTrue(listener.wasCalled()); assertFalse(future2.isDone()); try { getDone(compound); fail(); } catch (CancellationException expected) { } }
public void testNonCancellationPropagating_doesNotPropagate() throws Exception { SettableFuture<Foo> input = SettableFuture.create(); ListenableFuture<Foo> wrapper = nonCancellationPropagating(input); assertTrue(wrapper.cancel(true)); assertTrue(wrapper.isCancelled()); assertTrue(wrapper.isDone()); assertFalse(input.isCancelled()); assertFalse(input.isDone()); }