Search in sources :

Example 6 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class Reducers method execute.

private static <T> Optional<T> execute(StreamContext context, DAG dag, Vertex combiner) {
    String listName = uniqueListName();
    Vertex writeList = dag.newVertex("write-" + listName, SinkProcessors.writeListP(listName));
    dag.edge(between(combiner, writeList));
    IList<T> list = context.getJetInstance().getList(listName);
    executeJob(context, dag);
    if (list.isEmpty()) {
        list.destroy();
        return Optional.empty();
    }
    T result = list.get(0);
    list.destroy();
    return Optional.of(result);
}
Also used : Vertex(com.hazelcast.jet.core.Vertex)

Example 7 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class BackpressureTest method testBackpressure.

@Test
public void testBackpressure() throws Exception {
    DAG dag = new DAG();
    final int member1Port = jet1.getCluster().getLocalMember().getAddress().getPort();
    final Member member2 = jet2.getCluster().getLocalMember();
    final int ptionOwnedByMember2 = jet1.getHazelcastInstance().getPartitionService().getPartitions().stream().filter(p -> p.getOwner().equals(member2)).map(Partition::getPartitionId).findAny().orElseThrow(() -> new RuntimeException("Can't find a partition owned by member " + jet2));
    Vertex source = dag.newVertex("source", ProcessorMetaSupplier.of((Address address) -> ProcessorSupplier.of(address.getPort() == member1Port ? GenerateP::new : noopP())));
    Vertex hiccup = dag.newVertex("hiccup", HiccupP::new);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP("counts"));
    dag.edge(between(source, hiccup).distributed().partitioned(wholeItem(), (x, y) -> ptionOwnedByMember2)).edge(between(hiccup, sink));
    jet1.newJob(dag).join();
    assertCounts(jet1.getMap("counts"));
}
Also used : AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Traverser(com.hazelcast.jet.Traverser) JetInstance(com.hazelcast.jet.JetInstance) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) RunWith(org.junit.runner.RunWith) Address(com.hazelcast.nio.Address) HashMap(java.util.HashMap) Partition(com.hazelcast.core.Partition) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) DistributedFunctions.wholeItem(com.hazelcast.jet.function.DistributedFunctions.wholeItem) Traversers.lazy(com.hazelcast.jet.Traversers.lazy) Traversers.traverseIterable(com.hazelcast.jet.Traversers.traverseIterable) Util.entry(com.hazelcast.jet.Util.entry) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DAG(com.hazelcast.jet.core.DAG) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Before(org.junit.Before) JetConfig(com.hazelcast.jet.config.JetConfig) NightlyTest(com.hazelcast.test.annotation.NightlyTest) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) Assert.assertNotNull(org.junit.Assert.assertNotNull) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Category(org.junit.experimental.categories.Category) Member(com.hazelcast.core.Member) Vertex(com.hazelcast.jet.core.Vertex) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) Entry(java.util.Map.Entry) Processors.noopP(com.hazelcast.jet.core.processor.Processors.noopP) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) Partition(com.hazelcast.core.Partition) Vertex(com.hazelcast.jet.core.Vertex) Address(com.hazelcast.nio.Address) DAG(com.hazelcast.jet.core.DAG) Member(com.hazelcast.core.Member) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 8 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class AnyMatchReducer method reduce.

@Override
public Boolean reduce(StreamContext context, Pipe<? extends T> upstream) {
    String listName = uniqueListName();
    DAG dag = new DAG();
    Vertex previous = upstream.buildDAG(dag);
    Vertex anyMatch = dag.newVertex("any-match", () -> new AnyMatchP<>(predicate));
    Vertex writer = dag.newVertex("write-" + listName, SinkProcessors.writeListP(listName));
    dag.edge(between(previous, anyMatch)).edge(between(anyMatch, writer));
    executeJob(context, dag);
    IList<Boolean> results = context.getJetInstance().getList(listName);
    boolean result = anyMatch(results);
    results.destroy();
    return result;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG)

Example 9 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class BiConsumerCombinerReducer method reduce.

@Override
public R reduce(StreamContext context, Pipe<? extends T> upstream) {
    DAG dag = new DAG();
    Vertex accumulatorVertex = buildAccumulator(dag, upstream, supplier, accumulator);
    Vertex combinerVertex = buildCombiner(dag, accumulatorVertex, combiner);
    return execute(context, dag, combinerVertex, DistributedFunction.identity());
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG)

Example 10 with Vertex

use of com.hazelcast.jet.core.Vertex in project hazelcast-jet by hazelcast.

the class CollectorReducer method buildAccumulator.

static <T, R> Vertex buildAccumulator(DAG dag, Pipe<T> upstream, Supplier<R> supplier, BiConsumer<R, ? super T> accumulator) {
    Vertex accumulatorVertex = dag.newVertex("accumulator", () -> new CollectorAccumulateP<>(accumulator, supplier));
    if (upstream.isOrdered()) {
        accumulatorVertex.localParallelism(1);
    }
    Vertex previous = upstream.buildDAG(dag);
    if (previous != accumulatorVertex) {
        dag.edge(between(previous, accumulatorVertex));
    }
    return accumulatorVertex;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex)

Aggregations

Vertex (com.hazelcast.jet.core.Vertex)189 DAG (com.hazelcast.jet.core.DAG)130 Test (org.junit.Test)95 QuickTest (com.hazelcast.test.annotation.QuickTest)57 Job (com.hazelcast.jet.Job)53 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)48 Entry (java.util.Map.Entry)41 List (java.util.List)28 Edge.between (com.hazelcast.jet.core.Edge.between)26 Map (java.util.Map)26 Assert.assertEquals (org.junit.Assert.assertEquals)23 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)21 IntStream (java.util.stream.IntStream)21 Assert.assertTrue (org.junit.Assert.assertTrue)19 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)18 Category (org.junit.experimental.categories.Category)18 Collectors.toList (java.util.stream.Collectors.toList)17 Nonnull (javax.annotation.Nonnull)17 FunctionEx (com.hazelcast.function.FunctionEx)15 Edge (com.hazelcast.jet.core.Edge)15