use of org.apache.flink.streaming.api.functions.source.FromElementsFunction in project flink by apache.
the class SourceStreamTaskTest method testClosingAllOperatorsOnChainProperly.
@Test
public void testClosingAllOperatorsOnChainProperly() throws Exception {
final StreamTaskTestHarness<String> testHarness = new StreamTaskTestHarness<>(SourceStreamTask::new, STRING_TYPE_INFO);
testHarness.setupOperatorChain(new OperatorID(), new OutputRecordInCloseTestSource<>("Source0", new FromElementsFunction<>(StringSerializer.INSTANCE, "Hello"))).chain(new OperatorID(), new TestBoundedOneInputStreamOperator("Operator1"), STRING_TYPE_INFO.createSerializer(new ExecutionConfig())).finish();
StreamConfig streamConfig = testHarness.getStreamConfig();
streamConfig.setTimeCharacteristic(TimeCharacteristic.ProcessingTime);
testHarness.invoke();
testHarness.waitForTaskCompletion();
ArrayList<Object> expected = new ArrayList<>();
Collections.addAll(expected, new StreamRecord<>("Hello"), new StreamRecord<>("[Source0]: End of input"), Watermark.MAX_WATERMARK, new StreamRecord<>("[Source0]: Finish"), new StreamRecord<>("[Operator1]: End of input"), new StreamRecord<>("[Operator1]: Finish"));
final Object[] output = testHarness.getOutput().toArray();
assertArrayEquals("Output was not correct.", expected.toArray(), output);
}
use of org.apache.flink.streaming.api.functions.source.FromElementsFunction in project flink by apache.
the class FromElementsFunctionTest method testSetOutputTypeWithSameSerializer.
@Test
public void testSetOutputTypeWithSameSerializer() throws Exception {
FromElementsFunction<String> source = new FromElementsFunction<>(BasicTypeInfo.STRING_TYPE_INFO.createSerializer(new ExecutionConfig()), STRING_LIST_DATA);
TypeSerializer<String> existingSerializer = source.getSerializer();
source.setOutputType(BasicTypeInfo.STRING_TYPE_INFO, new ExecutionConfig());
TypeSerializer<String> newSerializer = source.getSerializer();
assertEquals(existingSerializer, newSerializer);
List<String> result = runSource(source);
assertEquals(STRING_LIST_DATA, result);
}
use of org.apache.flink.streaming.api.functions.source.FromElementsFunction in project flink by apache.
the class StreamExecutionEnvironmentTest method testSources.
@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);
}
use of org.apache.flink.streaming.api.functions.source.FromElementsFunction in project flink by apache.
the class FromElementsFunctionTest method testNonJavaSerializableTypeWithSetOutputType.
@Test
public void testNonJavaSerializableTypeWithSetOutputType() throws Exception {
MyPojo[] data = { new MyPojo(1, 2), new MyPojo(3, 4), new MyPojo(5, 6) };
FromElementsFunction<MyPojo> source = new FromElementsFunction<>(data);
source.setOutputType(TypeExtractor.getForClass(MyPojo.class), new ExecutionConfig());
List<MyPojo> result = runSource(source);
assertEquals(Arrays.asList(data), result);
}
use of org.apache.flink.streaming.api.functions.source.FromElementsFunction in project flink by apache.
the class FromElementsFunctionTest method testSetOutputTypeWithIncompatibleType.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testSetOutputTypeWithIncompatibleType() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("not all subclasses of java.lang.Integer");
FromElementsFunction<String> source = new FromElementsFunction<>(STRING_LIST_DATA);
source.setOutputType((TypeInformation) BasicTypeInfo.INT_TYPE_INFO, new ExecutionConfig());
}
Aggregations