Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2488F184DC for ; Fri, 9 Oct 2015 02:11:21 +0000 (UTC) Received: (qmail 46886 invoked by uid 500); 9 Oct 2015 02:11:20 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 46825 invoked by uid 500); 9 Oct 2015 02:11:20 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 46816 invoked by uid 99); 9 Oct 2015 02:11:20 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Oct 2015 02:11:20 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 59DFDE0C54; Fri, 9 Oct 2015 02:11:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aajisaka@apache.org To: common-commits@hadoop.apache.org Message-Id: <54d3073273e946d0ac89fabcf81f2bbb@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HADOOP-11104. org.apache.hadoop.metrics2.lib.MetricsRegistry needs numerical parameter checking. Contributed by Ray Chiang. Date: Fri, 9 Oct 2015 02:11:20 +0000 (UTC) Repository: hadoop Updated Branches: refs/heads/trunk 584cf3bb3 -> e1bf8b3df HADOOP-11104. org.apache.hadoop.metrics2.lib.MetricsRegistry needs numerical parameter checking. Contributed by Ray Chiang. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e1bf8b3d Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e1bf8b3d Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e1bf8b3d Branch: refs/heads/trunk Commit: e1bf8b3df6f019b92a3dad37c977f40397324e75 Parents: 584cf3b Author: Akira Ajisaka Authored: Fri Oct 9 11:10:29 2015 +0900 Committer: Akira Ajisaka Committed: Fri Oct 9 11:10:29 2015 +0900 ---------------------------------------------------------------------- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../apache/hadoop/metrics2/lib/MetricsRegistry.java | 9 +++++++-- .../hadoop/metrics2/lib/TestMetricsRegistry.java | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/e1bf8b3d/hadoop-common-project/hadoop-common/CHANGES.txt ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 3eb106f..9d954d0 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -876,6 +876,9 @@ Release 2.8.0 - UNRELEASED HADOOP-12350. WASB Logging: Improve WASB Logging around deletes, reads and writes (Dushyanth via cnauroth) + HADOOP-11104. org.apache.hadoop.metrics2.lib.MetricsRegistry needs numerical + parameter checking. (Ray Chiang via aajisaka) + OPTIMIZATIONS HADOOP-11785. Reduce the number of listStatus operation in distcp http://git-wip-us.apache.org/repos/asf/hadoop/blob/e1bf8b3d/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MetricsRegistry.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MetricsRegistry.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MetricsRegistry.java index 4b561f2..6e7e5ab 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MetricsRegistry.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MetricsRegistry.java @@ -188,16 +188,21 @@ public class MetricsRegistry { * @param valueName of the metric (e.g., "Time" or "Latency") * @param interval rollover interval of estimator in seconds * @return a new quantile estimator object + * @throws MetricsException if interval is not a positive integer */ public synchronized MutableQuantiles newQuantiles(String name, String desc, String sampleName, String valueName, int interval) { checkMetricName(name); - MutableQuantiles ret = + if (interval <= 0) { + throw new MetricsException("Interval should be positive. Value passed" + + " is: " + interval); + } + MutableQuantiles ret = new MutableQuantiles(name, desc, sampleName, valueName, interval); metricsMap.put(name, ret); return ret; } - + /** * Create a mutable metric with stats * @param name of the metric http://git-wip-us.apache.org/repos/asf/hadoop/blob/e1bf8b3d/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMetricsRegistry.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMetricsRegistry.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMetricsRegistry.java index af1ff96..d916928 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMetricsRegistry.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/lib/TestMetricsRegistry.java @@ -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 private void expectMetricsException(String prefix, Runnable fun) { try {