Search in sources :

Example 1 with StuckProcessor

use of com.hazelcast.jet.core.TestProcessors.StuckProcessor 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 2 with StuckProcessor

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

the class JobTest method when_jobIsCompleted_then_trackedJobCanQueryJobResult.

@Test
public void when_jobIsCompleted_then_trackedJobCanQueryJobResult() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
    // When
    instance1.newJob(dag);
    StuckProcessor.executionStarted.await();
    Collection<Job> trackedJobs = instance2.getJobs();
    assertEquals(1, trackedJobs.size());
    Job trackedJob = trackedJobs.iterator().next();
    StuckProcessor.proceedLatch.countDown();
    // Then
    trackedJob.join();
    assertEquals(COMPLETED, trackedJob.getStatus());
}
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 StuckProcessor

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

the class JobTest method testGetJobByIdWhenJobIsRunning.

private void testGetJobByIdWhenJobIsRunning(JetInstance instance) throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
    // When
    Job job = instance1.newJob(dag);
    StuckProcessor.executionStarted.await();
    // Then
    Job trackedJob = instance.getJob(job.getId());
    assertNotNull(trackedJob);
    assertEquals(job.getId(), trackedJob.getId());
    assertTrueEventually(() -> assertEquals(RUNNING, trackedJob.getStatus()));
    StuckProcessor.proceedLatch.countDown();
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job)

Example 4 with StuckProcessor

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

the class JobTest method when_jobIsSubmitted_then_trackedJobCanQueryJobStatus.

@Test
public void when_jobIsSubmitted_then_trackedJobCanQueryJobStatus() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
    // When
    Job submittedJob = instance1.newJob(dag);
    StuckProcessor.executionStarted.await();
    Collection<Job> trackedJobs = instance2.getJobs();
    assertEquals(1, trackedJobs.size());
    Job trackedJob = trackedJobs.iterator().next();
    // Then
    assertTrueEventually(() -> assertEquals(RUNNING, trackedJob.getStatus()));
    submittedJob.cancel();
    joinAndExpectCancellation(submittedJob);
}
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 5 with StuckProcessor

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

the class JobTest method testGetJobByNameWhenJobIsRunning.

private void testGetJobByNameWhenJobIsRunning(JetInstance instance) throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(StuckProcessor::new, NODE_COUNT)));
    JobConfig config = new JobConfig();
    String jobName = "job1";
    config.setName(jobName);
    // When
    Job job = instance1.newJob(dag, config);
    assertEquals(jobName, job.getName());
    StuckProcessor.executionStarted.await();
    // Then
    Job trackedJob = instance.getJob(jobName);
    assertNotNull(trackedJob);
    assertEquals(jobName, trackedJob.getName());
    assertEquals(job.getId(), trackedJob.getId());
    assertTrueEventually(() -> assertEquals(RUNNING, trackedJob.getStatus()));
    StuckProcessor.proceedLatch.countDown();
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) StuckProcessor(com.hazelcast.jet.core.TestProcessors.StuckProcessor) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig)

Aggregations

MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)37 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)37 Job (com.hazelcast.jet.Job)36 Test (org.junit.Test)32 JobConfig (com.hazelcast.jet.config.JobConfig)20 JetInstance (com.hazelcast.jet.JetInstance)12 JetConfig (com.hazelcast.jet.config.JetConfig)8 JobRepository (com.hazelcast.jet.impl.JobRepository)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 JetService (com.hazelcast.jet.impl.JetService)7 STARTING (com.hazelcast.jet.core.JobStatus.STARTING)6 MasterContext (com.hazelcast.jet.impl.MasterContext)6 Future (java.util.concurrent.Future)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 Assert.assertNotNull (org.junit.Assert.assertNotNull)6 Assert.assertTrue (org.junit.Assert.assertTrue)6 Assert.fail (org.junit.Assert.fail)6 Rule (org.junit.Rule)6 ExpectedException (org.junit.rules.ExpectedException)6 RunWith (org.junit.runner.RunWith)6