AHeise commented on a change in pull request #16770:
URL: https://github.com/apache/flink/pull/16770#discussion_r689131068



##########
File path: 
flink-tests/src/test/java/org/apache/flink/test/streaming/runtime/SinkITCase.java
##########
@@ -256,6 +278,95 @@ public void writerAndGlobalCommitterExecuteInBatchMode() 
throws Exception {
                 
containsInAnyOrder(EXPECTED_GLOBAL_COMMITTED_DATA_IN_BATCH_MODE.toArray()));
     }
 
+    @Test
+    public void testMetrics() throws Exception {
+        StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+        int numSplits = Math.max(1, env.getParallelism() - 2);
+
+        int numRecordsPerSplit = 10;
+
+        // make sure all parallel instances have processed the same amount of 
records before
+        // validating metrics
+        SharedReference<CyclicBarrier> beforeBarrier =
+                sharedObjects.add(new CyclicBarrier(numSplits + 1));
+        SharedReference<CyclicBarrier> afterBarrier =
+                sharedObjects.add(new CyclicBarrier(numSplits + 1));
+        int stopAtRecord1 = 4;
+        int stopAtRecord2 = numRecordsPerSplit - 1;
+
+        env.fromSequence(0, numSplits - 1)
+                .<Long>flatMap(
+                        (split, collector) ->
+                                LongStream.range(0, 
numRecordsPerSplit).forEach(collector::collect))
+                .returns(BasicTypeInfo.LONG_TYPE_INFO)
+                .map(
+                        i -> {
+                            if (i % numRecordsPerSplit == stopAtRecord1
+                                    || i % numRecordsPerSplit == 
stopAtRecord2) {
+                                beforeBarrier.get().await();
+                                afterBarrier.get().await();
+                            }
+                            return i;
+                        })
+                .sinkTo(TestSink.newBuilder().setWriter(new 
MetricWriter()).build())
+                .name("TestSink");
+        JobClient jobClient = env.executeAsync();
+
+        beforeBarrier.get().await();
+        assertSinkMetrics(stopAtRecord1, env.getParallelism(), numSplits);
+        afterBarrier.get().await();
+
+        beforeBarrier.get().await();
+        assertSinkMetrics(stopAtRecord2, env.getParallelism(), numSplits);
+        afterBarrier.get().await();
+
+        jobClient.getJobExecutionResult().get();
+    }
+
+    private void assertSinkMetrics(
+            long processedRecordsPerSubtask, int parallelism, int numSplits) {
+        List<OperatorMetricGroup> groups =
+                
inMemoryReporter.getReporter().findOperatorMetricGroups("TestSink");
+        //        assertThat(groups, hasSize(parallelism));

Review comment:
       No but I re-enabled it.




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