Search in sources :

Example 6 with ExpectedRuntimeException

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

the class InboundResponseHandler_NotifyTest method errorResponse_whenInvocationExists.

// ==================== errorResponse ======================
@Test
public void errorResponse_whenInvocationExists() {
    Invocation invocation = newInvocation();
    invocationRegistry.register(invocation);
    long callId = invocation.op.getCallId();
    inboundResponseHandler.notifyErrorResponse(callId, new ExpectedRuntimeException(), null);
    try {
        invocation.future.joinInternal();
        fail();
    } catch (ExpectedRuntimeException expected) {
    }
    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 7 with ExpectedRuntimeException

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

the class OperationServiceImpl_invokeOnTargetTest method whenExceptionThrownInOperationRun.

@Test
public void whenExceptionThrownInOperationRun() {
    DummyOperation operation = new DummyOperation(new ExceptionThrowingCallable());
    InternalCompletableFuture<String> invocation = operationService.invokeOnTarget(null, operation, getAddress(remote));
    try {
        invocation.joinInternal();
        fail();
    } catch (ExpectedRuntimeException expected) {
    }
}
Also used : ExceptionThrowingCallable(com.hazelcast.test.ExceptionThrowingCallable) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with ExpectedRuntimeException

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

the class Invocation_OffloadedTest method whenStartThrowsException_thenExceptionPropagated.

@Test(expected = ExpectedRuntimeException.class)
public void whenStartThrowsException_thenExceptionPropagated() {
    InternalCompletableFuture f = localOperationService.invokeOnPartition(new OffloadingOperation(op -> new Offload(op) {

        @Override
        public void start() {
            throw new ExpectedRuntimeException();
        }
    }));
    assertCompletesEventually(f);
    f.joinInternal();
}
Also used : Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Accessors.getOperationService(com.hazelcast.test.Accessors.getOperationService) Offload(com.hazelcast.spi.impl.operationservice.Offload) CallStatus(com.hazelcast.spi.impl.operationservice.CallStatus) QuickTest(com.hazelcast.test.annotation.QuickTest) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Operation(com.hazelcast.spi.impl.operationservice.Operation) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) Offload(com.hazelcast.spi.impl.operationservice.Offload) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with ExpectedRuntimeException

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

the class MapTransactionTest method testFailingMapStore.

@Test
public // TODO: @mm - Review following case...
void testFailingMapStore() throws TransactionException {
    final String map = "map";
    final String anotherMap = "anotherMap";
    Config config = getConfig();
    config.getMapConfig(map).setMapStoreConfig(new MapStoreConfig().setEnabled(true).setImplementation(new MapStoreAdapter() {

        public void store(Object key, Object value) {
            throw new ExpectedRuntimeException("Map store intentionally failed :) ");
        }
    }));
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    try {
        h1.executeTransaction(options, new TransactionalTask<Boolean>() {

            public Boolean execute(TransactionalTaskContext context) throws TransactionException {
                assertNull(context.getMap(map).put("1", "value1"));
                assertNull(context.getMap(anotherMap).put("1", "value1"));
                return true;
            }
        });
        fail();
    } catch (ExpectedRuntimeException expected) {
    }
    assertNull(h2.getMap(map).get("1"));
    assertEquals("value1", h2.getMap(anotherMap).get("1"));
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreAdapter(com.hazelcast.map.MapStoreAdapter) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) Mockito.anyObject(org.mockito.Mockito.anyObject) MapStoreConfig(com.hazelcast.config.MapStoreConfig) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 10 with ExpectedRuntimeException

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

the class InternalCompletableFutureTest method newCompletableFuture.

@Override
protected InternalCompletableFuture<Object> newCompletableFuture(boolean exceptional, long completeAfterMillis) {
    InternalCompletableFuture<Object> future = incompleteFuture();
    Executor completionExecutor;
    if (completeAfterMillis <= 0) {
        completionExecutor = CALLER_RUNS;
    } else {
        completionExecutor = new Executor() {

            @Override
            public void execute(Runnable command) {
                new Thread(() -> {
                    sleepAtLeastMillis(completeAfterMillis);
                    command.run();
                }, "test-completion-thread").start();
            }
        };
    }
    if (exceptional) {
        completionExecutor.execute(() -> future.completeExceptionally(new ExpectedRuntimeException()));
    } else {
        completionExecutor.execute(completeNormally(future));
    }
    return future;
}
Also used : 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