From 9ffb6429a487f75cf2477fbca24b220c2d64ef0f Mon Sep 17 00:00:00 2001 From: Jonathan Turner Eagles Date: Fri, 21 Feb 2014 16:32:52 +0000 Subject: [PATCH] MAPREDUCE-5671. NaN can be created by client and assign to Progress (Chen He via jeagles) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1570623 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/hadoop/util/Progress.java | 25 +++++++++++ .../org/apache/hadoop/util/TestProgress.java | 44 +++++++++++++++++++ hadoop-mapreduce-project/CHANGES.txt | 3 ++ 3 files changed, 72 insertions(+) create mode 100644 hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestProgress.java diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Progress.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Progress.java index 90643577479..0af0844134d 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Progress.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Progress.java @@ -160,6 +160,31 @@ public class Progress { /** Called during execution on a leaf node to set its progress. */ public synchronized void set(float progress) { + if (Float.isNaN(progress)) { + progress = 0; + LOG.warn("Illegal progress value found, progress is Float.NaN. " + + "Progress will be changed to 0"); + } + else if (progress == Float.NEGATIVE_INFINITY) { + progress = 0; + LOG.warn("Illegal progress value found, progress is " + + "Float.NEGATIVE_INFINITY. Progress will be changed to 0"); + } + else if (progress < 0) { + progress = 0; + LOG.warn("Illegal progress value found, progress is less than 0." + + " Progress will be changed to 0"); + } + else if (progress > 1) { + progress = 1; + LOG.warn("Illegal progress value found, progress is larger than 1." + + " Progress will be changed to 1"); + } + else if (progress == Float.POSITIVE_INFINITY) { + progress = 1; + LOG.warn("Illegal progress value found, progress is " + + "Float.POSITIVE_INFINITY. Progress will be changed to 1"); + } this.progress = progress; } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestProgress.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestProgress.java new file mode 100644 index 00000000000..20f537b2fa5 --- /dev/null +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestProgress.java @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.util; + +import org.junit.Assert; +import org.junit.Test; + +public class TestProgress { + + @Test + public void testSet(){ + Progress progress = new Progress(); + progress.set(Float.NaN); + Assert.assertEquals(0, progress.getProgress(), 0.0); + + progress.set(Float.NEGATIVE_INFINITY); + Assert.assertEquals(0,progress.getProgress(),0.0); + + progress.set(-1); + Assert.assertEquals(0,progress.getProgress(),0.0); + + progress.set((float) 1.1); + Assert.assertEquals(1,progress.getProgress(),0.0); + + progress.set(Float.POSITIVE_INFINITY); + Assert.assertEquals(1,progress.getProgress(),0.0); + } +} diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index c98d8949758..733db03d126 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -8,6 +8,9 @@ Release 2.5.0 - UNRELEASED IMPROVEMENTS + MAPREDUCE-5671. NaN can be created by client and assign to Progress (Chen + He via jeagles) + OPTIMIZATIONS BUG FIXES