Search in sources :

Example 31 with ExpectedRuntimeException

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

the class JobTest method when_jobIsFailed_then_jobStatusIsCompletedEventually.

@Test
public void when_jobIsFailed_then_jobStatusIsCompletedEventually() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS((DistributedSupplier<Processor>) () -> new MockP().setCompleteError(new ExpectedRuntimeException()), NODE_COUNT)));
    // When
    Job job = instance1.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) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 32 with ExpectedRuntimeException

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

the class JobTest method when_jobIsFailed_then_trackedJobCanQueryJobResult.

@Test
public void when_jobIsFailed_then_trackedJobCanQueryJobResult() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS((DistributedSupplier<Processor>) () -> new MockP().setCompleteError(new ExpectedRuntimeException()), NODE_COUNT)));
    // When
    instance1.newJob(dag);
    Collection<Job> trackedJobs = instance2.getJobs();
    assertEquals(1, trackedJobs.size());
    Job trackedJob = trackedJobs.iterator().next();
    // Then
    try {
        trackedJob.getFuture().get();
        fail();
    } catch (ExecutionException expected) {
        assertEquals(FAILED, trackedJob.getStatus());
    }
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 33 with ExpectedRuntimeException

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

the class HazelcastInstanceFactoryTest method test_NewInstance_failed_beforeNodeStart.

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

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

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

the class JobTest method when_jobFailed_then_trackedJobCanQueryResult.

@Test
public void when_jobFailed_then_trackedJobCanQueryResult() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS((SupplierEx<Processor>) () -> new MockP().setCompleteError(new ExpectedRuntimeException()), NODE_COUNT)));
    // When
    Job submittedJob = instance().getJet().newJob(dag);
    Collection<Job> trackedJobs = instances()[1].getJet().getJobs();
    Job trackedJob = trackedJobs.stream().filter(j -> j.getId() == submittedJob.getId()).findFirst().orElse(null);
    assertNotNull(trackedJob);
    // Then
    try {
        trackedJob.getFuture().get();
        fail();
    } catch (ExecutionException expected) {
        assertEquals(FAILED, trackedJob.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