Search in sources :

Example 6 with MockP

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

use of com.hazelcast.jet.core.TestProcessors.MockP in project hazelcast by hazelcast.

the class JobLifecycleMetricsTest method multipleJobsSubmittedAndCompleted.

@Test
public void multipleJobsSubmittedAndCompleted() {
    // when
    Job job1 = hzInstances[0].getJet().newJob(batchPipeline());
    job1.join();
    job1.cancel();
    // then
    assertTrueEventually(() -> assertJobStats(1, 1, 1, 1, 0));
    // given
    DAG dag = new DAG();
    Throwable e = new AssertionError("mock error");
    Vertex source = dag.newVertex("source", ListSource.supplier(singletonList(1)));
    Vertex process = dag.newVertex("faulty", new MockPMS(() -> new MockPS(() -> new MockP().setProcessError(e), MEMBER_COUNT)));
    dag.edge(between(source, process));
    // when
    Job job2 = hzInstances[0].getJet().newJob(dag);
    try {
        job2.join();
        fail("Expected exception not thrown!");
    } catch (Exception ex) {
    // ignore
    }
    // then
    assertTrueEventually(() -> assertJobStats(2, 2, 2, 1, 1));
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) MockPMS(com.hazelcast.jet.core.TestProcessors.MockPMS) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) MockP(com.hazelcast.jet.core.TestProcessors.MockP) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with MockP

use of com.hazelcast.jet.core.TestProcessors.MockP in project hazelcast by hazelcast.

the class JobMetrics_MiscTest method when_metricsForJobDisabled_then_emptyMetrics.

@Test
public void when_metricsForJobDisabled_then_emptyMetrics() throws Throwable {
    DAG dag = new DAG();
    dag.newVertex("v1", MockP::new);
    dag.newVertex("v2", (SupplierEx<Processor>) NoOutputSourceP::new);
    JobConfig config = new JobConfig().setMetricsEnabled(false).setStoreMetricsAfterJobCompletion(true);
    Job job = hz().getJet().newJob(dag, config);
    // when
    NoOutputSourceP.executionStarted.await();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    // then
    assertTrueAllTheTime(() -> assertEmptyJobMetrics(job, false), 2);
    // when
    NoOutputSourceP.proceedLatch.countDown();
    job.join();
    assertJobStatusEventually(job, JobStatus.COMPLETED);
    // then
    assertEmptyJobMetrics(job, true);
}
Also used : Processor(com.hazelcast.jet.core.Processor) MockP(com.hazelcast.jet.core.TestProcessors.MockP) DAG(com.hazelcast.jet.core.DAG) 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 9 with MockP

use of com.hazelcast.jet.core.TestProcessors.MockP in project hazelcast by hazelcast.

the class ExecutionLifecycleTest method when_processorInitThrows_then_failJob.

@Test
public void when_processorInitThrows_then_failJob() {
    // Given
    DAG dag = new DAG();
    dag.newVertex("faulty", new MockPMS(() -> new MockPS(() -> new MockP().setInitError(MOCK_ERROR), MEMBER_COUNT)));
    // When
    Job job = runJobExpectFailure(dag, false);
    // Then
    assertPClosedWithError();
    assertPsClosedWithError();
    assertPmsClosedWithError();
    assertJobFailed(job, MOCK_ERROR);
}
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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with MockP

use of com.hazelcast.jet.core.TestProcessors.MockP in project hazelcast by hazelcast.

the class ExecutionLifecycleTest method when_processorCloseThrows_then_jobSucceeds.

@Test
public void when_processorCloseThrows_then_jobSucceeds() {
    // Given
    DAG dag = new DAG();
    dag.newVertex("faulty", new MockPMS(() -> new MockPS(() -> new MockP().setCloseError(MOCK_ERROR), MEMBER_COUNT)));
    // When
    Job job = newJob(dag);
    job.join();
    // Then
    assertPClosedWithoutError();
    assertPsClosedWithoutError();
    assertPmsClosedWithoutError();
    assertJobSucceeded(job);
}
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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MockP (com.hazelcast.jet.core.TestProcessors.MockP)56 Test (org.junit.Test)54 Job (com.hazelcast.jet.Job)49 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)35 QuickTest (com.hazelcast.test.annotation.QuickTest)35 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)30 MockPMS (com.hazelcast.jet.core.TestProcessors.MockPMS)26 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 JobConfig (com.hazelcast.jet.config.JobConfig)11 DAG (com.hazelcast.jet.core.DAG)9 ExecutionException (java.util.concurrent.ExecutionException)8 ExpectedException (org.junit.rules.ExpectedException)5 JetException (com.hazelcast.jet.JetException)4 Processor (com.hazelcast.jet.core.Processor)4 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)4 NoOutputSourceP (com.hazelcast.jet.core.TestProcessors.NoOutputSourceP)3 Config (com.hazelcast.config.Config)2 JetInstance (com.hazelcast.jet.JetInstance)2 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2