public void testCheckedGetThrowsApplicationExceptionOnInterruption() throws InterruptedException { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, null, latch); final CountDownLatch startingGate = new CountDownLatch(1); final CountDownLatch successLatch = new CountDownLatch(1); assertFalse(future.isDone()); assertFalse(future.isCancelled()); Thread getThread = new Thread( new Runnable() { @Override public void run() { startingGate.countDown(); try { future.checkedGet(); } catch (Exception e) { checkInterruptedException(e); // This only gets hit if the original call throws an exception and // the check call above passes. successLatch.countDown(); } } }); getThread.start(); assertTrue(startingGate.await(500, TimeUnit.MILLISECONDS)); getThread.interrupt(); assertTrue(successLatch.await(500, TimeUnit.MILLISECONDS)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); }
public void testCheckedGetThrowsApplicationExceptionOnError() { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, new Exception("Error"), latch); assertFalse(future.isDone()); assertFalse(future.isCancelled()); new Thread( new Runnable() { @Override public void run() { latch.countDown(); } }) .start(); try { future.checkedGet(); fail(); } catch (Exception e) { checkExecutionException(e); } assertTrue(future.isDone()); assertFalse(future.isCancelled()); } }
/** * Tests that the {@link CheckedFuture#checkedGet()} method throws the correct type of * cancellation exception when it is cancelled. */ public void testCheckedGetThrowsApplicationExceptionOnCancellation() { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, null, latch); assertFalse(future.isDone()); assertFalse(future.isCancelled()); new Thread( new Runnable() { @Override public void run() { future.cancel(true); } }) .start(); try { future.checkedGet(); fail("RPC Should have been cancelled."); } catch (Exception e) { checkCancelledException(e); } assertTrue(future.isDone()); assertTrue(future.isCancelled()); }
assertFalse(checked.isCancelled());
public static boolean waitForSubmit(CheckedFuture<Void, TransactionCommitFailedException> submit) { // This can happen only when testing if (submit == null) return false; while (!submit.isDone() && !submit.isCancelled()) { try { Thread.sleep(1000); } catch (Exception err) { LOG.error("Interrupted", err); } } return submit.isCancelled(); }
public void testCheckedGetThrowsApplicationExceptionOnInterruption() throws InterruptedException { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, null, latch); final CountDownLatch startingGate = new CountDownLatch(1); final CountDownLatch successLatch = new CountDownLatch(1); assertFalse(future.isDone()); assertFalse(future.isCancelled()); Thread getThread = new Thread( new Runnable() { @Override public void run() { startingGate.countDown(); try { future.checkedGet(); } catch (Exception e) { checkInterruptedException(e); // This only gets hit if the original call throws an exception and // the check call above passes. successLatch.countDown(); } } }); getThread.start(); assertTrue(startingGate.await(500, TimeUnit.MILLISECONDS)); getThread.interrupt(); assertTrue(successLatch.await(500, TimeUnit.MILLISECONDS)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); }
public void testCheckedGetThrowsApplicationExceptionOnInterruption() throws InterruptedException { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, null, latch); final CountDownLatch startingGate = new CountDownLatch(1); final CountDownLatch successLatch = new CountDownLatch(1); assertFalse(future.isDone()); assertFalse(future.isCancelled()); Thread getThread = new Thread(new Runnable() { @Override public void run() { startingGate.countDown(); try { future.checkedGet(); } catch (Exception e) { checkInterruptedException(e); // This only gets hit if the original call throws an exception and // the check call above passes. successLatch.countDown(); } } }); getThread.start(); assertTrue(startingGate.await(500, TimeUnit.MILLISECONDS)); getThread.interrupt(); assertTrue(successLatch.await(500, TimeUnit.MILLISECONDS)); assertFalse(future.isDone()); assertFalse(future.isCancelled()); }
public void testCheckedGetThrowsApplicationExceptionOnError() { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, new Exception("Error"), latch); assertFalse(future.isDone()); assertFalse(future.isCancelled()); new Thread(new Runnable() { @Override public void run() { latch.countDown(); } }).start(); try { future.checkedGet(); fail(); } catch (Exception e) { checkExecutionException(e); } assertTrue(future.isDone()); assertFalse(future.isCancelled()); } }
public void testCheckedGetThrowsApplicationExceptionOnError() { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, new Exception("Error"), latch); assertFalse(future.isDone()); assertFalse(future.isCancelled()); new Thread( new Runnable() { @Override public void run() { latch.countDown(); } }) .start(); try { future.checkedGet(); fail(); } catch (Exception e) { checkExecutionException(e); } assertTrue(future.isDone()); assertFalse(future.isCancelled()); } }
/** * Tests that the {@link CheckedFuture#checkedGet()} method throws the correct * type of cancellation exception when it is cancelled. */ public void testCheckedGetThrowsApplicationExceptionOnCancellation() { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, null, latch); assertFalse(future.isDone()); assertFalse(future.isCancelled()); new Thread(new Runnable() { @Override public void run() { future.cancel(true); } }).start(); try { future.checkedGet(); fail("RPC Should have been cancelled."); } catch (Exception e) { checkCancelledException(e); } assertTrue(future.isDone()); assertTrue(future.isCancelled()); }
/** * Tests that the {@link CheckedFuture#checkedGet()} method throws the correct type of * cancellation exception when it is cancelled. */ public void testCheckedGetThrowsApplicationExceptionOnCancellation() { final CheckedFuture<Boolean, ?> future = createCheckedFuture(Boolean.TRUE, null, latch); assertFalse(future.isDone()); assertFalse(future.isCancelled()); new Thread( new Runnable() { @Override public void run() { future.cancel(true); } }) .start(); try { future.checkedGet(); fail("RPC Should have been cancelled."); } catch (Exception e) { checkCancelledException(e); } assertTrue(future.isDone()); assertTrue(future.isCancelled()); }
assertFalse(checked.isCancelled());