Search in sources :

Example 21 with ExpectedRuntimeException

use of com.hazelcast.test.ExpectedRuntimeException 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 22 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(true);
            return nodeExtension;
        }
    };
    Config config = new Config();
    config.getNetworkConfig().getJoin().getAutoDetectionConfig().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) TestNodeContext(com.hazelcast.instance.TestNodeContext) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Config(com.hazelcast.config.Config) TestNodeContext(com.hazelcast.instance.TestNodeContext) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 23 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().getAutoDetectionConfig().setEnabled(false);
    hazelcastInstance = HazelcastInstanceFactory.newHazelcastInstance(config, randomString(), context);
}
Also used : ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) TestNodeContext(com.hazelcast.instance.TestNodeContext) Config(com.hazelcast.config.Config) TestNodeContext(com.hazelcast.instance.TestNodeContext) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 24 with ExpectedRuntimeException

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

the class RenderTest method whenException.

@Test
public void whenException() {
    MetricsCollector renderer = mock(MetricsCollector.class);
    final ExpectedRuntimeException ex = new ExpectedRuntimeException();
    metricsRegistry.registerStaticProbe(this, "foo", ProbeLevel.MANDATORY, (LongProbeFunction<RenderTest>) source -> {
        throw ex;
    });
    metricsRegistry.collect(renderer);
    verify(renderer).collectException(metricDescriptor("foo"), ex);
    verifyNoMoreInteractions(renderer);
}
Also used : MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) Logger(com.hazelcast.logging.Logger) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Mockito.verify(org.mockito.Mockito.verify) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) DEFAULT_DESCRIPTOR_SUPPLIER(com.hazelcast.internal.metrics.impl.DefaultMetricDescriptorSupplier.DEFAULT_DESCRIPTOR_SUPPLIER) ProbeLevel(com.hazelcast.internal.metrics.ProbeLevel) LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with ExpectedRuntimeException

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

the class JobTest method when_jobFailed_then_jobStatusIsCompletedEventually.

@Test
public void when_jobFailed_then_jobStatusIsCompletedEventually() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS((SupplierEx<Processor>) () -> new MockP().setCompleteError(new ExpectedRuntimeException()), NODE_COUNT)));
    // When
    Job job = instance().getJet().newJob(dag);
    // Then
    try {
        job.getFuture().get();
        fail();
    } catch (ExecutionException expected) {
        assertEquals(FAILED, job.getStatus());
    }
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) ExecutionException(java.util.concurrent.ExecutionException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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