Search in sources :

Example 41 with ExpectedRuntimeException

use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.

the class AbstractInvocationFuture_JoinTest method whenRuntimeException.

@Test
public void whenRuntimeException() throws Exception {
    ExpectedRuntimeException ex = new ExpectedRuntimeException();
    future.completeExceptionally(ex);
    Future joinFuture = spawn(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return future.join();
        }
    });
    assertCompletesEventually(joinFuture);
    try {
        joinFuture.get();
        fail();
    } catch (ExecutionException e) {
        CompletionException wrapper = assertInstanceOf(CompletionException.class, e.getCause());
        assertSame(ex, wrapper.getCause());
    }
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) CompletionException(java.util.concurrent.CompletionException) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) CompletionException(java.util.concurrent.CompletionException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with ExpectedRuntimeException

use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.

the class CompletableFutureAbstractTest method thenRun_whenActionThrowsException.

private void thenRun_whenActionThrowsException(long completionDelay) {
    CompletableFuture<Object> future = newCompletableFuture(false, completionDelay);
    CompletableFuture<Void> chained = future.thenRun(() -> {
        throw new ExpectedRuntimeException();
    });
    assertTrueEventually(() -> assertTrue(future.isDone()));
    assertTrueEventually(() -> assertTrue(chained.isDone()));
    assertFalse(future.isCompletedExceptionally());
    assertTrue(chained.isCompletedExceptionally());
    expectedException.expect(CompletionException.class);
    expectedException.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
    chained.join();
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher)

Example 43 with ExpectedRuntimeException

use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.

the class CompletableFutureAbstractTest method handle_withExceptionFromBiFunction.

@Test
public void handle_withExceptionFromBiFunction() {
    CompletableFuture<Object> future = newCompletableFuture(false, 0L);
    CompletableFuture<Object> chained = future.handle((v, t) -> {
        throw new ExpectedRuntimeException();
    });
    assertTrueEventually(() -> assertTrue(chained.isCompletedExceptionally()));
    expectedException.expect(CompletionException.class);
    expectedException.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
    chained.join();
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with ExpectedRuntimeException

use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.

the class CompletableFutureAbstractTest method whenCompleteAsync_withExceptionFromBiConsumer.

@Test
public void whenCompleteAsync_withExceptionFromBiConsumer() {
    CompletableFuture<Object> future = newCompletableFuture(false, 1000L);
    CompletableFuture<Object> chained = future.whenComplete((v, t) -> {
        throw new ExpectedRuntimeException();
    });
    assertTrueEventually(() -> assertTrue(chained.isCompletedExceptionally()));
    expectedException.expect(CompletionException.class);
    expectedException.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
    chained.join();
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with ExpectedRuntimeException

use of com.hazelcast.test.ExpectedRuntimeException in project hazelcast by hazelcast.

the class CompletableFutureAbstractTest method whenCompleteAsync_withExecutor_withExceptionFromBiConsumer.

@Test
public void whenCompleteAsync_withExecutor_withExceptionFromBiConsumer() {
    CompletableFuture<Object> future = newCompletableFuture(false, 0L);
    CompletableFuture<Object> chained = future.whenCompleteAsync((v, t) -> {
        throw new ExpectedRuntimeException();
    }, countingExecutor);
    assertTrueEventually(() -> assertTrue(chained.isCompletedExceptionally()));
    expectedException.expect(CompletionException.class);
    expectedException.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
    chained.join();
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)50 Test (org.junit.Test)44 QuickTest (com.hazelcast.test.annotation.QuickTest)36 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)27 RootCauseMatcher (com.hazelcast.internal.util.RootCauseMatcher)16 Config (com.hazelcast.config.Config)11 ExecutionException (java.util.concurrent.ExecutionException)7 Executor (java.util.concurrent.Executor)6 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)5 CompletionException (java.util.concurrent.CompletionException)5 TestNodeContext (com.hazelcast.instance.TestNodeContext)4 SlowTest (com.hazelcast.test.annotation.SlowTest)4 Category (org.junit.experimental.categories.Category)4 RunWith (org.junit.runner.RunWith)4 CALLER_RUNS (com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS)3 Job (com.hazelcast.jet.Job)3 MockP (com.hazelcast.jet.core.TestProcessors.MockP)3 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)3 InternalCompletableFuture.newCompletedFuture (com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture)3 CompletableFutureTestUtil (com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil)3