Search in sources :

Example 1 with ExpectedRuntimeException

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

the class PacketDispatcherImplTest method whenProblemHandlingPacket_thenSwallowed.

// when one of the handlers throws an exception, the exception is logged but not rethrown
@Test
public void whenProblemHandlingPacket_thenSwallowed() throws Exception {
    Packet packet = new Packet().setPacketType(Packet.Type.OPERATION);
    Mockito.doThrow(new ExpectedRuntimeException()).when(operationExecutor).handle(packet);
    dispatcher.dispatch(packet);
}
Also used : Packet(com.hazelcast.nio.Packet) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ExpectedRuntimeException

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

the class HazelcastInstanceFactoryTest method test_NewInstance_failedAfterStartAndBeforeShutdown.

@Test(expected = ExpectedRuntimeException.class)
public void test_NewInstance_failedAfterStartAndBeforeShutdown() throws Exception {
    NodeContext context = new TestNodeContext() {

        @Override
        public NodeExtension createNodeExtension(Node node) {
            NodeExtension nodeExtension = super.createNodeExtension(node);
            doThrow(new ExpectedRuntimeException()).when(nodeExtension).afterStart();
            doThrow(new ExpectedRuntimeException()).when(nodeExtension).beforeShutdown();
            return nodeExtension;
        }
    };
    Config config = new Config();
    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with ExpectedRuntimeException

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

the class HazelcastInstanceFactoryTest method test_NewInstance_failed_beforeJoin.

@Test(expected = ExpectedRuntimeException.class)
public void test_NewInstance_failed_beforeJoin() throws Exception {
    NodeContext context = new TestNodeContext() {

        @Override
        public NodeExtension createNodeExtension(Node node) {
            NodeExtension nodeExtension = super.createNodeExtension(node);
            doThrow(new ExpectedRuntimeException()).when(nodeExtension).beforeJoin();
            return nodeExtension;
        }
    };
    Config config = new Config();
    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ExpectedRuntimeException

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

the class HazelcastInstanceFactoryTest method test_NewInstance_failed_beforeNodeStart.

@Test(expected = ExpectedRuntimeException.class)
public void test_NewInstance_failed_beforeNodeStart() throws Exception {
    NodeContext context = new TestNodeContext() {

        @Override
        public NodeExtension createNodeExtension(Node node) {
            NodeExtension nodeExtension = super.createNodeExtension(node);
            doThrow(new ExpectedRuntimeException()).when(nodeExtension).beforeStart();
            return nodeExtension;
        }
    };
    Config config = new Config();
    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with ExpectedRuntimeException

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

the class AbstractInvocationFuture_AndThenTest method whenExceptionalResponseAvailableAfterSomeWaiting.

@Test
public void whenExceptionalResponseAvailableAfterSomeWaiting() {
    final ExecutionCallback callback = mock(ExecutionCallback.class);
    future.andThen(callback);
    sleepSeconds(5);
    verifyZeroInteractions(callback);
    final ExpectedRuntimeException ex = new ExpectedRuntimeException();
    future.complete(ex);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(callback).onFailure(ex);
        }
    });
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) AssertTask(com.hazelcast.test.AssertTask) ExecutionCallback(com.hazelcast.core.ExecutionCallback) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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