Code example for CancellationException

0
 
    @Test(timeout = 10000) 
    public void testCancel() throws Exception { 
        FutureResultHolder<Object> holder = new FutureResultHolder<>();
 
        assertTrue(holder.trySetError(new CancellationException()));
        checkCanceled(holder);
 
        assertFalse(holder.tryStoreResult(new Object()));
        checkCanceled(holder);
 
        assertFalse(holder.trySetError(new Exception()));
        checkCanceled(holder);
    } 
 
    @Test(timeout = 10000) 
    public void testCancelThroughFuture() throws Exception { 
        FutureResultHolder<Object> holder = new FutureResultHolder<>();
 
        holder.asFuture().cancel(true);
        checkCanceled(holder);