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_r209260792
 
 

 ##########
 File path: 
flink-streaming-java/src/test/java/org/apache/flink/streaming/api/functions/PrintSinkFunctionTest.java
 ##########
 @@ -117,6 +117,65 @@ public void testPrintSinkWithPrefix() throws Exception {
                stream.close();
        }
 
+       @Test
+       public void testPrintSinkWithIdentifierAndPrefix() throws Exception {
+               ByteArrayOutputStream baos = new ByteArrayOutputStream();
+               PrintStream stream = new PrintStream(baos);
+               System.setOut(stream);
+
+               final StreamingRuntimeContext ctx = 
Mockito.mock(StreamingRuntimeContext.class);
+               Mockito.when(ctx.getNumberOfParallelSubtasks()).thenReturn(2);
+               Mockito.when(ctx.getIndexOfThisSubtask()).thenReturn(1);
+
+               PrintSinkFunction<String> printSink = new 
PrintSinkFunction<>(false, "mySink");
+               printSink.setRuntimeContext(ctx);
+               try {
+                       printSink.open(new Configuration());
+               } catch (Exception e) {
+                       Assert.fail();
+               }
+               printSink.invoke("hello world!", 
SinkContextUtil.forTimestamp(0));
+
+               assertEquals("Print to System.out", printSink.toString());
+               assertEquals("mySink:2> hello world!" + line, baos.toString());
+
+               printSink.setTargetToStandardErr();
+               assertEquals("Print to System.err", printSink.toString());
+               assertEquals("mySink:2> hello world!" + line, baos.toString());
+
+               printSink.close();
+               stream.close();
+       }
+
+       @Test
+       public void testPrintSinkWithIdentifierButNoPrefix() throws Exception {
+               ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
 Review comment:
   There is quite a lot of code duplication in those tests and they were 
unnecessarily using mockito instead of proper mock. Also there was even a bug 
in `testPrintSinkStdErr`. I have fixed those issues in a hotifx: 
https://github.com/apache/flink/pull/6538
   
   I would the hotifx to be merged before this PR and please adapt/rewrite your 
test in similar fashion as I did in my hotfix.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to