You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/07/30 07:32:58 UTC

[GitHub] [flink] pnowojski commented on a change in pull request #9221: [FLINK-13376][datastream] ContinuousFileReaderOperator should respect…

pnowojski commented on a change in pull request #9221: [FLINK-13376][datastream] ContinuousFileReaderOperator should respect…
URL: https://github.com/apache/flink/pull/9221#discussion_r308568937
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/test/streaming/api/ContinuousFileReaderOperatorITCase.java
 ##########
 @@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.test.streaming.api;
+
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+import org.apache.flink.streaming.api.operators.AbstractStreamOperator;
+import org.apache.flink.streaming.api.operators.BoundedOneInput;
+import org.apache.flink.streaming.api.operators.ChainingStrategy;
+import org.apache.flink.streaming.api.operators.OneInputStreamOperator;
+import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
+import org.apache.flink.test.util.AbstractTestBase;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.io.PrintWriter;
+
+import static org.apache.flink.api.common.typeinfo.BasicTypeInfo.STRING_TYPE_INFO;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * Integration tests for {@link org.apache.flink.streaming.api.functions.source.ContinuousFileReaderOperator}.
+ */
+public class ContinuousFileReaderOperatorITCase extends AbstractTestBase {
+
+	@Test
+	public void testEndInput() throws Exception {
+		final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+		env.setParallelism(1);
+		final File sourceFile = TEMPORARY_FOLDER.newFile();
+		try (PrintWriter printWriter = new PrintWriter(sourceFile)) {
+			for (int i = 0; i < 10000; i++) {
+				printWriter.println(i);
+			}
+		}
+
+		DataStreamSource<String> source = env.readTextFile(sourceFile.getAbsolutePath());
+
+		// check the endInput is invoked at the right time
+		TestBoundedOneInputStreamOperator checkingOperator = new TestBoundedOneInputStreamOperator();
+		DataStream<String> endInputChecking = source.transform("EndInputChecking", STRING_TYPE_INFO, checkingOperator);
+
+		endInputChecking.addSink(new NoOpSink());
+
+		env.execute("ContinuousFileReaderOperatorITCase.testEndInput");
+	}
+
+	private static class TestBoundedOneInputStreamOperator extends AbstractStreamOperator<String>
+		implements OneInputStreamOperator<String, String>, BoundedOneInput {
+
+		private boolean isEnded = false;
+
+		TestBoundedOneInputStreamOperator() {
+			// this operator must be chained with ContinuousFileReaderOperator
+			// that way, this end input would be triggered after ContinuousFileReaderOperator
+			chainingStrategy = ChainingStrategy.ALWAYS;
+		}
+
+		@Override
+		public void endInput() throws Exception {
+			isEnded = true;
 
 Review comment:
   nit: I would add also one more assertion here in the `endInput`, to check that expected number of elements was processed before  `endInput()` was invoked. (passing expected number of elements via the `TestBoundedOneInputStreamOperator` constructor).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services