HADOOP-11104. org.apache.hadoop.metrics2.lib.MetricsRegistry needs numerical parameter checking. Contributed by Ray Chiang.

(cherry picked from commit e1bf8b3df6)
This commit is contained in:
Akira Ajisaka 2015-10-09 11:10:29 +09:00
parent 22ff37f5ce
commit 2c6c9e315c
3 changed files with 26 additions and 2 deletions

View File

@ -291,6 +291,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-12350. WASB Logging: Improve WASB Logging around deletes, reads and HADOOP-12350. WASB Logging: Improve WASB Logging around deletes, reads and
writes (Dushyanth via cnauroth) writes (Dushyanth via cnauroth)
HADOOP-11104. org.apache.hadoop.metrics2.lib.MetricsRegistry needs numerical
parameter checking. (Ray Chiang via aajisaka)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-11785. Reduce the number of listStatus operation in distcp HADOOP-11785. Reduce the number of listStatus operation in distcp

View File

@ -188,10 +188,15 @@ public class MetricsRegistry {
* @param valueName of the metric (e.g., "Time" or "Latency") * @param valueName of the metric (e.g., "Time" or "Latency")
* @param interval rollover interval of estimator in seconds * @param interval rollover interval of estimator in seconds
* @return a new quantile estimator object * @return a new quantile estimator object
* @throws MetricsException if interval is not a positive integer
*/ */
public synchronized MutableQuantiles newQuantiles(String name, String desc, public synchronized MutableQuantiles newQuantiles(String name, String desc,
String sampleName, String valueName, int interval) { String sampleName, String valueName, int interval) {
checkMetricName(name); checkMetricName(name);
if (interval <= 0) {
throw new MetricsException("Interval should be positive. Value passed" +
" is: " + interval);
}
MutableQuantiles ret = MutableQuantiles ret =
new MutableQuantiles(name, desc, sampleName, valueName, interval); new MutableQuantiles(name, desc, sampleName, valueName, interval);
metricsMap.put(name, ret); metricsMap.put(name, ret);

View File

@ -122,6 +122,22 @@ public class TestMetricsRegistry {
}); });
} }
/**
* Test adding illegal parameters
*/
@Test
public void testAddIllegalParameters() {
final MetricsRegistry r = new MetricsRegistry("IllegalParamTest");
expectMetricsException("Interval should be positive. Value passed is: -20",
new Runnable() {
@Override
public void run() {
r.newQuantiles("q1", "New Quantile 1", "qq1", "qv1", (int)-20);
}
});
}
@Ignore @Ignore
private void expectMetricsException(String prefix, Runnable fun) { private void expectMetricsException(String prefix, Runnable fun) {
try { try {