pnowojski commented on a change in pull request #6367: [FLINK-9850] Add a
string to the print method to identify output for DataStream
URL: https://github.com/apache/flink/pull/6367#discussion_r210240875
##########
File path:
flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/PrintSinkFunctionTest.java
##########
@@ -103,4 +102,41 @@ public void testPrintSinkWithPrefix() throws Exception {
assertEquals("2> hello world!" + line,
arrayOutputStream.toString());
printSink.close();
}
+
+ @Test
+ public void testPrintSinkWithIdentifierAndPrefix() throws Exception {
+ PrintSinkFunction<String> printSink = new
PrintSinkFunction<>("mySink", false);
+ printSink.setRuntimeContext(new
MockStreamingRuntimeContext(false, 2, 1));
+ printSink.open(new Configuration());
+
+ printSink.invoke("hello world!",
SinkContextUtil.forTimestamp(0));
+
+ assertEquals("Print to System.out", printSink.toString());
+ assertEquals("mySink:2> hello world!" + line,
arrayOutputStream.toString());
+
+ printSink = new PrintSinkFunction<>("mySink", true);
+ assertEquals("Print to System.err", printSink.toString());
+ assertEquals("mySink:2> hello world!" + line,
arrayOutputStream.toString());
+
+ printSink.close();
+ }
+
+ @Test
+ public void testPrintSinkWithIdentifierButNoPrefix() throws Exception {
+ PrintSinkFunction<String> printSink = new
PrintSinkFunction<>("mySink", false);
+ printSink.setRuntimeContext(new MockRuntimeContext(false, 1,
0));
+ printSink.open(new Configuration());
+
+ printSink.invoke("hello world!",
SinkContextUtil.forTimestamp(0));
+
+ assertEquals("Print to System.out", printSink.toString());
+ assertEquals("mySink> hello world!" + line,
arrayOutputStream.toString());
+
+ printSink = new PrintSinkFunction<>("mySink", true);
+ assertEquals("Print to System.err", printSink.toString());
+ assertEquals("mySink> hello world!" + line,
arrayOutputStream.toString());
Review comment:
ditto regarding testing stderr
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services