Search in sources :

Example 1 with DAG

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

the class WatermarkCoalescer_IntegrationTest method createDag.

private static DAG createDag(Mode mode, List<Object> input1, List<Object> input2) {
    DAG dag = new DAG();
    Vertex mapWmToString = dag.newVertex("mapWmToString", MapWatermarksToString::new).localParallelism(1);
    Vertex sink = dag.newVertex("sink", writeListP("sinkList")).localParallelism(1);
    dag.edge(between(mapWmToString, sink));
    switch(mode) {
        case TWO_EDGES:
            Vertex edge1 = dag.newVertex("edge1", ListSource.supplier(input1)).localParallelism(1);
            Vertex edge2 = dag.newVertex("edge2", ListSource.supplier(input2)).localParallelism(1);
            dag.edge(from(edge1).to(mapWmToString, 0));
            dag.edge(from(edge2).to(mapWmToString, 1));
            break;
        case TWO_QUEUES:
            Vertex edge = dag.newVertex("edge", ListSource.supplier(input1, input2)).localParallelism(2);
            dag.edge(between(edge, mapWmToString));
            break;
        default:
            throw new IllegalArgumentException(mode.toString());
    }
    return dag;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG)

Example 2 with DAG

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

the class DetermineLocalParallelismTest method testWithParallelism.

private void testWithParallelism(int preferred, int specified, int expected) {
    DAG dag = new DAG();
    dag.newVertex("x", new ValidatingMetaSupplier(preferred, expected)).localParallelism(specified);
    validateExecutionPlans(dag);
}
Also used : DAG(com.hazelcast.jet.core.DAG)

Example 3 with DAG

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

the class ExceptionUtilTest method test_serializationFromNodeToClient.

@Test
public void test_serializationFromNodeToClient() {
    // create one member and one client
    createJetMember();
    JetInstance client = createJetClient();
    RuntimeException exc = new RuntimeException("myException");
    try {
        DAG dag = new DAG();
        dag.newVertex("source", () -> new MockP().setCompleteError(exc)).localParallelism(1);
        client.newJob(dag).join();
    } catch (Exception caught) {
        assertThat(caught.toString(), containsString(exc.toString()));
        TestUtil.assertExceptionInCauses(exc, caught);
    } finally {
        shutdownFactory();
    }
}
Also used : JetInstance(com.hazelcast.jet.JetInstance) MockP(com.hazelcast.jet.core.TestProcessors.MockP) DAG(com.hazelcast.jet.core.DAG) JetException(com.hazelcast.jet.JetException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 4 with DAG

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

the class Planner method createDag.

DAG createDag() {
    Map<Transform, List<Transform>> adjacencyMap = pipeline.adjacencyMap();
    validateNoLeakage(adjacencyMap);
    // Calculate greatest common denominator of frame lengths from all transforms in the pipeline
    long frameSizeGcd = Util.gcd(adjacencyMap.keySet().stream().map(Transform::watermarkFrameSize).filter(frameSize -> frameSize > 0).mapToLong(i -> i).toArray());
    WatermarkEmissionPolicy emitPolicy = frameSizeGcd > 0 ? emitByFrame(tumblingWinPolicy(frameSizeGcd)) : noThrottling();
    // Replace emission policy
    for (Transform transform : adjacencyMap.keySet()) {
        if (transform instanceof StreamSourceTransform) {
            StreamSourceTransform t = (StreamSourceTransform) transform;
            if (t.getWmParams() != null) {
                t.setWmGenerationParams(t.getWmParams().withEmitPolicy(emitPolicy));
            }
        } else if (transform instanceof TimestampTransform) {
            TimestampTransform t = (TimestampTransform) transform;
            t.setWmGenerationParams(t.getWmGenParams().withEmitPolicy(emitPolicy));
        }
    }
    Iterable<Transform> sorted = topologicalSort(adjacencyMap, Object::toString);
    for (Transform transform : sorted) {
        transform.addToDag(this);
    }
    return dag;
}
Also used : Processor(com.hazelcast.jet.core.Processor) HashMap(java.util.HashMap) HashSet(java.util.HashSet) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) Map(java.util.Map) WatermarkEmissionPolicy.noThrottling(com.hazelcast.jet.core.WatermarkEmissionPolicy.noThrottling) BiConsumer(java.util.function.BiConsumer) TimestampTransform(com.hazelcast.jet.impl.pipeline.transform.TimestampTransform) Edge.from(com.hazelcast.jet.core.Edge.from) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) TopologicalSorter.topologicalSort(com.hazelcast.jet.impl.TopologicalSorter.topologicalSort) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) DistributedSupplier(com.hazelcast.jet.function.DistributedSupplier) WatermarkEmissionPolicy.emitByFrame(com.hazelcast.jet.core.WatermarkEmissionPolicy.emitByFrame) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) WatermarkEmissionPolicy(com.hazelcast.jet.core.WatermarkEmissionPolicy) Set(java.util.Set) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) Consumer(java.util.function.Consumer) Vertex(com.hazelcast.jet.core.Vertex) Util(com.hazelcast.jet.impl.util.Util) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Entry(java.util.Map.Entry) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) SlidingWindowPolicy.tumblingWinPolicy(com.hazelcast.jet.core.SlidingWindowPolicy.tumblingWinPolicy) WatermarkEmissionPolicy(com.hazelcast.jet.core.WatermarkEmissionPolicy) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) SinkTransform(com.hazelcast.jet.impl.pipeline.transform.SinkTransform) TimestampTransform(com.hazelcast.jet.impl.pipeline.transform.TimestampTransform) Transform(com.hazelcast.jet.impl.pipeline.transform.Transform) StreamSourceTransform(com.hazelcast.jet.impl.pipeline.transform.StreamSourceTransform) TimestampTransform(com.hazelcast.jet.impl.pipeline.transform.TimestampTransform)

Example 5 with DAG

use of com.hazelcast.jet.core.DAG 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)

Aggregations

DAG (com.hazelcast.jet.core.DAG)211 Test (org.junit.Test)159 Vertex (com.hazelcast.jet.core.Vertex)127 QuickTest (com.hazelcast.test.annotation.QuickTest)100 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)91 Job (com.hazelcast.jet.Job)64 Entry (java.util.Map.Entry)51 List (java.util.List)38 Assert.assertEquals (org.junit.Assert.assertEquals)37 Map (java.util.Map)36 JobConfig (com.hazelcast.jet.config.JobConfig)35 Assert.assertTrue (org.junit.Assert.assertTrue)31 Edge (com.hazelcast.jet.core.Edge)29 IntStream (java.util.stream.IntStream)29 Category (org.junit.experimental.categories.Category)28 Collectors.toList (java.util.stream.Collectors.toList)26 HazelcastInstance (com.hazelcast.core.HazelcastInstance)23 FunctionEx (com.hazelcast.function.FunctionEx)23 ArrayList (java.util.ArrayList)22 Nonnull (javax.annotation.Nonnull)21