Search in sources :

Example 86 with RootCauseMatcher

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

the class BiCompletionStageTest method runAfterEither.

// {run|accept|apply}AfterEither* tests. Javadoc of CompletionStage states:
// If a stage is dependent on
// <em>either</em> of two others, and only one of them completes
// exceptionally, no guarantees are made about whether the dependent
// stage completes normally or exceptionally.
@Test
public void runAfterEither() {
    CompletableFuture<Void> eitherFuture = future1.runAfterEither(future2, () -> {
        assertTrue(future1.isDone() || future2.isDone());
    });
    boolean exceptionalCompletion = invocation1.throwsException || invocation2.throwsException;
    assertTrueEventually(() -> {
        assertTrue(eitherFuture.isDone());
    });
    if (exceptionalCompletion && eitherFuture.isCompletedExceptionally()) {
        expected.expect(CompletionException.class);
        expected.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
        eitherFuture.join();
    }
    // non-exceptional completion
    assertNull(eitherFuture.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 87 with RootCauseMatcher

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

the class BiCompletionStageTest method thenAcceptBothAsync.

@Test
public void thenAcceptBothAsync() {
    CompletableFuture<Void> combinedFuture = future1.thenAcceptBothAsync(future2, (v1, v2) -> {
        assertTrue(future1.isDone());
        assertTrue(future2.isDone());
        assertNull(v1);
        assertNull(v2);
    });
    boolean exceptionalCompletion = invocation1.throwsException || invocation2.throwsException;
    assertTrueEventually(() -> {
        assertTrue(combinedFuture.isDone());
    });
    if (exceptionalCompletion) {
        expected.expect(CompletionException.class);
        expected.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
        combinedFuture.join();
    }
    // non-exceptional completion
    assertNull(combinedFuture.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 88 with RootCauseMatcher

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

the class BiCompletionStageTest method acceptEither.

@Test
public void acceptEither() {
    CompletableFuture<Void> eitherFuture = future1.acceptEither(future2, value -> {
        assertTrue(future1.isDone() || future2.isDone());
    });
    boolean exceptionalCompletion = invocation1.throwsException || invocation2.throwsException;
    assertTrueEventually(() -> {
        assertTrue(eitherFuture.isDone());
    });
    if (exceptionalCompletion && eitherFuture.isCompletedExceptionally()) {
        expected.expect(CompletionException.class);
        expected.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
        eitherFuture.join();
    }
    // non-exceptional completion
    assertNull(eitherFuture.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 89 with RootCauseMatcher

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

the class BiCompletionStageTest method thenCombine.

@Test
public void thenCombine() {
    CompletableFuture<Integer> combinedFuture = future1.thenCombine(future2, (v1, v2) -> {
        assertTrue(future1.isDone());
        assertTrue(future2.isDone());
        assertNull(v1);
        assertNull(v2);
        return 1;
    });
    boolean exceptionalCompletion = invocation1.throwsException || invocation2.throwsException;
    assertTrueEventually(() -> {
        assertTrue(combinedFuture.isDone());
    });
    if (exceptionalCompletion) {
        expected.expect(CompletionException.class);
        expected.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
        combinedFuture.join();
    }
    // non-exceptional completion
    assertEquals(1, (int) combinedFuture.join());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 90 with RootCauseMatcher

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

the class BiCompletionStageTest method applyToEitherAsync_withExecutor.

@Test
public void applyToEitherAsync_withExecutor() {
    AtomicInteger executionCounter = new AtomicInteger();
    CompletableFuture<Object> eitherFuture = future1.applyToEitherAsync(future2, value -> {
        assertTrue(future1.isDone() || future2.isDone());
        executionCounter.getAndIncrement();
        return expectedResult;
    }, countingExecutor);
    boolean exceptionalCompletion = invocation1.throwsException || invocation2.throwsException;
    assertTrueEventually(() -> {
        assertTrue(eitherFuture.isDone());
    });
    if (exceptionalCompletion && eitherFuture.isCompletedExceptionally()) {
        expected.expect(CompletionException.class);
        expected.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
        eitherFuture.join();
    }
    // non-exceptional completion
    assertSame(expectedResult, eitherFuture.join());
    assertEquals(1, executionCounter.get());
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) 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