Search in sources :

Example 1 with MockPS

use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast-jet by hazelcast.

the class ExecutionLifecycleTest method when_pmsInitThrows_then_jobFails.

@Test
public void when_pmsInitThrows_then_jobFails() {
    // Given
    RuntimeException e = new RuntimeException("mock error");
    DAG dag = new DAG().vertex(new Vertex("test", new MockPMS(() -> new MockPS(MockP::new, NODE_COUNT)).setInitError(e)));
    // When
    Job job = runJobExpectFailure(dag, e);
    // Then
    assertPmsClosedWithError(e);
    assertJobFailed(job, e);
}
Also used : MockPMS(com.hazelcast.jet.core.TestProcessors.MockPMS) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 2 with MockPS

use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast-jet by hazelcast.

the class ExecutionLifecycleTest method when_jobCancelled_then_psCloseNotCalledBeforeTaskletsDone.

@Test
public void when_jobCancelled_then_psCloseNotCalledBeforeTaskletsDone() {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(() -> new StuckProcessor(10_000), NODE_COUNT)));
    // When
    Job job = instance.newJob(dag);
    assertOpenEventually(StuckProcessor.executionStarted);
    // Then
    job.cancel();
    assertTrueEventually(() -> assertEquals(JobStatus.COMPLETING, job.getStatus()), 3);
    assertTrueFiveSeconds(() -> {
        assertEquals(JobStatus.COMPLETING, job.getStatus());
        assertEquals("PS.close called before execution finished", 0, MockPS.closeCount.get());
    });
    StuckProcessor.proceedLatch.countDown();
    expectedException.expect(CancellationException.class);
    job.join();
    assertEquals("PS.close not called after execution finished", NODE_COUNT, MockPS.closeCount.get());
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 3 with MockPS

use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast-jet by hazelcast.

the class ExecutionLifecycleTest method when_executionCancelled_then_jobCompletedWithCancellationException.

@Test
public void when_executionCancelled_then_jobCompletedWithCancellationException() throws Throwable {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPMS(() -> new MockPS(StuckProcessor::new, NODE_COUNT))));
    // When
    Job job = instance.newJob(dag);
    try {
        StuckProcessor.executionStarted.await();
        job.cancel();
        job.join();
        fail("Job execution should fail");
    } catch (CancellationException ignored) {
    }
    assertTrueEventually(() -> {
        assertJobFailed(job, new CancellationException());
        assertPsClosedWithError(new CancellationException());
        assertPmsClosedWithError(new CancellationException());
    });
}
Also used : MockPMS(com.hazelcast.jet.core.TestProcessors.MockPMS) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) CancellationException(java.util.concurrent.CancellationException) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 4 with MockPS

use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast-jet by hazelcast.

the class ExecutionLifecycleTest method when_processorInitThrows_then_failJob.

@Test
public void when_processorInitThrows_then_failJob() {
    // Given
    DAG dag = new DAG();
    RuntimeException e = new RuntimeException("mock error");
    dag.newVertex("faulty", new MockPMS(() -> new MockPS(() -> new MockP().setInitError(e), NODE_COUNT)));
    // When
    Job job = runJobExpectFailure(dag, e);
    // Then
    assertPClosedWithError(e, true);
    assertPsClosedWithError(e);
    assertPmsClosedWithError(e);
    assertJobFailed(job, e);
}
Also used : MockPMS(com.hazelcast.jet.core.TestProcessors.MockPMS) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 5 with MockPS

use of com.hazelcast.jet.core.TestProcessors.MockPS in project hazelcast-jet by hazelcast.

the class ExecutionLifecycleTest method when_pmsGetThrows_then_jobFails.

@Test
public void when_pmsGetThrows_then_jobFails() {
    // Given
    RuntimeException e = new RuntimeException("mock error");
    DAG dag = new DAG().vertex(new Vertex("faulty", new MockPMS(() -> new MockPS(MockP::new, NODE_COUNT)).setGetError(e)));
    // When
    Job job = runJobExpectFailure(dag, e);
    // Then
    assertPmsClosedWithError(e);
    assertJobFailed(job, e);
}
Also used : MockPMS(com.hazelcast.jet.core.TestProcessors.MockPMS) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Aggregations

MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)135 Job (com.hazelcast.jet.Job)127 Test (org.junit.Test)115 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)56 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)53 JobConfig (com.hazelcast.jet.config.JobConfig)49 QuickTest (com.hazelcast.test.annotation.QuickTest)42 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)40 MockPMS (com.hazelcast.jet.core.TestProcessors.MockPMS)31 MockP (com.hazelcast.jet.core.TestProcessors.MockP)30 HazelcastInstance (com.hazelcast.core.HazelcastInstance)21 CountDownLatch (java.util.concurrent.CountDownLatch)21 JobRepository (com.hazelcast.jet.impl.JobRepository)18 CancellationException (java.util.concurrent.CancellationException)16 Future (java.util.concurrent.Future)16 JetInstance (com.hazelcast.jet.JetInstance)15 MasterContext (com.hazelcast.jet.impl.MasterContext)15 ExpectedException (org.junit.rules.ExpectedException)15 STARTING (com.hazelcast.jet.core.JobStatus.STARTING)14 SlowTest (com.hazelcast.test.annotation.SlowTest)14