Github user rmetzger commented on a diff in the pull request:
https://github.com/apache/flink/pull/519#discussion_r26938775
--- Diff:
flink-staging/flink-streaming/flink-streaming-examples/src/test/java/org/apache/flink/streaming/examples/test/socket/SocketTextStreamWordCountITCase.java
---
@@ -0,0 +1,93 @@
+/*
+ * 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.streaming.examples.test.socket;
+
+import
org.apache.flink.streaming.examples.socket.SocketTextStreamWordCount;
+import
org.apache.flink.streaming.examples.socket.util.SocketTextStreamWordCountData;
+import org.apache.flink.streaming.util.StreamingProgramTestBase;
+
+import java.io.PrintWriter;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class SocketTextStreamWordCountITCase extends
StreamingProgramTestBase {
+
+ private static final String HOST = "localhost";
+ private static final String PORT = "9999";
+ protected String resultPath;
+
+ private ServerSocket temporarySocket;
+
+ @Override
+ protected void preSubmit() throws Exception {
+ temporarySocket = createSocket(HOST, Integer.valueOf(PORT),
SocketTextStreamWordCountData.SOCKET_TEXT);
+ resultPath = getTempDirPath("result");
+ }
+
+ @Override
+ protected void postSubmit() throws Exception {
+
compareResultsByLinesInMemory(SocketTextStreamWordCountData.STREAMING_COUNTS_AS_TUPLES,
resultPath);
+ temporarySocket.close();
+ }
+
+ @Override
+ protected void testProgram() throws Exception {
+ SocketTextStreamWordCount.main(new String[]{HOST, PORT,
resultPath});
+ }
+
+ public ServerSocket createSocket(String host, int port, String
contents) throws Exception {
+ ServerSocket serverSocket = new ServerSocket(port);
+ ServerThread st = new ServerThread(serverSocket, contents);
+ st.start();
+ return serverSocket;
+ }
+
+ private static class ServerThread extends Thread {
+
+ private ServerSocket serverSocket;
+ private String contents;
+ private Thread t;
+
+ public ServerThread(ServerSocket serverSocket, String contents)
{
+ this.serverSocket = serverSocket;
+ this.contents = contents;
+ t = new Thread(this);
+ }
+
+ public void waitForAccept() throws Exception {
+ Socket socket = serverSocket.accept();
+ PrintWriter writer = new
PrintWriter(socket.getOutputStream(), true);
+ writer.println(contents);
+ writer.close();
+ socket.close();
+ }
+
+ public void run() {
+ try {
+ waitForAccept();
+ } catch (Exception e) {
+ e.printStackTrace();
--- End diff --
I would fail the test in case of an exception.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---