Search in sources :

Example 1 with Util

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

the class ReadFilesPTest method buildDag.

private DAG buildDag(String glob) {
    if (glob == null) {
        glob = "*";
    }
    DAG dag = new DAG();
    Vertex reader = dag.newVertex("reader", readFilesP(directory.getPath(), StandardCharsets.UTF_8, glob, Util::entry)).localParallelism(1);
    Vertex writer = dag.newVertex("writer", writeListP(list.getName())).localParallelism(1);
    dag.edge(between(reader, writer));
    return dag;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Util(com.hazelcast.jet.Util) DAG(com.hazelcast.jet.core.DAG)

Example 2 with Util

use of com.hazelcast.jet.Util in project hazelcast by hazelcast.

the class StreamFilesP_integrationTest method buildDag.

private DAG buildDag() {
    DAG dag = new DAG();
    Vertex reader = dag.newVertex("reader", streamFilesP(directory.getPath(), UTF_8, "*", false, Util::entry)).localParallelism(1);
    Vertex writer = dag.newVertex("writer", writeListP(list.getName())).localParallelism(1);
    dag.edge(between(reader, writer));
    return dag;
}
Also used : Vertex(com.hazelcast.jet.core.Vertex) Util(com.hazelcast.jet.Util) DAG(com.hazelcast.jet.core.DAG)

Example 3 with Util

use of com.hazelcast.jet.Util in project hazelcast by hazelcast.

the class RebalanceBatchStageTest method when_hashJoinRebalanceEnrichingStage_then_noEffect.

@Test
public void when_hashJoinRebalanceEnrichingStage_then_noEffect() {
    // Given
    List<Integer> input = sequence(itemCount);
    String prefix = "value-";
    BatchStage<Integer> mainStage = batchStageFromList(input);
    BatchStage<Entry<Integer, String>> enrichingStageRebalanced = batchStageFromList(input).map(i -> entry(i, prefix + i)).rebalance();
    // When
    BatchStage<Entry<Integer, String>> joined = mainStage.hashJoin(enrichingStageRebalanced, joinMapEntries(wholeItem()), Util::entry);
    // Then
    joined.writeTo(sink);
    DAG dag = p.toDag();
    Edge mapToJoin = dag.getInboundEdges("2-way hash-join-collector1").get(0);
    assertTrue("Edge into a hash-join collector vertex must be distributed", mapToJoin.isDistributed());
    assertNull("Didn't rebalance by key, the edge must not be partitioned", mapToJoin.getPartitioner());
    Edge stage0ToJoin = dag.getInboundEdges("2-way hash-join-joiner").get(0);
    assertFalse("Didn't rebalance this stage, why is its edge distributed?", stage0ToJoin.isDistributed());
    assertNull("Didn't rebalance by key, the edge must not be partitioned", stage0ToJoin.getPartitioner());
    execute();
    Function<Entry<Integer, String>, String> formatFn = e -> String.format("(%04d, %s)", e.getKey(), e.getValue());
    assertEquals(streamToString(input.stream().map(i -> tuple2(i, prefix + i)), formatFn), streamToString(sinkStreamOfEntry(), formatFn));
}
Also used : Spliterators.spliteratorUnknownSize(java.util.Spliterators.spliteratorUnknownSize) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AggregateOperations.coAggregateOperationBuilder(com.hazelcast.jet.aggregate.AggregateOperations.coAggregateOperationBuilder) Collections.singletonList(java.util.Collections.singletonList) AggregateOperation(com.hazelcast.jet.aggregate.AggregateOperation) Map(java.util.Map) DAG(com.hazelcast.jet.core.DAG) Collector(java.util.stream.Collector) FunctionEx(com.hazelcast.function.FunctionEx) Tag(com.hazelcast.jet.datamodel.Tag) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) Category(org.junit.experimental.categories.Category) Tuple3.tuple3(com.hazelcast.jet.datamodel.Tuple3.tuple3) List(java.util.List) Stream(java.util.stream.Stream) StreamSupport.stream(java.util.stream.StreamSupport.stream) ItemsByTag(com.hazelcast.jet.datamodel.ItemsByTag) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) IntStream(java.util.stream.IntStream) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Function(java.util.function.Function) FORMAT_FN_3(com.hazelcast.jet.pipeline.BatchAggregateTest.FORMAT_FN_3) JoinClause.joinMapEntries(com.hazelcast.jet.pipeline.JoinClause.joinMapEntries) ArrayList(java.util.ArrayList) JetException(com.hazelcast.jet.JetException) JetAssert.assertFalse(com.hazelcast.jet.core.test.JetAssert.assertFalse) FORMAT_FN(com.hazelcast.jet.pipeline.BatchAggregateTest.FORMAT_FN) AssertionSinks.assertAnyOrder(com.hazelcast.jet.pipeline.test.AssertionSinks.assertAnyOrder) FORMAT_FN_2(com.hazelcast.jet.pipeline.BatchAggregateTest.FORMAT_FN_2) Collectors.summingLong(java.util.stream.Collectors.summingLong) Util.entry(com.hazelcast.jet.Util.entry) Edge(com.hazelcast.jet.core.Edge) Nonnull(javax.annotation.Nonnull) Tuple2(com.hazelcast.jet.datamodel.Tuple2) Tuple3(com.hazelcast.jet.datamodel.Tuple3) IList(com.hazelcast.collection.IList) Iterator(java.util.Iterator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AggregateOperation1(com.hazelcast.jet.aggregate.AggregateOperation1) CoAggregateOperationBuilder(com.hazelcast.jet.aggregate.CoAggregateOperationBuilder) TestSources(com.hazelcast.jet.pipeline.test.TestSources) Collectors.toList(java.util.stream.Collectors.toList) Tuple2.tuple2(com.hazelcast.jet.datamodel.Tuple2.tuple2) Assert.assertNull(org.junit.Assert.assertNull) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Functions.wholeItem(com.hazelcast.function.Functions.wholeItem) Util(com.hazelcast.jet.Util) Assert.assertEquals(org.junit.Assert.assertEquals) Entry(java.util.Map.Entry) Util(com.hazelcast.jet.Util) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with Util

use of com.hazelcast.jet.Util in project hazelcast by hazelcast.

the class StreamFilesPTest method when_metaSupplier_then_returnsCorrectProcessors.

@Test
public void when_metaSupplier_then_returnsCorrectProcessors() throws Exception {
    ProcessorMetaSupplier metaSupplier = streamFilesP(workDir.getAbsolutePath(), UTF_8, "*", false, Util::entry);
    Address a = new Address();
    ProcessorSupplier supplier = metaSupplier.get(singletonList(a)).apply(a);
    supplier.init(new TestProcessorContext());
    assertEquals(1, supplier.get(1).size());
    supplier.close(null);
}
Also used : Address(com.hazelcast.cluster.Address) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) IOUtil(com.hazelcast.internal.nio.IOUtil) Util(com.hazelcast.jet.Util) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with Util

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

the class StreamFilesPTest method when_metaSupplier_then_returnsCorrectProcessors.

@Test
public void when_metaSupplier_then_returnsCorrectProcessors() {
    ProcessorMetaSupplier metaSupplier = streamFilesP(workDir.getAbsolutePath(), UTF_8, "*", Util::entry);
    Address a = new Address();
    ProcessorSupplier supplier = metaSupplier.get(singletonList(a)).apply(a);
    supplier.init(new TestProcessorContext());
    assertEquals(1, supplier.get(1).size());
    supplier.close(null);
}
Also used : Address(com.hazelcast.nio.Address) TestProcessorContext(com.hazelcast.jet.core.test.TestProcessorContext) IOUtil(com.hazelcast.nio.IOUtil) Util(com.hazelcast.jet.Util) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test)

Aggregations

Util (com.hazelcast.jet.Util)9 DAG (com.hazelcast.jet.core.DAG)6 Vertex (com.hazelcast.jet.core.Vertex)5 Test (org.junit.Test)4 Util.entry (com.hazelcast.jet.Util.entry)3 ProcessorMetaSupplier (com.hazelcast.jet.core.ProcessorMetaSupplier)3 ProcessorSupplier (com.hazelcast.jet.core.ProcessorSupplier)3 ArrayList (java.util.ArrayList)3 Collections.singletonList (java.util.Collections.singletonList)3 List (java.util.List)3 FunctionEx (com.hazelcast.function.FunctionEx)2 Functions.wholeItem (com.hazelcast.function.Functions.wholeItem)2 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)2 AggregateOperations.counting (com.hazelcast.jet.aggregate.AggregateOperations.counting)2 Processors (com.hazelcast.jet.core.processor.Processors)2 TestProcessorContext (com.hazelcast.jet.core.test.TestProcessorContext)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Arrays (java.util.Arrays)2 Entry (java.util.Map.Entry)2