Search in sources :

Example 71 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class JobTest method when_jobSubmittedWithNewJobIfAbsent_then_jobStatusIsStarting.

private void when_jobSubmittedWithNewJobIfAbsent_then_jobStatusIsStarting(HazelcastInstance submitter) {
    PSThatWaitsOnInit.initLatch = new CountDownLatch(1);
    DAG dag = new DAG().vertex(new Vertex("test", new PSThatWaitsOnInit(Identity::new)));
    // When
    Job job = submitter.getJet().newJobIfAbsent(dag, new JobConfig());
    JobStatus status = job.getStatus();
    assertTrue(status == NOT_RUNNING || status == STARTING);
    PSThatWaitsOnInit.initLatch.countDown();
    // Then
    assertJobStatusEventually(job, COMPLETED);
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Identity(com.hazelcast.jet.core.TestProcessors.Identity) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig)

Example 72 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class JobTest method when_jobSubmittedWithNewJobIfAbsent_then_trackedJobCanQueryStatus.

@Test
public void when_jobSubmittedWithNewJobIfAbsent_then_trackedJobCanQueryStatus() throws InterruptedException {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, NODE_COUNT)));
    // When
    Job submittedJob = instance().getJet().newJobIfAbsent(dag, new JobConfig());
    NoOutputSourceP.executionStarted.await();
    Collection<Job> trackedJobs = instances()[1].getJet().getJobs();
    Job trackedJob = trackedJobs.stream().filter(j -> j.getId() == submittedJob.getId()).findFirst().orElse(null);
    assertNotNull(trackedJob);
    // Then
    assertJobStatusEventually(trackedJob, RUNNING);
    cancelAndJoin(submittedJob);
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 73 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class JobTest method when_jobIsCompleted_then_jobSubmissionTimeIsQueried.

@Test
public void when_jobIsCompleted_then_jobSubmissionTimeIsQueried() {
    // Given
    DAG dag = new DAG().vertex(new Vertex("test", new MockPS(NoOutputSourceP::new, NODE_COUNT)));
    JobConfig config = new JobConfig();
    String jobName = randomName();
    config.setName(jobName);
    // When
    Job job = instance().getJet().newJob(dag, config);
    NoOutputSourceP.proceedLatch.countDown();
    job.join();
    Job trackedJob = instance().getJet().getJob(jobName);
    // Then
    assertNotNull(trackedJob);
    assertNotEquals(0, job.getSubmissionTime());
    assertNotEquals(0, trackedJob.getSubmissionTime());
}
Also used : MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) NoOutputSourceP(com.hazelcast.jet.core.TestProcessors.NoOutputSourceP) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class JobTimeoutClusterTest method when_masterFails_timedOutJobIsCancelled.

@Test
public void when_masterFails_timedOutJobIsCancelled() {
    final HazelcastInstance[] instances = createHazelcastInstances(2);
    final HazelcastInstance oldMaster = instances[0];
    final HazelcastInstance newMaster = instances[1];
    assertClusterSizeEventually(2, newMaster);
    assertClusterStateEventually(ClusterState.ACTIVE, newMaster);
    final DAG dag = new DAG();
    dag.newVertex("stuck", () -> new MockP().streaming());
    final JobConfig jobConfig = new JobConfig().setTimeoutMillis(10000L).setSnapshotIntervalMillis(1L).setProcessingGuarantee(ProcessingGuarantee.EXACTLY_ONCE);
    final Job job = oldMaster.getJet().newJob(dag, jobConfig);
    final long jobId = job.getId();
    // start and wait for the job to start running
    assertJobStatusEventually(job, JobStatus.RUNNING);
    final JobRepository oldJobRepository = new JobRepository(oldMaster);
    assertTrueEventually(() -> {
        final JobExecutionRecord record = oldJobRepository.getJobExecutionRecord(jobId);
        assertTrue(record.snapshotId() > 0);
    });
    // kill old master and wait for the cluster to reconfigure
    oldMaster.getLifecycleService().terminate();
    assertClusterStateEventually(ClusterState.ACTIVE, newMaster);
    assertClusterSize(1, newMaster);
    // wait for the job to be restarted and cancelled due to timeout
    final Job restartedJob = newMaster.getJet().getJob(jobId);
    assertNotNull(restartedJob);
    assertJobStatusEventually(restartedJob, JobStatus.FAILED);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) JobRepository(com.hazelcast.jet.impl.JobRepository) JobExecutionRecord(com.hazelcast.jet.impl.JobExecutionRecord) JobConfig(com.hazelcast.jet.config.JobConfig) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 75 with JobConfig

use of com.hazelcast.jet.config.JobConfig in project hazelcast by hazelcast.

the class JobTimeoutTest method when_jobIsCompletedBeforeTimeout_jobIsNotCancelled.

@Test
public void when_jobIsCompletedBeforeTimeout_jobIsNotCancelled() {
    final HazelcastInstance hz = createHazelcastInstance();
    final DAG dag = new DAG();
    dag.newVertex("normal", MockP::new);
    final JobConfig jobConfig = new JobConfig().setTimeoutMillis(1000L);
    final Job job = hz.getJet().newJob(dag, jobConfig);
    job.join();
    assertEquals(JobStatus.COMPLETED, job.getStatus());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MockP(com.hazelcast.jet.core.TestProcessors.MockP) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

JobConfig (com.hazelcast.jet.config.JobConfig)254 Test (org.junit.Test)196 Job (com.hazelcast.jet.Job)160 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)111 QuickTest (com.hazelcast.test.annotation.QuickTest)109 Pipeline (com.hazelcast.jet.pipeline.Pipeline)70 HazelcastInstance (com.hazelcast.core.HazelcastInstance)64 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)46 Category (org.junit.experimental.categories.Category)45 Assert.assertEquals (org.junit.Assert.assertEquals)43 DAG (com.hazelcast.jet.core.DAG)41 JobRepository (com.hazelcast.jet.impl.JobRepository)40 List (java.util.List)36 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)35 Config (com.hazelcast.config.Config)33 Assert.assertTrue (org.junit.Assert.assertTrue)32 ArrayList (java.util.ArrayList)31 Sinks (com.hazelcast.jet.pipeline.Sinks)28 RUNNING (com.hazelcast.jet.core.JobStatus.RUNNING)27 RunWith (org.junit.runner.RunWith)27