Skip to content

Commit a22a2f5

Browse files
author
Xing Lin
committed
Fixed OverallPingAvgTime assert
1 parent c3b306f commit a22a2f5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestRPC.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import java.util.concurrent.locks.ReentrantLock;
9898

9999
import static org.apache.hadoop.test.MetricsAsserts.assertGaugeGt;
100+
import static org.apache.hadoop.test.MetricsAsserts.assertGaugeGte;
100101
import static org.apache.hadoop.test.MetricsAsserts.mockMetricsRecordBuilder;
101102
import static org.assertj.core.api.Assertions.assertThat;
102103
import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
@@ -1466,9 +1467,11 @@ public void testOverallRpcProcessingTimeMetric() throws Exception {
14661467
server.rpcDetailedMetrics.getOverallRpcProcessingRates();
14671468
rates.snapshot(rb, true);
14681469

1469-
// Verify the ping request. AvgTime should be non-zero.
1470+
// Verify the ping request.
1471+
// Overall processing time for ping is zero when this test is run together with
1472+
// the rest of tests. Thus, we use assertGaugeGte() for OverallPingAvgTime.
14701473
assertCounter("OverallPingNumOps", 1L, rb);
1471-
assertGaugeGt("OverallPingAvgTime", 0, rb);
1474+
assertGaugeGte("OverallPingAvgTime", 0.0, rb);
14721475

14731476
// Verify lockAndSleep requests. AvgTime should be greater than 10 ms,
14741477
// since we sleep for 10 and 12 ms respectively.

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/MetricsAsserts.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,18 @@ public static void assertGaugeGt(String name, double greater,
358358
getDoubleGauge(name, rb) > greater);
359359
}
360360

361+
/**
362+
* Assert that a double gauge metric is greater than or equal to a value
363+
* @param name of the metric
364+
* @param greater value of the metric should be greater than or equal to this
365+
* @param rb the record builder mock used to getMetrics
366+
*/
367+
public static void assertGaugeGte(String name, double greater,
368+
MetricsRecordBuilder rb) {
369+
Assert.assertTrue("Bad value for metric " + name,
370+
getDoubleGauge(name, rb) >= greater);
371+
}
372+
361373
/**
362374
* Assert that a double gauge metric is greater than a value
363375
* @param name of the metric

0 commit comments

Comments
 (0)