use of com.hazelcast.function.FunctionEx 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());
}
use of com.hazelcast.function.FunctionEx in project hazelcast by hazelcast.
the class RebalanceBatchStageTest method when_peekAndRebalanceByKeyAndMap_then_dagEdgePartitionedDistributed.
@Test
public void when_peekAndRebalanceByKeyAndMap_then_dagEdgePartitionedDistributed() {
// Given
List<Integer> input = sequence(itemCount);
BatchStage<Integer> srcStage = batchStageFromList(input);
FunctionEx<Integer, String> formatFn = i -> String.format("%04d-string", i);
// When
BatchStage<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("Rebalancing by key, the edge must be partitioned", srcToMap.getPartitioner());
execute();
assertEquals(streamToString(input.stream(), formatFn), streamToString(sinkStreamOf(String.class), identity()));
}
use of com.hazelcast.function.FunctionEx in project hazelcast by hazelcast.
the class RebalanceBatchStageTest method when_rebalanceByKeyAndMap_then_dagEdgePartitionedDistributed.
@Test
public void when_rebalanceByKeyAndMap_then_dagEdgePartitionedDistributed() {
// Given
List<Integer> input = sequence(itemCount);
BatchStage<Integer> srcStage = batchStageFromList(input);
FunctionEx<Integer, String> formatFn = i -> String.format("%04d-string", i);
// When
BatchStage<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("Rebalancing by key, the edge must be partitioned", srcToMap.getPartitioner());
execute();
assertEquals(streamToString(input.stream(), formatFn), streamToString(sinkStreamOf(String.class), identity()));
}
use of com.hazelcast.function.FunctionEx in project hazelcast by hazelcast.
the class RebalanceBatchStageTest method when_rebalanceAndMap_then_dagEdgeDistributed.
@Test
public void when_rebalanceAndMap_then_dagEdgeDistributed() {
// Given
List<Integer> input = sequence(itemCount);
BatchStage<Integer> srcStage = batchStageFromList(input);
FunctionEx<Integer, String> formatFn = i -> String.format("%04d-string", i);
// When
BatchStage<String> mapped = srcStage.rebalance().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());
assertNull("Didn't rebalance by key, the edge must not be partitioned", srcToMap.getPartitioner());
execute();
assertEquals(streamToString(input.stream(), formatFn), streamToString(sinkStreamOf(String.class), identity()));
}
use of com.hazelcast.function.FunctionEx in project hazelcast by hazelcast.
the class OrderedBatchParallelismTest method applyTransformAndGetDag.
private DAG applyTransformAndGetDag(FunctionEx<BatchStage<Long>, BatchStage<Long>> transform) {
PipelineImpl p = (PipelineImpl) Pipeline.create().setPreserveOrder(true);
BatchStage<Long> source = p.readFrom(TestSources.items(1L)).setLocalParallelism(UPSTREAM_PARALLELISM);
BatchStage<Long> applied = source.apply(transform);
applied.mapStateful(LongAccumulator::new, (s, x) -> x).writeTo(Sinks.noop());
return p.toDag(PIPELINE_CTX);
}
Aggregations