Search in sources :

Example 1 with ExceptionHandler

use of com.hazelcast.util.FutureUtil.ExceptionHandler in project hazelcast by hazelcast.

the class FutureUtilTest method testTransactionTimedOutExceptionHandler.

@Test(expected = TransactionTimedOutException.class)
public void testTransactionTimedOutExceptionHandler() throws Exception {
    final ExceptionHandler exceptionHandler = FutureUtil.RETHROW_TRANSACTION_EXCEPTION;
    final Throwable throwable = new TimeoutException();
    exceptionHandler.handleException(throwable);
}
Also used : ExceptionHandler(com.hazelcast.util.FutureUtil.ExceptionHandler) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with ExceptionHandler

use of com.hazelcast.util.FutureUtil.ExceptionHandler in project hazelcast by hazelcast.

the class FutureUtilTest method test_returnWithDeadline_timeout_exception.

@Test(expected = TimeoutException.class)
public void test_returnWithDeadline_timeout_exception() throws Exception {
    AtomicBoolean waitLock = new AtomicBoolean(true);
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    List<Future<Integer>> futures = new ArrayList<Future<Integer>>();
    for (int i = 0; i < 2; i++) {
        Future<Integer> submit = (Future<Integer>) executorService.submit(new TimeoutingTask(waitLock));
        futures.add(submit);
    }
    returnWithDeadline(futures, 1, TimeUnit.SECONDS, new ExceptionHandler() {

        @Override
        public void handleException(Throwable throwable) {
            if (throwable instanceof TimeoutException) {
                ExceptionUtil.sneakyThrow(throwable);
            }
            throw ExceptionUtil.rethrow(throwable);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) ExceptionHandler(com.hazelcast.util.FutureUtil.ExceptionHandler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) CompletedFuture(com.hazelcast.util.executor.CompletedFuture) AbstractCompletableFuture(com.hazelcast.spi.impl.AbstractCompletableFuture) TimeoutException(java.util.concurrent.TimeoutException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 ExceptionHandler (com.hazelcast.util.FutureUtil.ExceptionHandler)2 TimeoutException (java.util.concurrent.TimeoutException)2 Test (org.junit.Test)2 AbstractCompletableFuture (com.hazelcast.spi.impl.AbstractCompletableFuture)1 CompletedFuture (com.hazelcast.util.executor.CompletedFuture)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1