weiqingy commented on code in PR #30044:
URL: https://github.com/apache/flink/pull/30044#discussion_r4650878958


##########
flink-table/flink-table-runtime/src/test/java/org/apache/flink/table/runtime/operators/metrics/UdfMetricsTest.java:
##########
@@ -134,6 +139,45 @@ void metricsAreIndependentPerUdf() {
         assertThat(secondCounter.getCount()).isZero();
     }
 
+    @Test
+    void restartedOperatorGetsNewHandle() {
+        MetricGroup firstAttempt = 
metricListener.getMetricGroup().addGroup("operator");
+        UdfMetrics first = UdfMetrics.register(firstAttempt, "myUdf", 1);
+        ((AbstractMetricGroup<?>) firstAttempt).close();
+
+        // Same scope as the closed group, but a new group instance, as for a 
restarted task.
+        MetricGroup secondAttempt = 
metricListener.getMetricGroup().addGroup("operator");
+        UdfMetrics second = UdfMetrics.register(secondAttempt, "myUdf", 1);
+        second.update(10L);
+
+        assertThat(second).isNotSameAs(first);
+        assertThat(
+                        metricListener
+                                .getHistogram("operator", "udf", "myUdf", 
"udfProcessingTime")
+                                .get()
+                                .getCount())
+                .isEqualTo(1L);
+    }
+
+    @Test
+    void doesNotRetainOperatorMetricGroup() throws Exception {
+        WeakReference<MetricGroup> operatorGroup = 
registerOnUnreferencedGroup();
+
+        for (int i = 0; i < 10 && operatorGroup.get() != null; i++) {
+            System.gc();
+            Thread.sleep(50);
+        }

Review Comment:
   Thanks. The test now uses `CommonTestUtils.waitUtil` and requests a GC every 
50 ms for up to 30 seconds before failing, so a slow collection no longer fails 
it (9896bc749ad).



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