Search in sources :

Example 46 with RootCauseMatcher

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

the class CompletableFutureAbstractTest method handleAsync_whenExecutionRejected.

@Test
public void handleAsync_whenExecutionRejected() {
    CompletableFuture<Object> future = newCompletableFuture(false, 0L);
    expectedException.expect(CompletionException.class);
    expectedException.expectCause(new RootCauseMatcher(RejectedExecutionException.class));
    future.handleAsync((v, t) -> null, REJECTING_EXECUTOR).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) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with RootCauseMatcher

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

the class CompletableFutureAbstractTest method handleAsync_withExecutor_withExceptionFromBiFunction.

@Test
public void handleAsync_withExecutor_withExceptionFromBiFunction() {
    CompletableFuture<Object> future = newCompletableFuture(false, 0L);
    CompletableFuture<Object> chained = future.handleAsync((v, t) -> {
        throw new ExpectedRuntimeException();
    }, countingExecutor);
    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 48 with RootCauseMatcher

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

the class ScheduledExecutorServiceBasicTest method schedule_getHandlerDisposeThenRecreateFutureAndGet.

@Test
public void schedule_getHandlerDisposeThenRecreateFutureAndGet() throws Exception {
    int delay = 1;
    String taskName = "Test";
    HazelcastInstance[] instances = createClusterWithCount(2);
    IScheduledExecutorService executorService = getScheduledExecutor(instances, ANY_EXECUTOR_NAME);
    IScheduledFuture<Double> first = executorService.schedule(named(taskName, new PlainCallableTask()), delay, SECONDS);
    ScheduledTaskHandler handler = first.getHandler();
    first.dispose();
    expected.expect(ExecutionException.class);
    expected.expectCause(new RootCauseMatcher(StaleTaskException.class));
    executorService.getScheduledFuture(handler).get();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) IScheduledExecutorService(com.hazelcast.scheduledexecutor.IScheduledExecutorService) ScheduledTaskHandler(com.hazelcast.scheduledexecutor.ScheduledTaskHandler) StaleTaskException(com.hazelcast.scheduledexecutor.StaleTaskException) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with RootCauseMatcher

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

the class MemberAddressProviderTest method instanceFailsToStartWhenAssignedUnbindableAddress.

@Test
public void instanceFailsToStartWhenAssignedUnbindableAddress() {
    final MemberAddressProvider mock = mock(MemberAddressProvider.class);
    when(mock.getBindAddress()).thenReturn(new InetSocketAddress("1.2.3.4", 9999));
    when(mock.getPublicAddress()).thenReturn(new InetSocketAddress("1.2.3.4", 0));
    final Config config = getConfig(mock);
    // we expect an BindException to be thrown (wrapped in an IllegalStateException)
    rule.expect(HazelcastException.class);
    rule.expect(new RootCauseMatcher(BindException.class));
    Hazelcast.newHazelcastInstance(config);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Config(com.hazelcast.config.Config) BindException(java.net.BindException) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 50 with RootCauseMatcher

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

the class PromoteLiteMemberTest method notExistingMember_promotion_shouldFail.

@Test
public void notExistingMember_promotion_shouldFail() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz1 = factory.newHazelcastInstance(new Config());
    HazelcastInstance hz2 = factory.newHazelcastInstance(new Config());
    PromoteLiteMemberOp op = new PromoteLiteMemberOp();
    op.setCallerUuid(UuidUtil.newUnsecureUUID());
    InternalCompletableFuture<MembersView> future = getOperationService(hz2).invokeOnTarget(ClusterServiceImpl.SERVICE_NAME, op, getAddress(hz1));
    exception.expect(CompletionException.class);
    exception.expect(new RootCauseMatcher(IllegalStateException.class));
    future.join();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) PromoteLiteMemberOp(com.hazelcast.internal.cluster.impl.operations.PromoteLiteMemberOp) RootCauseMatcher(com.hazelcast.internal.util.RootCauseMatcher) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) 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