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);
}
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));
}
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);
}
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);
}
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);
}
Aggregations