Search in sources :

Example 1 with SequencesInPartitionsMetaSupplier

use of com.hazelcast.jet.core.JobRestartWithSnapshotTest.SequencesInPartitionsMetaSupplier in project hazelcast-jet by hazelcast.

the class SnapshotFailureTest method when_snapshotFails_then_jobShouldNotFail.

@Test
public void when_snapshotFails_then_jobShouldNotFail() {
    int numPartitions = 2;
    int numElements = 10;
    IMapJet<Object, Object> results = instance1.getMap("results");
    DAG dag = new DAG();
    SequencesInPartitionsMetaSupplier sup = new SequencesInPartitionsMetaSupplier(numPartitions, numElements);
    Vertex generator = dag.newVertex("generator", peekOutputP(throttle(sup, 2))).localParallelism(1);
    Vertex writeMap = dag.newVertex("writeMap", writeMapP(results.getName())).localParallelism(1);
    dag.edge(between(generator, writeMap));
    JobConfig config = new JobConfig();
    config.setProcessingGuarantee(ProcessingGuarantee.EXACTLY_ONCE);
    config.setSnapshotIntervalMillis(100);
    Job job = instance1.newJob(dag, config);
    // let's start a second job that will watch the snapshots map and write failed
    // SnapshotRecords to a list, which we will check for presence of failed snapshot
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.mapJournal(snapshotsMapName(job.getId()), event -> event.getNewValue() instanceof SnapshotRecord && ((SnapshotRecord) event.getNewValue()).status() == SnapshotStatus.FAILED, EventJournalMapEvent::getNewValue, JournalInitialPosition.START_FROM_OLDEST)).peek().drainTo(Sinks.list("failed_snapshot_records"));
    instance1.newJob(p);
    job.join();
    assertEquals("numPartitions", numPartitions, results.size());
    assertEquals("offset partition 0", numElements - 1, results.get(0));
    assertEquals("offset partition 1", numElements - 1, results.get(1));
    assertTrue("no failure occurred in store", storeFailed);
    assertFalse("no failed snapshot appeared in snapshotsMap", instance1.getList("failed_snapshot_records").isEmpty());
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) SnapshotRecord(com.hazelcast.jet.impl.execution.SnapshotRecord) RunWith(org.junit.runner.RunWith) EventJournalConfig(com.hazelcast.config.EventJournalConfig) IMapJet(com.hazelcast.jet.IMapJet) SequencesInPartitionsMetaSupplier(com.hazelcast.jet.core.JobRestartWithSnapshotTest.SequencesInPartitionsMetaSupplier) SnapshotStatus(com.hazelcast.jet.impl.execution.SnapshotRecord.SnapshotStatus) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) MapConfig(com.hazelcast.config.MapConfig) TestUtil.throttle(com.hazelcast.jet.core.TestUtil.throttle) ExpectedException(org.junit.rules.ExpectedException) Job(com.hazelcast.jet.Job) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) Before(org.junit.Before) JetConfig(com.hazelcast.jet.config.JetConfig) SnapshotRepository(com.hazelcast.jet.impl.SnapshotRepository) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JobConfig(com.hazelcast.jet.config.JobConfig) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DiagnosticProcessors.peekOutputP(com.hazelcast.jet.core.processor.DiagnosticProcessors.peekOutputP) AMapStore(com.hazelcast.client.map.helpers.AMapStore) Serializable(java.io.Serializable) Sources(com.hazelcast.jet.pipeline.Sources) Rule(org.junit.Rule) JournalInitialPosition(com.hazelcast.jet.pipeline.JournalInitialPosition) Assert.assertFalse(org.junit.Assert.assertFalse) MapStoreConfig(com.hazelcast.config.MapStoreConfig) ProcessingGuarantee(com.hazelcast.jet.config.ProcessingGuarantee) SnapshotRepository.snapshotsMapName(com.hazelcast.jet.impl.SnapshotRepository.snapshotsMapName) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) SinkProcessors.writeMapP(com.hazelcast.jet.core.processor.SinkProcessors.writeMapP) SnapshotRecord(com.hazelcast.jet.impl.execution.SnapshotRecord) Job(com.hazelcast.jet.Job) SequencesInPartitionsMetaSupplier(com.hazelcast.jet.core.JobRestartWithSnapshotTest.SequencesInPartitionsMetaSupplier) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Aggregations

AMapStore (com.hazelcast.client.map.helpers.AMapStore)1 EventJournalConfig (com.hazelcast.config.EventJournalConfig)1 MapConfig (com.hazelcast.config.MapConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 IMapJet (com.hazelcast.jet.IMapJet)1 JetInstance (com.hazelcast.jet.JetInstance)1 Job (com.hazelcast.jet.Job)1 JetConfig (com.hazelcast.jet.config.JetConfig)1 JobConfig (com.hazelcast.jet.config.JobConfig)1 ProcessingGuarantee (com.hazelcast.jet.config.ProcessingGuarantee)1 Edge.between (com.hazelcast.jet.core.Edge.between)1 SequencesInPartitionsMetaSupplier (com.hazelcast.jet.core.JobRestartWithSnapshotTest.SequencesInPartitionsMetaSupplier)1 TestUtil.throttle (com.hazelcast.jet.core.TestUtil.throttle)1 DiagnosticProcessors.peekOutputP (com.hazelcast.jet.core.processor.DiagnosticProcessors.peekOutputP)1 SinkProcessors.writeMapP (com.hazelcast.jet.core.processor.SinkProcessors.writeMapP)1 SnapshotRepository (com.hazelcast.jet.impl.SnapshotRepository)1 SnapshotRepository.snapshotsMapName (com.hazelcast.jet.impl.SnapshotRepository.snapshotsMapName)1 SnapshotRecord (com.hazelcast.jet.impl.execution.SnapshotRecord)1 SnapshotStatus (com.hazelcast.jet.impl.execution.SnapshotRecord.SnapshotStatus)1 JournalInitialPosition (com.hazelcast.jet.pipeline.JournalInitialPosition)1