Search in sources :

Example 86 with Vertex

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

the class HazelcastConnectorTest method when_streamMap_withProjectionToNull_then_nullsSkipped.

@Test
public void when_streamMap_withProjectionToNull_then_nullsSkipped() {
    DAG dag = new DAG();
    Vertex source = dag.newVertex("source", SourceProcessors.streamMapP(streamSourceName, mapPutEvents(), (EventJournalMapEvent<Integer, Entry<Integer, String>> entry) -> entry.getNewValue().getValue(), START_FROM_OLDEST, noEventTime()));
    Vertex sink = dag.newVertex("sink", writeListP(streamSinkName));
    dag.edge(between(source, sink));
    Job job = instance().getJet().newJob(dag);
    IMap<Integer, Entry<Integer, String>> sourceMap = instance().getMap(streamSourceName);
    range(0, ENTRY_COUNT).forEach(i -> sourceMap.put(i, entry(i, i % 2 == 0 ? null : String.valueOf(i))));
    assertTrueEventually(() -> checkContents_projectedToNull(streamSinkName));
    job.cancel();
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Entry(java.util.Map.Entry) 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 87 with Vertex

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

the class StreamEventJournalPTest method when_processorsWithNoPartitions_then_snapshotRestoreWorks.

@Test
public void when_processorsWithNoPartitions_then_snapshotRestoreWorks() {
    DAG dag = new DAG();
    Vertex vertex = dag.newVertex("src", streamMapP(map.getName(), JournalInitialPosition.START_FROM_OLDEST, noEventTime())).localParallelism(8);
    int partitionCount = instance.getPartitionService().getPartitions().size();
    assertTrue("partition count should be lower than local parallelism", vertex.getLocalParallelism() > partitionCount);
    Job job = instance.getJet().newJob(dag, new JobConfig().setProcessingGuarantee(EXACTLY_ONCE).setSnapshotIntervalMillis(200_000));
    assertJobStatusEventually(job, JobStatus.RUNNING, 25);
    job.restart();
    // Then
    // The job should be running: this test checks that state restored to NoopP, which is
    // created by the meta supplier for processor with no partitions, is ignored.
    sleepMillis(3000);
    assertJobStatusEventually(job, JobStatus.RUNNING, 10);
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) 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 88 with Vertex

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

the class BatchStageTest method addTimestamps_when_upstreamHasPreferredLocalParallelism_then_lpMatchUpstream.

@Test
public void addTimestamps_when_upstreamHasPreferredLocalParallelism_then_lpMatchUpstream() {
    // Given
    int lp = 11;
    // When
    p.readFrom(Sources.batchFromProcessor("src", ProcessorMetaSupplier.of(lp, ProcessorSupplier.of(noopP())))).addTimestamps(o -> 0L, 0).writeTo(Sinks.noop());
    DAG dag = p.toDag();
    // Then
    Vertex tsVertex = dag.getVertex("add-timestamps");
    assertEquals(lp, tsVertex.getLocalParallelism());
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) Arrays(java.util.Arrays) ServiceFactories.sharedService(com.hazelcast.jet.pipeline.ServiceFactories.sharedService) QuickTest(com.hazelcast.test.annotation.QuickTest) QuadFunction(com.hazelcast.jet.function.QuadFunction) Collections.singletonList(java.util.Collections.singletonList) BiFunctionEx(com.hazelcast.function.BiFunctionEx) Arrays.asList(java.util.Arrays.asList) DAG(com.hazelcast.jet.core.DAG) PredicateEx(com.hazelcast.function.PredicateEx) FunctionEx(com.hazelcast.function.FunctionEx) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) Collections.emptyList(java.util.Collections.emptyList) Tag(com.hazelcast.jet.datamodel.Tag) Set(java.util.Set) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) Tuple3.tuple3(com.hazelcast.jet.datamodel.Tuple3.tuple3) List(java.util.List) Stream(java.util.stream.Stream) ItemsByTag(com.hazelcast.jet.datamodel.ItemsByTag) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) IntStream(java.util.stream.IntStream) Processors(com.hazelcast.jet.core.processor.Processors) CompletableFuture(java.util.concurrent.CompletableFuture) ServiceFactories.nonSharedService(com.hazelcast.jet.pipeline.ServiceFactories.nonSharedService) Function(java.util.function.Function) JoinClause.joinMapEntries(com.hazelcast.jet.pipeline.JoinClause.joinMapEntries) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AssertionSinks.assertAnyOrder(com.hazelcast.jet.pipeline.test.AssertionSinks.assertAnyOrder) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AssertionSinks.assertOrdered(com.hazelcast.jet.pipeline.test.AssertionSinks.assertOrdered) Util.entry(com.hazelcast.jet.Util.entry) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Tuple2(com.hazelcast.jet.datamodel.Tuple2) ExecutorService(java.util.concurrent.ExecutorService) Job(com.hazelcast.jet.Job) Tuple3(com.hazelcast.jet.datamodel.Tuple3) HazelcastInstance(com.hazelcast.core.HazelcastInstance) LongStream(java.util.stream.LongStream) AbstractStage.transformOf(com.hazelcast.jet.impl.pipeline.AbstractStage.transformOf) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Traversers.traverseItems(com.hazelcast.jet.Traversers.traverseItems) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TimeUnit(java.util.concurrent.TimeUnit) Vertex(com.hazelcast.jet.core.Vertex) TestSources(com.hazelcast.jet.pipeline.test.TestSources) Collectors.toList(java.util.stream.Collectors.toList) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Functions.wholeItem(com.hazelcast.function.Functions.wholeItem) Processors.noopP(com.hazelcast.jet.core.processor.Processors.noopP) TriFunction(com.hazelcast.jet.function.TriFunction) Collections(java.util.Collections) Util(com.hazelcast.jet.Util) Tuple4.tuple4(com.hazelcast.jet.datamodel.Tuple4.tuple4) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 89 with Vertex

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

the class LightJobTest method smokeTest_dag.

@Test
public void smokeTest_dag() {
    List<Integer> items = IntStream.range(0, 1_000).boxed().collect(Collectors.toList());
    DAG dag = new DAG();
    Vertex src = dag.newVertex("src", processorFromPipelineSource(TestSources.items(items)));
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeListP("sink"));
    dag.edge(between(src, sink).distributed());
    submittingInstance().getJet().newLightJob(dag).join();
    List<Integer> result = instance().getList("sink");
    assertThat(result).containsExactlyInAnyOrderElementsOf(items);
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) DAG(com.hazelcast.jet.core.DAG) Test(org.junit.Test)

Example 90 with Vertex

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

the class WordCountTest method generateMockInput.

private void generateMockInput() {
    logger.info("Generating input");
    final DAG dag = new DAG();
    Vertex source = dag.newVertex("source", (List<Address> addrs) -> (Address addr) -> ProcessorSupplier.of(addr.equals(addrs.get(0)) ? MockInputP::new : noopP()));
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP("words"));
    dag.edge(between(source.localParallelism(1), sink.localParallelism(1)));
    instance.getJet().newJob(dag).join();
    logger.info("Input generated.");
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Address(com.hazelcast.cluster.Address) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) DAG(com.hazelcast.jet.core.DAG)

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