github-advanced-security[bot] commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2027756849


##########
server/src/test/java/org/apache/druid/segment/realtime/SegmentGenerationMetricsTest.java:
##########
@@ -37,33 +37,73 @@
   public void testSnapshotBeforeProcessing()
   {
     SegmentGenerationMetrics snapshot = metrics.snapshot();
-    Assert.assertEquals(0L, snapshot.messageGap());
+    assertMetricsReset(snapshot);
+    assertMetricsReset(metrics);
     // invalid value
     Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
   }
 
   @Test
   public void testSnapshotAfterProcessingOver()
   {
-    metrics.reportMessageMaxTimestamp(System.currentTimeMillis() - 20L);
+    metrics.reportMessageGapAggregates(20L);
+    metrics.reportMessageMaxTimestamp(20L);
     metrics.reportMaxSegmentHandoffTime(7L);
     SegmentGenerationMetrics snapshot = metrics.snapshot();
+
     Assert.assertTrue(snapshot.messageGap() >= 20L);
+    Assert.assertEquals(20L, snapshot.minMessageGap());
+    Assert.assertEquals(20L, snapshot.maxMessageGap());
+    Assert.assertEquals(snapshot.minMessageGap(), snapshot.maxMessageGap());
+    Assert.assertEquals(20L, snapshot.messageGapAvg());
     Assert.assertEquals(7, snapshot.maxSegmentHandoffTime());
   }
 
   @Test
   public void testProcessingOverAfterSnapshot()
   {
     metrics.reportMessageMaxTimestamp(10);
+    metrics.reportMessageGapAggregates(1);
     metrics.reportMaxSegmentHandoffTime(7L);
     // Should reset to invalid value
     metrics.snapshot();
     metrics.markProcessingDone();
     SegmentGenerationMetrics snapshot = metrics.snapshot();
-    // Message gap must be invalid after processing is done
-    Assert.assertTrue(0 > snapshot.messageGap());
+
+    // Latest message gap must be invalid after processing is done
+    Assert.assertEquals(-1, snapshot.messageGap());
+    assertMetricsReset(snapshot);
+    assertMetricsReset(metrics);
     // value must be invalid
     Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
   }
+
+  @Test
+  public void testMessageGapAggregateMetrics()
+  {
+    for (int i = 0; i < 5; ++i) {
+      metrics.reportMessageGapAggregates(i * 30);
+    }
+    metrics.reportMessageMaxTimestamp(10L);
+    metrics.reportMaxSegmentHandoffTime(7L);
+    metrics.markProcessingDone();
+    SegmentGenerationMetrics snapshot = metrics.snapshot();
+    // Latest message gap must be invalid after processing is done
+    Assert.assertEquals(-1, snapshot.messageGap());
+
+    Assert.assertEquals(5, snapshot.numMessageGapEvent());
+    Assert.assertEquals(0, snapshot.minMessageGap());
+    Assert.assertEquals(120, snapshot.maxMessageGap());
+    Assert.assertEquals(60, snapshot.messageGapAvg());

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Assert.assertEquals](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8794)



##########
server/src/test/java/org/apache/druid/segment/realtime/SegmentGenerationMetricsTest.java:
##########
@@ -37,33 +37,73 @@
   public void testSnapshotBeforeProcessing()
   {
     SegmentGenerationMetrics snapshot = metrics.snapshot();
-    Assert.assertEquals(0L, snapshot.messageGap());
+    assertMetricsReset(snapshot);
+    assertMetricsReset(metrics);
     // invalid value
     Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
   }
 
   @Test
   public void testSnapshotAfterProcessingOver()
   {
-    metrics.reportMessageMaxTimestamp(System.currentTimeMillis() - 20L);
+    metrics.reportMessageGapAggregates(20L);
+    metrics.reportMessageMaxTimestamp(20L);
     metrics.reportMaxSegmentHandoffTime(7L);
     SegmentGenerationMetrics snapshot = metrics.snapshot();
+
     Assert.assertTrue(snapshot.messageGap() >= 20L);
+    Assert.assertEquals(20L, snapshot.minMessageGap());
+    Assert.assertEquals(20L, snapshot.maxMessageGap());
+    Assert.assertEquals(snapshot.minMessageGap(), snapshot.maxMessageGap());
+    Assert.assertEquals(20L, snapshot.messageGapAvg());

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Assert.assertEquals](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8793)



##########
server/src/test/java/org/apache/druid/segment/realtime/SegmentGenerationMetricsTest.java:
##########
@@ -37,33 +37,73 @@
   public void testSnapshotBeforeProcessing()
   {
     SegmentGenerationMetrics snapshot = metrics.snapshot();
-    Assert.assertEquals(0L, snapshot.messageGap());
+    assertMetricsReset(snapshot);
+    assertMetricsReset(metrics);
     // invalid value
     Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
   }
 
   @Test
   public void testSnapshotAfterProcessingOver()
   {
-    metrics.reportMessageMaxTimestamp(System.currentTimeMillis() - 20L);
+    metrics.reportMessageGapAggregates(20L);
+    metrics.reportMessageMaxTimestamp(20L);
     metrics.reportMaxSegmentHandoffTime(7L);
     SegmentGenerationMetrics snapshot = metrics.snapshot();
+
     Assert.assertTrue(snapshot.messageGap() >= 20L);
+    Assert.assertEquals(20L, snapshot.minMessageGap());
+    Assert.assertEquals(20L, snapshot.maxMessageGap());
+    Assert.assertEquals(snapshot.minMessageGap(), snapshot.maxMessageGap());
+    Assert.assertEquals(20L, snapshot.messageGapAvg());
     Assert.assertEquals(7, snapshot.maxSegmentHandoffTime());
   }
 
   @Test
   public void testProcessingOverAfterSnapshot()
   {
     metrics.reportMessageMaxTimestamp(10);
+    metrics.reportMessageGapAggregates(1);
     metrics.reportMaxSegmentHandoffTime(7L);
     // Should reset to invalid value
     metrics.snapshot();
     metrics.markProcessingDone();
     SegmentGenerationMetrics snapshot = metrics.snapshot();
-    // Message gap must be invalid after processing is done
-    Assert.assertTrue(0 > snapshot.messageGap());
+
+    // Latest message gap must be invalid after processing is done
+    Assert.assertEquals(-1, snapshot.messageGap());
+    assertMetricsReset(snapshot);
+    assertMetricsReset(metrics);
     // value must be invalid
     Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
   }
+
+  @Test
+  public void testMessageGapAggregateMetrics()
+  {
+    for (int i = 0; i < 5; ++i) {
+      metrics.reportMessageGapAggregates(i * 30);
+    }
+    metrics.reportMessageMaxTimestamp(10L);
+    metrics.reportMaxSegmentHandoffTime(7L);
+    metrics.markProcessingDone();
+    SegmentGenerationMetrics snapshot = metrics.snapshot();
+    // Latest message gap must be invalid after processing is done
+    Assert.assertEquals(-1, snapshot.messageGap());
+
+    Assert.assertEquals(5, snapshot.numMessageGapEvent());
+    Assert.assertEquals(0, snapshot.minMessageGap());
+    Assert.assertEquals(120, snapshot.maxMessageGap());
+    Assert.assertEquals(60, snapshot.messageGapAvg());
+
+    Assert.assertEquals(7L, snapshot.maxSegmentHandoffTime());
+  }
+
+  private static void assertMetricsReset(final SegmentGenerationMetrics 
metrics)
+  {
+    Assert.assertEquals(0, metrics.numMessageGapEvent());
+    Assert.assertEquals(0, metrics.maxMessageGap());
+    Assert.assertEquals(Long.MAX_VALUE, metrics.minMessageGap());
+    Assert.assertEquals(0, metrics.messageGapAvg());

Review Comment:
   ## Deprecated method or constructor invocation
   
   Invoking [Assert.assertEquals](1) should be avoided because it has been 
deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8795)



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to