Search in sources :

Example 26 with ExpectedRuntimeException

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

the class HazelcastInstanceFactoryTest method test_NewInstance_failed_beforeNodeShutdown.

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

        @Override
        public NodeExtension createNodeExtension(Node node) {
            NodeExtension nodeExtension = super.createNodeExtension(node);
            doAnswer(new Answer() {

                final AtomicBoolean throwException = new AtomicBoolean(false);

                @Override
                public Object answer(InvocationOnMock invocation) throws Throwable {
                    if (throwException.compareAndSet(false, true)) {
                        throw new ExpectedRuntimeException();
                    }
                    return null;
                }
            }).when(nodeExtension).beforeShutdown();
            return nodeExtension;
        }
    };
    Config config = new Config();
    config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
    try {
        hazelcastInstance.getLifecycleService().terminate();
    } catch (ExpectedRuntimeException expected) {
        hazelcastInstance.getLifecycleService().terminate();
        throw expected;
    }
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 27 with ExpectedRuntimeException

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

the class HazelcastInstanceFactoryTest method test_NewInstance_failed_afterNodeStart.

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

        @Override
        public NodeExtension createNodeExtension(Node node) {
            NodeExtension nodeExtension = super.createNodeExtension(node);
            doThrow(new ExpectedRuntimeException()).when(nodeExtension).afterStart();
            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 28 with ExpectedRuntimeException

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

the class NonBlockingIOThreadAbstractTest 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).handle();
    selector.scheduleSelectAction(selectionKey);
    assertTrueEventually(new AssertTask() {

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

Example 29 with ExpectedRuntimeException

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

the class AsyncInboundResponseHandlerTest method whenPacketThrowsException.

@Test
public void whenPacketThrowsException() throws Exception {
    final Packet badPacket = new Packet(serializationService.toBytes(new NormalResponse("bad", 1, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
    final Packet goodPacket = new Packet(serializationService.toBytes(new NormalResponse("good", 1, 0, false))).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
    doThrow(new ExpectedRuntimeException()).when(responsePacketHandler).handle(badPacket);
    asyncHandler.handle(badPacket);
    asyncHandler.handle(goodPacket);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            verify(responsePacketHandler).handle(goodPacket);
        }
    });
}
Also used : Packet(com.hazelcast.nio.Packet) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) AssertTask(com.hazelcast.test.AssertTask) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with ExpectedRuntimeException

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

the class ClientDelegatingFutureTest_CompletionStageTest method newCompletableFuture.

@Override
protected CompletableFuture<Object> newCompletableFuture(boolean exceptional, long completeAfterMillis) {
    invocation.getCallIdSequence().next();
    ClientInvocationFuture cf = invocation.getClientInvocationFuture();
    ClientDelegatingFuture<Object> future = new ClientDelegatingFuture<>(cf, serializationService, MapGetCodec::decodeResponse);
    Executor completionExecutor;
    if (completeAfterMillis <= 0) {
        completionExecutor = CALLER_RUNS;
    } else {
        completionExecutor = command -> new Thread(() -> {
            sleepAtLeastMillis(completeAfterMillis);
            command.run();
        }, "test-completion-thread").start();
    }
    if (exceptional) {
        completionExecutor.execute(() -> invocation.completeExceptionally(new ExpectedRuntimeException()));
    } else {
        completionExecutor.execute(completeNormally(invocation));
    }
    return future;
}
Also used : MapGetCodec(com.hazelcast.client.impl.protocol.codec.MapGetCodec) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Executor(java.util.concurrent.Executor)

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