NicoK commented on a change in pull request #31:
URL: https://github.com/apache/flink-training/pull/31#discussion_r695684798



##########
File path: 
common/src/test/java/org/apache/flink/training/exercises/testing/TestSink.java
##########
@@ -0,0 +1,26 @@
+package org.apache.flink.training.exercises.testing;
+
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class TestSink<OUT> implements SinkFunction<OUT> {
+
+    // must be static
+    public static final List VALUES = Collections.synchronizedList(new 
ArrayList<>());
+
+    @Override
+    public void invoke(OUT value, Context context) {
+        VALUES.add(value);
+    }
+
+    public Iterable<OUT> results() {
+        return VALUES;
+    }
+
+    public void reset() {
+        VALUES.clear();
+    }
+}

Review comment:
       I'm not that deep into the accumulator topic, but reading up on them in 
the 
[docs](https://ci.apache.org/projects/flink/flink-docs-release-1.13/docs/dev/datastream/user_defined_functions/#accumulators--counters)
 and code, it looks like they are even able to synchronise when used from 
different operator functions!
   
   Seems safer than a static variable and can be used in parallel tests.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to