Search in sources :

Example 21 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.

the class CompletableFutureAbstractTest method thenApplyAsync_exceptional.

@Test
public void thenApplyAsync_exceptional() {
    CompletableFuture<Object> future = newCompletableFuture(true, 1000L);
    CompletableFuture<Object> chained = future.thenApplyAsync(Function.identity());
    assertTrueEventually(() -> assertTrue(chained.isDone()));
    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 22 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.

the class CompletableFutureAbstractTest method thenRunAsync_onIncompleteFuture_whenExecutionRejected.

@Test
public void thenRunAsync_onIncompleteFuture_whenExecutionRejected() {
    CompletableFuture<Object> future = newCompletableFuture(false, 1000L);
    expectedException.expect(CompletionException.class);
    expectedException.expectCause(new RootCauseMatcher(RejectedExecutionException.class));
    future.thenRunAsync(() -> ignore(), REJECTING_EXECUTOR).join();
}
Also used : RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.

the class CompletableFutureAbstractTest method thenRun_whenActionThrowsException.

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

Example 24 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.

the class CompletableFutureAbstractTest method handle_withExceptionFromFirstStage_failsWithSecondException.

// since handle* methods process and substitute processing outcome of first stage,
// if the the handler BiFunction fails with an exception, the chained CompletionStage
// will fail with the exception thrown from the handler's body (not the one thrown from
// the original CompletionStage).
@Test
public void handle_withExceptionFromFirstStage_failsWithSecondException() {
    CompletableFuture<Object> future = newCompletableFuture(true, 0L);
    CompletableFuture<Object> chained = future.handle((v, t) -> {
        throw new IllegalArgumentException();
    });
    assertTrueEventually(() -> assertTrue(chained.isCompletedExceptionally()));
    expectedException.expect(CompletionException.class);
    expectedException.expectCause(new RootCauseMatcher(IllegalArgumentException.class));
    chained.join();
}
Also used : RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with RootCauseMatcher

use of com.hazelcast.internal.util.RootCauseMatcher in project hazelcast by hazelcast.

the class CompletableFutureAbstractTest method thenRunAsync_whenExecutionRejected.

// Tests for exceptional completion of dependent stage due to executor rejecting execution
@Test
public void thenRunAsync_whenExecutionRejected() {
    CompletableFuture<Object> future = newCompletableFuture(false, 0L);
    expectedException.expect(CompletionException.class);
    expectedException.expectCause(new RootCauseMatcher(RejectedExecutionException.class));
    future.thenRunAsync(() -> ignore(), REJECTING_EXECUTOR).join();
}
Also used : RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

RootCauseMatcher (com.hazelcast.internal.util.RootCauseMatcher)122 QuickTest (com.hazelcast.test.annotation.QuickTest)118 Test (org.junit.Test)118 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)106 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)64 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)31 CompletableFutureTestUtil (com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil)26 CancellationException (java.util.concurrent.CancellationException)25 CountDownLatch (java.util.concurrent.CountDownLatch)25 CALLER_RUNS (com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS)24 InternalCompletableFuture.newCompletedFuture (com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture)24 CountingExecutor (com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil.CountingExecutor)24 CompletableFutureTestUtil.ignore (com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil.ignore)24 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)24 HazelcastTestSupport.assertInstanceOf (com.hazelcast.test.HazelcastTestSupport.assertInstanceOf)24 HazelcastTestSupport.assertOpenEventually (com.hazelcast.test.HazelcastTestSupport.assertOpenEventually)24 HazelcastTestSupport.assertTrueEventually (com.hazelcast.test.HazelcastTestSupport.assertTrueEventually)24 CompletableFuture (java.util.concurrent.CompletableFuture)24 CompletionException (java.util.concurrent.CompletionException)24 CompletionStage (java.util.concurrent.CompletionStage)24