Search in sources :

Example 61 with DAG

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

the class JobLifecycleMetricsTest method multipleJobsSubmittedAndCompleted.

@Test
public void multipleJobsSubmittedAndCompleted() {
    // when
    Job job1 = hzInstances[0].getJet().newJob(batchPipeline());
    job1.join();
    job1.cancel();
    // then
    assertTrueEventually(() -> assertJobStats(1, 1, 1, 1, 0));
    // given
    DAG dag = new DAG();
    Throwable e = new AssertionError("mock error");
    Vertex source = dag.newVertex("source", ListSource.supplier(singletonList(1)));
    Vertex process = dag.newVertex("faulty", new MockPMS(() -> new MockPS(() -> new MockP().setProcessError(e), MEMBER_COUNT)));
    dag.edge(between(source, process));
    // when
    Job job2 = hzInstances[0].getJet().newJob(dag);
    try {
        job2.join();
        fail("Expected exception not thrown!");
    } catch (Exception ex) {
    // ignore
    }
    // then
    assertTrueEventually(() -> assertJobStats(2, 2, 2, 1, 1));
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) MockPMS(com.hazelcast.jet.core.TestProcessors.MockPMS) MockPS(com.hazelcast.jet.core.TestProcessors.MockPS) MockP(com.hazelcast.jet.core.TestProcessors.MockP) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 62 with DAG

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

the class JobMetrics_MiscTest method when_jobNotYetRunning_then_emptyMetrics.

@Test
public void when_jobNotYetRunning_then_emptyMetrics() {
    DAG dag = new DAG();
    BlockingInInitMetaSupplier.latch = new CountDownLatch(1);
    dag.newVertex("v1", new BlockingInInitMetaSupplier());
    Job job = hz().getJet().newJob(dag, JOB_CONFIG_WITH_METRICS);
    assertTrueAllTheTime(() -> assertEmptyJobMetrics(job, false), 2);
    BlockingInInitMetaSupplier.latch.countDown();
    assertTrueEventually(() -> assertJobHasMetrics(job, false));
}
Also used : DAG(com.hazelcast.jet.core.DAG) CountDownLatch(java.util.concurrent.CountDownLatch) Job(com.hazelcast.jet.Job) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 63 with DAG

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

the class JobMetrics_MiscTest method when_metricsForJobDisabled_then_emptyMetrics.

@Test
public void when_metricsForJobDisabled_then_emptyMetrics() throws Throwable {
    DAG dag = new DAG();
    dag.newVertex("v1", MockP::new);
    dag.newVertex("v2", (SupplierEx<Processor>) NoOutputSourceP::new);
    JobConfig config = new JobConfig().setMetricsEnabled(false).setStoreMetricsAfterJobCompletion(true);
    Job job = hz().getJet().newJob(dag, config);
    // when
    NoOutputSourceP.executionStarted.await();
    assertJobStatusEventually(job, JobStatus.RUNNING);
    // then
    assertTrueAllTheTime(() -> assertEmptyJobMetrics(job, false), 2);
    // when
    NoOutputSourceP.proceedLatch.countDown();
    job.join();
    assertJobStatusEventually(job, JobStatus.COMPLETED);
    // then
    assertEmptyJobMetrics(job, true);
}
Also used : Processor(com.hazelcast.jet.core.Processor) MockP(com.hazelcast.jet.core.TestProcessors.MockP) DAG(com.hazelcast.jet.core.DAG) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 64 with DAG

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

the class AsyncTransformUsingServiceP_IntegrationTest method stressTestInt.

private void stressTestInt(boolean restart) {
    /*
        This is a stress test of the cooperative emission using the DAG api. Only through DAG
        API we can configure edge queue sizes, which we use to cause more trouble for the
        cooperative emission.
         */
    // add more input to the source map
    int numItems = 10_000;
    journaledMap.putAll(IntStream.range(NUM_ITEMS, numItems).boxed().collect(toMap(i -> i, i -> i)));
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", throttle(streamMapP(journaledMap.getName(), alwaysTrue(), EventJournalMapEvent::getNewValue, START_FROM_OLDEST, eventTimePolicy(i -> (long) ((Integer) i), WatermarkPolicy.limitingLag(10), 10, 0, 0)), 5000));
    BiFunctionEx<ExecutorService, Integer, CompletableFuture<Traverser<String>>> flatMapAsyncFn = transformNotPartitionedFn(i -> traverseItems(i + "-1", i + "-2", i + "-3", i + "-4", i + "-5"));
    ProcessorSupplier processorSupplier = ordered ? AsyncTransformUsingServiceOrderedP.supplier(serviceFactory, DEFAULT_MAX_CONCURRENT_OPS, flatMapAsyncFn) : AsyncTransformUsingServiceUnorderedP.supplier(serviceFactory, DEFAULT_MAX_CONCURRENT_OPS, flatMapAsyncFn, identity());
    Vertex map = dag.newVertex("map", processorSupplier).localParallelism(2);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeListP(sinkList.getName()));
    // Use a shorter queue to not block the barrier from the source for too long due to
    // the backpressure from the slow mapper
    EdgeConfig edgeToMapperConfig = new EdgeConfig().setQueueSize(128);
    // Use a shorter queue on output from the mapper so that we experience backpressure
    // from the sink
    EdgeConfig edgeFromMapperConfig = new EdgeConfig().setQueueSize(10);
    dag.edge(between(source, map).setConfig(edgeToMapperConfig)).edge(between(map, sink).setConfig(edgeFromMapperConfig));
    Job job = instance().getJet().newJob(dag, jobConfig);
    for (int i = 0; restart && i < 5; i++) {
        assertJobStatusEventually(job, RUNNING);
        sleepMillis(100);
        job.restart();
    }
    assertResultEventually(i -> Stream.of(i + "-1", i + "-2", i + "-3", i + "-4", i + "-5"), numItems);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Traverser(com.hazelcast.jet.Traverser) ServiceFactories.sharedService(com.hazelcast.jet.pipeline.ServiceFactories.sharedService) QuickTest(com.hazelcast.test.annotation.QuickTest) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Collectors.toMap(java.util.stream.Collectors.toMap) Arrays.asList(java.util.Arrays.asList) DAG(com.hazelcast.jet.core.DAG) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) FunctionEx(com.hazelcast.function.FunctionEx) WatermarkPolicy(com.hazelcast.jet.core.WatermarkPolicy) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Collection(java.util.Collection) JobConfig(com.hazelcast.jet.config.JobConfig) START_FROM_OLDEST(com.hazelcast.jet.pipeline.JournalInitialPosition.START_FROM_OLDEST) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) Collectors.joining(java.util.stream.Collectors.joining) Sources(com.hazelcast.jet.pipeline.Sources) Stream(java.util.stream.Stream) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) IntStream(java.util.stream.IntStream) PredicateEx.alwaysTrue(com.hazelcast.function.PredicateEx.alwaysTrue) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) CompletableFuture(java.util.concurrent.CompletableFuture) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) Function(java.util.function.Function) DEFAULT_MAX_CONCURRENT_OPS(com.hazelcast.jet.pipeline.GeneralStage.DEFAULT_MAX_CONCURRENT_OPS) TestUtil.throttle(com.hazelcast.jet.core.TestUtil.throttle) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ServiceFactory(com.hazelcast.jet.pipeline.ServiceFactory) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ExecutorService(java.util.concurrent.ExecutorService) Job(com.hazelcast.jet.Job) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) IList(com.hazelcast.collection.IList) Config(com.hazelcast.config.Config) SourceProcessors.streamMapP(com.hazelcast.jet.core.processor.SourceProcessors.streamMapP) Parameter(org.junit.runners.Parameterized.Parameter) EXACTLY_ONCE(com.hazelcast.jet.config.ProcessingGuarantee.EXACTLY_ONCE) Sinks(com.hazelcast.jet.pipeline.Sinks) Traversers.traverseItems(com.hazelcast.jet.Traversers.traverseItems) Test(org.junit.Test) Vertex(com.hazelcast.jet.core.Vertex) FunctionEx.identity(com.hazelcast.function.FunctionEx.identity) EventTimePolicy.eventTimePolicy(com.hazelcast.jet.core.EventTimePolicy.eventTimePolicy) RUNNING(com.hazelcast.jet.core.JobStatus.RUNNING) TriFunction(com.hazelcast.jet.function.TriFunction) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Edge.between(com.hazelcast.jet.core.Edge.between) Vertex(com.hazelcast.jet.core.Vertex) EdgeConfig(com.hazelcast.jet.config.EdgeConfig) EventJournalMapEvent(com.hazelcast.map.EventJournalMapEvent) DAG(com.hazelcast.jet.core.DAG) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutorService(java.util.concurrent.ExecutorService) Job(com.hazelcast.jet.Job)

Example 65 with DAG

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

the class Processors_globalAggregationIntegrationTest method runTest.

private void runTest(List<Long> sourceItems, Long expectedOutput) throws Exception {
    HazelcastInstance instance = createHazelcastInstance();
    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("foo")).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("foo")).edge(between(combine, sink).isolated());
    }
    instance.getJet().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) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListSource(com.hazelcast.jet.core.TestProcessors.ListSource) AggregateOperations.summingLong(com.hazelcast.jet.aggregate.AggregateOperations.summingLong) DAG(com.hazelcast.jet.core.DAG)

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