Search in sources :

Example 36 with ExpectedRuntimeException

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

the class NioThreadAbstractTest method whenHandlerThrowException_thenHandlerOnFailureCalledWithThatException.

@Test
public void whenHandlerThrowException_thenHandlerOnFailureCalledWithThatException() throws Exception {
    startThread();
    SelectionKey selectionKey = mock(SelectionKey.class);
    selectionKey.attach(handler);
    when(selectionKey.isValid()).thenReturn(true);
    doThrow(new ExpectedRuntimeException()).when(handler).process();
    selector.scheduleSelectAction(selectionKey);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            verify(handler).onError(isA(ExpectedRuntimeException.class));
        }
    });
    assertStillRunning();
}
Also used : SelectionKey(java.nio.channels.SelectionKey) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) AssertTask(com.hazelcast.test.AssertTask) Test(org.junit.Test)

Example 37 with ExpectedRuntimeException

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

the class InboundResponseHandler_NotifyTest method errorResponse_whenInvocationMissing_thenNothingBadHappens.

@Test
public void errorResponse_whenInvocationMissing_thenNothingBadHappens() {
    Invocation invocation = newInvocation();
    invocationRegistry.register(invocation);
    long callId = invocation.op.getCallId();
    invocationRegistry.deregister(invocation);
    inboundResponseHandler.notifyErrorResponse(callId, new ExpectedRuntimeException(), null);
    assertInvocationDeregisteredEventually(callId);
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 38 with ExpectedRuntimeException

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

the class CompletableFutureAbstractTest method thenCompose_whenActionThrowsException.

@Test
public void thenCompose_whenActionThrowsException() {
    CompletableFuture<Object> future = newCompletableFuture(false, 1000L);
    expectedException.expect(CompletionException.class);
    expectedException.expectCause(new RootCauseMatcher(ExpectedRuntimeException.class));
    future.thenCompose(v -> {
        throw new ExpectedRuntimeException();
    }).join();
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) CountingExecutor(com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil.CountingExecutor) Assert.assertSame(org.junit.Assert.assertSame) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) HazelcastTestSupport.assertOpenEventually(com.hazelcast.test.HazelcastTestSupport.assertOpenEventually) ExpectedException(org.junit.rules.ExpectedException) CALLER_RUNS(com.hazelcast.internal.util.ConcurrencyUtil.CALLER_RUNS) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) HazelcastTestSupport.assertTrueEventually(com.hazelcast.test.HazelcastTestSupport.assertTrueEventually) CancellationException(java.util.concurrent.CancellationException) Executor(java.util.concurrent.Executor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) HazelcastTestSupport.assertInstanceOf(com.hazelcast.test.HazelcastTestSupport.assertInstanceOf) Category(org.junit.experimental.categories.Category) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) CompletionStage(java.util.concurrent.CompletionStage) Assert.assertNull(org.junit.Assert.assertNull) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) CompletableFutureTestUtil.ignore(com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil.ignore) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) CompletableFutureTestUtil(com.hazelcast.spi.impl.operationservice.impl.CompletableFutureTestUtil) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) 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 39 with ExpectedRuntimeException

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

the class CompletableFutureAbstractTest method handleAsync_withExceptionFromBiFunction.

@Test
public void handleAsync_withExceptionFromBiFunction() {
    CompletableFuture<Object> future = newCompletableFuture(false, 1000L);
    CompletableFuture<Object> chained = future.handleAsync((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 40 with ExpectedRuntimeException

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

the class AbstractInvocationFuture_GetSafely method whenRuntimeException.

@Test
public void whenRuntimeException() throws Exception {
    ExpectedRuntimeException ex = new ExpectedRuntimeException();
    future.completeExceptionally(ex);
    Future joinFuture = spawn(() -> 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) 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