Search in sources :

Example 76 with RootCauseMatcher

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

the class PartitioningStrategyFactoryTest method whenStrategyInstantiationThrowsException_getPartitioningStrategy_rethrowsException.

// when an exception is thrown while attempting to instantiate a partitioning strategy
// then the exception is rethrown (the same if it is a RuntimeException, otherwise it is peeled,
// see ExceptionUtil.rethrow for all the details).
@Test
public void whenStrategyInstantiationThrowsException_getPartitioningStrategy_rethrowsException() {
    PartitioningStrategyConfig cfg = new PartitioningStrategyConfig();
    cfg.setPartitioningStrategyClass("NonExistentPartitioningStrategy");
    // while attempting to get partitioning strategy, ClassNotFound exception will be thrown and wrapped in HazelcastException
    expectedException.expect(new RootCauseMatcher(ClassNotFoundException.class));
    // use a random UUID as map name, to avoid obtaining the PartitioningStrategy from cache.
    partitioningStrategyFactory.getPartitioningStrategy(UUID.randomUUID().toString(), cfg);
}
Also used : PartitioningStrategyConfig(com.hazelcast.config.PartitioningStrategyConfig) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 77 with RootCauseMatcher

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

the class TargetTest method testConstructor_withInvalidPartitionId.

@Test
public void testConstructor_withInvalidPartitionId() throws Exception {
    // retrieve the wanted constructor and make it accessible
    Constructor<Target> constructor = Target.class.getDeclaredConstructor(Target.TargetMode.class, PartitionIdSet.class);
    constructor.setAccessible(true);
    // we expect an IllegalArgumentException to be thrown
    rule.expect(new RootCauseMatcher(IllegalArgumentException.class));
    constructor.newInstance(Target.TargetMode.PARTITION_OWNER, null);
}
Also used : RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 78 with RootCauseMatcher

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

the class ScheduledExecutorServiceBasicTest method getErroneous_durable.

@Test
public void getErroneous_durable() throws Exception {
    int delay = 2;
    String taskName = "Test";
    String completionLatchName = "completionLatch";
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    ICountDownLatch latch = instances[1].getCPSubsystem().getCountDownLatch(completionLatchName);
    latch.trySetCount(1);
    IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
    assertOpenEventually(latch);
    instances[1].getLifecycleService().shutdown();
    Thread.sleep(2000);
    expected.expect(ExecutionException.class);
    expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 79 with RootCauseMatcher

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

the class ScheduledExecutorServiceBasicTest method getErroneous.

@Test
public void getErroneous() throws Exception {
    int delay = 2;
    String taskName = "Test";
    String completionLatchName = "completionLatch";
    HazelcastInstance[] instances = createClusterWithCount(2);
    String key = generateKeyOwnedBy(instances[1]);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    ICountDownLatch latch = instances[1].getCPSubsystem().getCountDownLatch(completionLatchName);
    latch.trySetCount(1);
    IScheduledFuture<Double> future = executorService.scheduleOnKeyOwner(named(taskName, new ErroneousCallableTask(completionLatchName)), key, delay, SECONDS);
    assertOpenEventually(latch);
    expected.expect(ExecutionException.class);
    expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
    future.get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ICountDownLatch(com.hazelcast.cp.ICountDownLatch) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 80 with RootCauseMatcher

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

the class ScheduledExecutorServiceBasicTest method exception_suppressesFutureExecutions.

@Test
public void exception_suppressesFutureExecutions() throws ExecutionException, InterruptedException {
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService service = instances[0].getScheduledExecutorService(ANY_EXECUTOR_NAME);
    final IScheduledFuture f = service.scheduleAtFixedRate(new ErroneousRunnableTask(), 1, 1, TimeUnit.SECONDS);
    assertTrueEventually(() -> assertTrue(f.isDone()));
    assertEquals(1L, f.getStats().getTotalRuns());
    expected.expect(ExecutionException.class);
    expected.expectCause(new RootCauseMatcher(IllegalStateException.class, "Erroneous task"));
    f.get();
}
Also used : IScheduledFuture(com.hazelcast.scheduledexecutor.IScheduledFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) 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