private SocketAddress startServer(String listen) throws IOException, ExecutionException, InterruptedException, TimeoutException { serverSocketChannel.bind(toSocketAddress(listen)); serverSocketChannel.configureBlocking(false); acceptorHub.register(serverSocketChannel, acceptor, true, false, false, false, acceptor); acceptor.registered.get(10, TimeUnit.SECONDS); return addr.get(); }
assert futureChannel.isDone(); try { channel = futureChannel.get(); } catch (InterruptedException e) {
@Test public void defaultState() throws Exception { try { future.get(5, TimeUnit.MILLISECONDS); fail(); } catch (TimeoutException expected) { assertTrue(true); } }
public void assertFailedFuture(@Nullable String message) throws InterruptedException { assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertTrue(latch.await(5, TimeUnit.SECONDS)); assertTrue(future.isDone()); assertFalse(future.isCancelled()); try { future.get(); fail("Future should rethrow the exception."); } catch (ExecutionException e) { assertThat(e.getCause().getMessage(), is(message)); } }
public void assertCompletedFuture(@Nullable Object expectedValue) throws InterruptedException, ExecutionException { assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertTrue(latch.await(5, TimeUnit.SECONDS)); assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertEquals(expectedValue, future.get()); }
public void assertCancelledFuture() throws InterruptedException, ExecutionException { assertTrue(future.isDone()); assertTrue(future.isCancelled()); assertTrue(latch.await(5, TimeUnit.SECONDS)); assertTrue(future.isDone()); assertTrue(future.isCancelled()); try { future.get(); fail("Future should throw CancellationException on cancel."); } catch (CancellationException expected) { } }
@Test public void setException() 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"))); // Check that the future has been set properly. assertTrue(future.isDone()); assertFalse(future.isCancelled()); try { future.get(); fail("Expected ExecutionException"); } catch (ExecutionException ee) { assertSame(e, ee.getCause()); } }
@Test public void setValue_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"))); // Check that the future has been set properly. assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertEquals(42, (int) future.get()); }