本文整理汇总了Java中org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.generateSequence方法的典型用法代码示例。如果您正苦于以下问题:Java StreamExecutionEnvironment.generateSequence方法的具体用法?Java StreamExecutionEnvironment.generateSequence怎么用?Java StreamExecutionEnvironment.generateSequence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flink.streaming.api.environment.StreamExecutionEnvironment
的用法示例。
在下文中一共展示了StreamExecutionEnvironment.generateSequence方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCollect
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //导入方法依赖的package包/类
@Test
public void testCollect() throws Exception {
final LocalFlinkMiniCluster cluster = new LocalFlinkMiniCluster(new Configuration(), false);
try {
cluster.start();
TestStreamEnvironment.setAsContext(cluster, 1);
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
final long n = 10;
DataStream<Long> stream = env.generateSequence(1, n);
long i = 1;
for (Iterator<Long> it = DataStreamUtils.collect(stream); it.hasNext(); ) {
long x = it.next();
assertEquals("received wrong element", i, x);
i++;
}
assertEquals("received wrong number of elements", n + 1, i);
}
finally {
TestStreamEnvironment.unsetAsContext();
cluster.stop();
}
}
示例2: testSources
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //导入方法依赖的package包/类
@Test
public void testSources() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
SourceFunction<Integer> srcFun = new SourceFunction<Integer>() {
private static final long serialVersionUID = 1L;
@Override
public void run(SourceContext<Integer> ctx) throws Exception {
}
@Override
public void cancel() {
}
};
DataStreamSource<Integer> src1 = env.addSource(srcFun);
src1.addSink(new DiscardingSink<Integer>());
assertEquals(srcFun, getFunctionFromDataSource(src1));
List<Long> list = Arrays.asList(0L, 1L, 2L);
DataStreamSource<Long> src2 = env.generateSequence(0, 2);
assertTrue(getFunctionFromDataSource(src2) instanceof StatefulSequenceSource);
DataStreamSource<Long> src3 = env.fromElements(0L, 1L, 2L);
assertTrue(getFunctionFromDataSource(src3) instanceof FromElementsFunction);
DataStreamSource<Long> src4 = env.fromCollection(list);
assertTrue(getFunctionFromDataSource(src4) instanceof FromElementsFunction);
}
示例3: testUnion
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //导入方法依赖的package包/类
@Test
public void testUnion() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
FilterFunction<Long> dummyFilter = new FilterFunction<Long>() {
@Override
public boolean filter(Long value) {
return false;
}
};
DataStream<Long> src1 = env.generateSequence(1, 10);
DataStream<Long> src2 = env.generateSequence(1, 10).slotSharingGroup("src-1");
// this should not inherit group "src-1"
src1.union(src2).filter(dummyFilter);
DataStream<Long> src3 = env.generateSequence(1, 10).slotSharingGroup("group-1");
DataStream<Long> src4 = env.generateSequence(1, 10).slotSharingGroup("group-1");
// this should inherit "group-1" now
src3.union(src4).filter(dummyFilter);
JobGraph jobGraph = env.getStreamGraph().getJobGraph();
List<JobVertex> vertices = jobGraph.getVerticesSortedTopologicallyFromSources();
// first pipeline
assertEquals(vertices.get(0).getSlotSharingGroup(), vertices.get(4).getSlotSharingGroup());
assertNotEquals(vertices.get(0).getSlotSharingGroup(), vertices.get(1).getSlotSharingGroup());
assertNotEquals(vertices.get(1).getSlotSharingGroup(), vertices.get(4).getSlotSharingGroup());
// second pipeline
assertEquals(vertices.get(2).getSlotSharingGroup(), vertices.get(3).getSlotSharingGroup());
assertEquals(vertices.get(2).getSlotSharingGroup(), vertices.get(5).getSlotSharingGroup());
assertEquals(vertices.get(3).getSlotSharingGroup(), vertices.get(5).getSlotSharingGroup());
}
示例4: testChannelSelectors
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; //导入方法依赖的package包/类
@Test
public void testChannelSelectors() {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
DataStreamSource<Long> src = env.generateSequence(0, 0);
DataStream<Long> broadcast = src.broadcast();
DataStreamSink<Long> broadcastSink = broadcast.print();
StreamPartitioner<?> broadcastPartitioner =
env.getStreamGraph().getStreamEdges(src.getId(),
broadcastSink.getTransformation().getId()).get(0).getPartitioner();
assertTrue(broadcastPartitioner instanceof BroadcastPartitioner);
DataStream<Long> shuffle = src.shuffle();
DataStreamSink<Long> shuffleSink = shuffle.print();
StreamPartitioner<?> shufflePartitioner =
env.getStreamGraph().getStreamEdges(src.getId(),
shuffleSink.getTransformation().getId()).get(0).getPartitioner();
assertTrue(shufflePartitioner instanceof ShufflePartitioner);
DataStream<Long> forward = src.forward();
DataStreamSink<Long> forwardSink = forward.print();
StreamPartitioner<?> forwardPartitioner =
env.getStreamGraph().getStreamEdges(src.getId(),
forwardSink.getTransformation().getId()).get(0).getPartitioner();
assertTrue(forwardPartitioner instanceof ForwardPartitioner);
DataStream<Long> rebalance = src.rebalance();
DataStreamSink<Long> rebalanceSink = rebalance.print();
StreamPartitioner<?> rebalancePartitioner =
env.getStreamGraph().getStreamEdges(src.getId(),
rebalanceSink.getTransformation().getId()).get(0).getPartitioner();
assertTrue(rebalancePartitioner instanceof RebalancePartitioner);
DataStream<Long> global = src.global();
DataStreamSink<Long> globalSink = global.print();
StreamPartitioner<?> globalPartitioner =
env.getStreamGraph().getStreamEdges(src.getId(),
globalSink.getTransformation().getId()).get(0).getPartitioner();
assertTrue(globalPartitioner instanceof GlobalPartitioner);
}