Search in sources :

Example 71 with JetInstance

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

the class StreamKafkaPTest method when_projectionFunctionProvided_thenAppliedToReadRecords.

@Test
public void when_projectionFunctionProvided_thenAppliedToReadRecords() throws Exception {
    int messageCount = 20;
    JetInstance[] instances = new JetInstance[2];
    Arrays.setAll(instances, i -> createJetMember());
    Pipeline p = Pipeline.create();
    p.drawFrom(KafkaSources.<Integer, String, String>kafka(properties, rec -> rec.value() + "-x", topic1Name)).drainTo(Sinks.list("sink"));
    Job job = instances[0].newJob(p);
    sleepAtLeastSeconds(3);
    for (int i = 0; i < messageCount; i++) {
        produce(topic1Name, i, Integer.toString(i));
    }
    IList<String> list = instances[0].getList("sink");
    assertTrueEventually(() -> {
        assertEquals(messageCount, list.size());
        for (int i = 0; i < messageCount; i++) {
            String value = Integer.toString(i) + "-x";
            assertTrue("missing entry: " + value, list.contains(value));
        }
    }, 5);
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) Job(com.hazelcast.jet.Job) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 72 with JetInstance

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

the class Processors_globalAggregationIntegrationTest method runTest.

private void runTest(List<Long> sourceItems, Long expectedOutput) throws Exception {
    JetInstance instance = createJetMember();
    AggregateOperation1<Long, ?, Long> summingOp = summingLong((Long l) -> l);
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", () -> new ListSource(sourceItems)).localParallelism(1);
    Vertex sink = dag.newVertex("sink", writeListP("sink"));
    if (singleStageProcessor) {
        Vertex aggregate = dag.newVertex("aggregate", Processors.aggregateP(summingOp)).localParallelism(1);
        dag.edge(between(source, aggregate).distributed().allToOne()).edge(between(aggregate, sink).isolated());
    } else {
        Vertex accumulate = dag.newVertex("accumulate", Processors.accumulateP(summingOp));
        Vertex combine = dag.newVertex("combine", combineP(summingOp)).localParallelism(1);
        dag.edge(between(source, accumulate)).edge(between(accumulate, combine).distributed().allToOne()).edge(between(combine, sink).isolated());
    }
    instance.newJob(dag).join();
    IList<Long> sinkList = instance.getList("sink");
    assertEquals(singletonList(expectedOutput), new ArrayList<>(sinkList));
    // wait a little more and make sure, that there are no more frames
    Thread.sleep(1000);
    assertEquals(singletonList(expectedOutput), new ArrayList<>(sinkList));
    assertEquals(expectedOutput, sinkList.get(0));
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) JetInstance(com.hazelcast.jet.JetInstance) ListSource(com.hazelcast.jet.core.TestProcessors.ListSource) AggregateOperations.summingLong(com.hazelcast.jet.aggregate.AggregateOperations.summingLong) DAG(com.hazelcast.jet.core.DAG)

Example 73 with JetInstance

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

the class S8 method s6.

static void s6() {
    // tag::s6[]
    JetInstance jet = Jet.newJetInstance();
    Jet.newJetInstance();
    int upperBound = 10;
    DAG dag = new DAG();
// rest of the code same as above
// end::s6[]
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) DAG(com.hazelcast.jet.core.DAG)

Example 74 with JetInstance

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

the class HelloWorld method main.

public static void main(String[] args) {
    // Create the specification of the computation pipeline. Note
    // it's a pure POJO: no instance of Jet needed to create it.
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<String>list("text")).flatMap(word -> traverseArray(word.toLowerCase().split("\\W+"))).filter(word -> !word.isEmpty()).groupingKey(wholeItem()).aggregate(counting()).drainTo(Sinks.map("counts"));
    // Start Jet, populate the input list
    JetInstance jet = Jet.newJetInstance();
    try {
        List<String> text = jet.getList("text");
        text.add("hello world hello hello world");
        text.add("world world hello world");
        // Perform the computation
        jet.newJob(p).join();
        // Check the results
        Map<String, Long> counts = jet.getMap("counts");
        System.out.println("Count of hello: " + counts.get("hello"));
        System.out.println("Count of world: " + counts.get("world"));
    } finally {
        Jet.shutdownAll();
    }
}
Also used : Sources(com.hazelcast.jet.pipeline.Sources) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) List(java.util.List) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Map(java.util.Map) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) Sinks(com.hazelcast.jet.pipeline.Sinks) Jet(com.hazelcast.jet.Jet) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 75 with JetInstance

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

the class ImdgConnectors method s14.

static void s14() {
    JetInstance jet = Jet.newJetInstance();
    // tag::s14[]
    IList<Integer> inputList = jet.getList("inputList");
    for (int i = 0; i < 10; i++) {
        inputList.add(i);
    }
    Pipeline p = Pipeline.create();
    p.drawFrom(Sources.<Integer>list("inputList")).map(i -> "item" + i).drainTo(Sinks.list("resultList"));
    jet.newJob(p).join();
    IList<String> resultList = jet.getList("resultList");
    System.out.println("Results: " + new ArrayList<>(resultList));
// end::s14[]
}
Also used : EventJournalCacheEvent(com.hazelcast.cache.journal.EventJournalCacheEvent) JetConfig(com.hazelcast.jet.config.JetConfig) StreamStage(com.hazelcast.jet.pipeline.StreamStage) Person(datamodel.Person) JetInstance(com.hazelcast.jet.JetInstance) DistributedFunctions(com.hazelcast.jet.function.DistributedFunctions) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Sinks(com.hazelcast.jet.pipeline.Sinks) IListJet(com.hazelcast.jet.IListJet) EntryBackupProcessor(com.hazelcast.map.EntryBackupProcessor) ArrayList(java.util.ArrayList) BatchStage(com.hazelcast.jet.pipeline.BatchStage) Sources(com.hazelcast.jet.pipeline.Sources) EntryProcessor(com.hazelcast.map.EntryProcessor) Entry(java.util.Map.Entry) START_FROM_CURRENT(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_CURRENT) ClientConfig(com.hazelcast.client.config.ClientConfig) IList(com.hazelcast.core.IList) Jet(com.hazelcast.jet.Jet) DistributedFunction(com.hazelcast.jet.function.DistributedFunction) EventJournalMapEvent(com.hazelcast.map.journal.EventJournalMapEvent) JetInstance(com.hazelcast.jet.JetInstance) ArrayList(java.util.ArrayList) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

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