Search in sources :

Example 26 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class CancellationTest method when_jobCancelled_then_jobStatusIsSetEventually.

@Test
public void when_jobCancelled_then_jobStatusIsSetEventually() {
    // Given
    JetInstance instance = newInstance();
    DAG dag = new DAG();
    dag.newVertex("slow", StuckSource::new);
    Job job = instance.newJob(dag);
    assertExecutionStarted();
    // When
    job.cancel();
    // Then
    assertTrueEventually(() -> assertEquals(JobStatus.COMPLETED, job.getStatus()), 3);
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 27 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class Processors_slidingWindowingIntegrationTest method runTest.

private void runTest(List<MyEvent> sourceEvents, List<TimestampedEntry<String, Long>> expectedOutput) throws Exception {
    JetInstance instance = createJetMember();
    SlidingWindowPolicy wDef = slidingWinPolicy(2000, 1000);
    DAG dag = new DAG();
    // to prevent serialization of whole class
    boolean isBatchLocal = isBatch;
    DistributedFunction<? super MyEvent, ?> keyFn = MyEvent::getKey;
    DistributedToLongFunction<? super MyEvent> timestampFn = MyEvent::getTimestamp;
    Vertex source = dag.newVertex("source", () -> new EmitListP(sourceEvents, isBatchLocal)).localParallelism(1);
    Vertex insertPP = dag.newVertex("insertWmP", insertWatermarksP(wmGenParams(timestampFn, limitingLagAndLull(500, 1000), emitByFrame(wDef), -1))).localParallelism(1);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeListP("sink"));
    dag.edge(between(source, insertPP).isolated());
    AggregateOperation<LongAccumulator, Long> counting = counting();
    if (singleStageProcessor) {
        Vertex slidingWin = dag.newVertex("slidingWin", Processors.aggregateToSlidingWindowP(singletonList(keyFn), singletonList(timestampFn), TimestampKind.EVENT, wDef, counting, TimestampedEntry::new));
        dag.edge(between(insertPP, slidingWin).partitioned(MyEvent::getKey).distributed()).edge(between(slidingWin, sink));
    } else {
        Vertex accumulateByFrame = dag.newVertex("accumulateByFrame", Processors.accumulateByFrameP(singletonList(keyFn), singletonList(timestampFn), TimestampKind.EVENT, wDef, counting.withFinishFn(identity())));
        Vertex slidingWin = dag.newVertex("slidingWin", combineToSlidingWindowP(wDef, counting, TimestampedEntry::new));
        dag.edge(between(insertPP, accumulateByFrame).partitioned(keyFn)).edge(between(accumulateByFrame, slidingWin).partitioned(entryKey()).distributed()).edge(between(slidingWin, sink));
    }
    Job job = instance.newJob(dag);
    if (isBatch) {
        job.join();
    }
    IList<MyEvent> sinkList = instance.getList("sink");
    assertTrueEventually(() -> assertEquals(streamToString(expectedOutput.stream()), streamToString(new ArrayList<>(sinkList).stream())), 5);
    // wait a little more and make sure, that there are no more frames
    Thread.sleep(1000);
    assertTrue(sinkList.size() == expectedOutput.size());
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) ArrayList(java.util.ArrayList) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Job(com.hazelcast.jet.Job)

Example 28 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet by hazelcast.

the class SnapshotFailureTest method setup.

@Before
public void setup() {
    JetConfig config = new JetConfig();
    config.getInstanceConfig().setCooperativeThreadCount(LOCAL_PARALLELISM);
    // force snapshots to fail by adding a failing map store configuration for snapshot data maps
    MapConfig mapConfig = new MapConfig(SnapshotRepository.SNAPSHOT_DATA_NAME_PREFIX + '*');
    MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new FailingMapStore());
    config.getHazelcastConfig().addMapConfig(mapConfig);
    config.getHazelcastConfig().addEventJournalConfig(new EventJournalConfig().setMapName(SnapshotRepository.SNAPSHOT_NAME_PREFIX + '*'));
    JetInstance[] instances = createJetMembers(config, 2);
    instance1 = instances[0];
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) JetConfig(com.hazelcast.jet.config.JetConfig) EventJournalConfig(com.hazelcast.config.EventJournalConfig) Before(org.junit.Before)

Example 29 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.

the class Considerations method s9.

static void s9() {
    // tag::s9[]
    SerializerConfig serializerConfig = new SerializerConfig().setImplementation(new MyItemSerializer()).setTypeClass(MyItem.class);
    JetConfig config = new JetConfig();
    config.getHazelcastConfig().getSerializationConfig().addSerializerConfig(serializerConfig);
    JetInstance jet = Jet.newJetInstance(config);
// end::s9[]
}
Also used : SerializerConfig(com.hazelcast.config.SerializerConfig) JetInstance(com.hazelcast.jet.JetInstance) JetConfig(com.hazelcast.jet.config.JetConfig)

Example 30 with JetInstance

use of com.hazelcast.jet.JetInstance in project hazelcast-jet-reference-manual by hazelcast.

the class ImdgConnectors method s9.

static void s9() {
    // tag::s9[]
    JetConfig cfg = new JetConfig();
    cfg.getHazelcastConfig().getMapEventJournalConfig("inputMap").setEnabled(true).setCapacity(// how many events to keep before evicting
    1000).setTimeToLiveSeconds(// evict events older than this
    10);
    JetInstance jet = Jet.newJetInstance(cfg);
    // end::s9[]
    // tag::s10[]
    cfg.getHazelcastConfig().getCacheEventJournalConfig("inputCache").setEnabled(true).setCapacity(1000).setTimeToLiveSeconds(10);
// end::s10[]
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) JetConfig(com.hazelcast.jet.config.JetConfig)

Aggregations

JetInstance (com.hazelcast.jet.JetInstance)84 Test (org.junit.Test)45 Job (com.hazelcast.jet.Job)32 JetConfig (com.hazelcast.jet.config.JetConfig)22 MockPS (com.hazelcast.jet.core.TestProcessors.MockPS)14 Pipeline (com.hazelcast.jet.pipeline.Pipeline)14 JobConfig (com.hazelcast.jet.config.JobConfig)13 StuckProcessor (com.hazelcast.jet.core.TestProcessors.StuckProcessor)12 DAG (com.hazelcast.jet.core.DAG)10 ExpectedException (org.junit.rules.ExpectedException)10 Jet (com.hazelcast.jet.Jet)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 JetService (com.hazelcast.jet.impl.JetService)8 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 JobRepository (com.hazelcast.jet.impl.JobRepository)7 Sources (com.hazelcast.jet.pipeline.Sources)7 CancellationException (java.util.concurrent.CancellationException)7 Assert.assertNotNull (org.junit.Assert.assertNotNull)7 Before (org.junit.Before)7