Search in sources :

Example 11 with Edge

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

the class RebalanceStreamStageTest method when_peekAndRebalanceByKeyAndMap_then_dagEdgePartitionedDistributed.

@Test
public void when_peekAndRebalanceByKeyAndMap_then_dagEdgePartitionedDistributed() {
    // Given
    List<Integer> input = sequence(itemCount);
    StreamStage<Integer> srcStage = streamStageFromList(input);
    FunctionEx<Integer, String> formatFn = i -> String.format("%04d-string", i);
    // When
    StreamStage<String> mapped = srcStage.peek().rebalance(i -> i).map(formatFn);
    // Then
    mapped.writeTo(sink);
    DAG dag = p.toDag();
    Edge srcToMap = dag.getInboundEdges("map").get(0);
    assertTrue("Rebalancing should make the edge distributed", srcToMap.isDistributed());
    assertNotNull("Rebalanced by key, the edge must be partitioned", srcToMap.getPartitioner());
}
Also used : FunctionEx(com.hazelcast.function.FunctionEx) KeyedWindowResult(com.hazelcast.jet.datamodel.KeyedWindowResult) Assert.assertNotNull(org.junit.Assert.assertNotNull) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AggregateOperation1(com.hazelcast.jet.aggregate.AggregateOperation1) JetException(com.hazelcast.jet.JetException) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) WindowDefinition.tumbling(com.hazelcast.jet.pipeline.WindowDefinition.tumbling) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Function.identity(java.util.function.Function.identity) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Assert.assertEquals(org.junit.Assert.assertEquals) WindowResult(com.hazelcast.jet.datamodel.WindowResult) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Test(org.junit.Test)

Example 12 with Edge

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

the class RebalanceStreamStageTest method when_rebalanceByKeyAndMap_then_dagEdgePartitionedDistributed.

@Test
public void when_rebalanceByKeyAndMap_then_dagEdgePartitionedDistributed() {
    // Given
    List<Integer> input = sequence(itemCount);
    StreamStage<Integer> srcStage = streamStageFromList(input);
    FunctionEx<Integer, String> formatFn = i -> String.format("%04d-string", i);
    // When
    StreamStage<String> mapped = srcStage.rebalance(i -> i).map(formatFn);
    // Then
    mapped.writeTo(sink);
    DAG dag = p.toDag();
    Edge srcToMap = dag.getInboundEdges("map").get(0);
    assertTrue("Rebalancing should make the edge distributed", srcToMap.isDistributed());
    assertNotNull("Rebalanced by key, the edge must be partitioned", srcToMap.getPartitioner());
}
Also used : FunctionEx(com.hazelcast.function.FunctionEx) KeyedWindowResult(com.hazelcast.jet.datamodel.KeyedWindowResult) Assert.assertNotNull(org.junit.Assert.assertNotNull) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AggregateOperation1(com.hazelcast.jet.aggregate.AggregateOperation1) JetException(com.hazelcast.jet.JetException) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) WindowDefinition.tumbling(com.hazelcast.jet.pipeline.WindowDefinition.tumbling) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Function.identity(java.util.function.Function.identity) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Assert.assertEquals(org.junit.Assert.assertEquals) WindowResult(com.hazelcast.jet.datamodel.WindowResult) DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge) Test(org.junit.Test)

Example 13 with Edge

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

the class RebalanceBatchStageTest method assertSingleStageAggregation.

private void assertSingleStageAggregation() {
    DAG dag = p.toDag();
    try {
        Edge srcToAggregate = dag.getOutboundEdges("items").get(0);
        assertTrue("Outbound edge after rebalancing must be distributed", srcToAggregate.isDistributed());
        Edge aggregateToSink = dag.getOutboundEdges(srcToAggregate.getDestName()).get(0);
        List<Edge> sinkOutbound = dag.getOutboundEdges(aggregateToSink.getDestName());
        assertEquals("Aggregation after rebalancing must be single-stage", 0, sinkOutbound.size());
    } catch (AssertionError e) {
        System.err.println(dag.toDotString());
        throw e;
    }
}
Also used : DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge)

Example 14 with Edge

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

the class RebalanceBatchStageTest method assertTwoStageGlobalAggregation.

private void assertTwoStageGlobalAggregation(int i) {
    DAG dag = p.toDag();
    try {
        Edge srcToAggregate = dag.getOutboundEdges("items" + (i == 1 ? "" : "-" + i)).get(0);
        assertNull("Rebalanced edge to global aggregation must be unicast", srcToAggregate.getPartitioner());
        assertTrue("Outbound edge after rebalancing must be distributed", srcToAggregate.isDistributed());
        String accumulatingVertexName = srcToAggregate.getDestName();
        String aggregatePrepare = "aggregate-prepare";
        assertEquals("Aggregation must be two-stage", aggregatePrepare, accumulatingVertexName.substring(accumulatingVertexName.length() - aggregatePrepare.length()));
        Edge internalAggregationEdge = dag.getOutboundEdges(accumulatingVertexName).get(0);
        assertTrue("Internal aggregation edge must be distributed", internalAggregationEdge.isDistributed());
        assertNotNull("Internal aggregation edge must be partitioned", internalAggregationEdge.getPartitioner());
    } catch (AssertionError e) {
        System.err.println(dag.toDotString());
        throw e;
    }
}
Also used : DAG(com.hazelcast.jet.core.DAG) Edge(com.hazelcast.jet.core.Edge)

Example 15 with Edge

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

the class RebalanceBatchStageTest method when_rebalanceByKeyAndAggregate_then_distributedPartitionedEdgeAndTwoStageAggregation.

@Test
public void when_rebalanceByKeyAndAggregate_then_distributedPartitionedEdgeAndTwoStageAggregation() {
    List<Integer> input = sequence(itemCount);
    BatchStage<Integer> srcStage = batchStageFromList(input);
    // When
    BatchStage<Long> aggregated = srcStage.rebalance(i -> 2 * i).aggregate(SUMMING);
    // Then
    aggregated.writeTo(sink);
    DAG dag = p.toDag();
    try {
        Edge srcToAggregate = dag.getOutboundEdges("items").get(0);
        assertNotNull("Rebalanced edge to grouped aggregation must be partitioned", srcToAggregate.getPartitioner());
        assertTrue("Outbound edge after rebalancing must be distributed", srcToAggregate.isDistributed());
        String accumulatingVertexName = srcToAggregate.getDestName();
        assertEquals("Aggregation must be two-stage", "aggregate-prepare", accumulatingVertexName);
        Edge internalAggregationEdge = dag.getOutboundEdges(accumulatingVertexName).get(0);
        assertTrue("Internal aggregation edge must be distributed", internalAggregationEdge.isDistributed());
        assertNotNull("Internal aggregation edge must be partitioned", internalAggregationEdge.getPartitioner());
    } catch (AssertionError e) {
        System.err.println(dag.toDotString());
        throw e;
    }
    execute();
    assertEquals(singletonList(input.stream().mapToLong(i -> i).sum()), new ArrayList<>(sinkList));
}
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) Collectors.summingLong(java.util.stream.Collectors.summingLong) 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)

Aggregations

Edge (com.hazelcast.jet.core.Edge)39 DAG (com.hazelcast.jet.core.DAG)22 FunctionEx (com.hazelcast.function.FunctionEx)16 List (java.util.List)16 Test (org.junit.Test)16 JetException (com.hazelcast.jet.JetException)12 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)12 AggregateOperation1 (com.hazelcast.jet.aggregate.AggregateOperation1)12 AggregateOperations (com.hazelcast.jet.aggregate.AggregateOperations)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)12 QuickTest (com.hazelcast.test.annotation.QuickTest)12 AggregateOperation (com.hazelcast.jet.aggregate.AggregateOperation)11 Collections.singletonList (java.util.Collections.singletonList)11 Function (java.util.function.Function)11 Function.identity (java.util.function.Function.identity)10 Assert.assertEquals (org.junit.Assert.assertEquals)10 Assert.assertNotNull (org.junit.Assert.assertNotNull)10 Assert.assertNull (org.junit.Assert.assertNull)10 Assert.assertTrue (org.junit.Assert.assertTrue)10 ItemsByTag (com.hazelcast.jet.datamodel.ItemsByTag)9