From cb98b81851184e1ae35b65c00386806147005338 Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Sat, 13 Aug 2011 20:25:53 +0000 Subject: [PATCH] MAPREDUCE-2727. Fix divide-by-zero error in SleepJob for sleepCount equals 0. Contributed by Jeffrey Naisbitt. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1157422 13f79535-47bb-0310-9956-ffa450edef68 --- mapreduce/CHANGES.txt | 3 +++ .../mapred/org/apache/hadoop/mapreduce/SleepJob.java | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mapreduce/CHANGES.txt b/mapreduce/CHANGES.txt index 8acda6dba7c..1ea594bbcf0 100644 --- a/mapreduce/CHANGES.txt +++ b/mapreduce/CHANGES.txt @@ -402,6 +402,9 @@ Trunk (unreleased changes) MAPREDUCE-2839. Fixed TokenCache to get delegation tokens using both new and old apis. (Siddharth Seth via acmurthy) + MAPREDUCE-2727. Fix divide-by-zero error in SleepJob for sleepCount equals + 0. (Jeffrey Naisbitt via acmurthy) + Release 0.22.0 - Unreleased diff --git a/mapreduce/src/test/mapred/org/apache/hadoop/mapreduce/SleepJob.java b/mapreduce/src/test/mapred/org/apache/hadoop/mapreduce/SleepJob.java index f6ce1cc0c48..92add201c39 100644 --- a/mapreduce/src/test/mapred/org/apache/hadoop/mapreduce/SleepJob.java +++ b/mapreduce/src/test/mapred/org/apache/hadoop/mapreduce/SleepJob.java @@ -97,6 +97,9 @@ public class SleepJob extends Configured implements Tool { public boolean nextKeyValue() throws IOException { + if (count == 0) { + return false; + } key = new IntWritable(); key.set(emitCount); int emit = emitPerMapTask / count; @@ -112,7 +115,7 @@ public class SleepJob extends Configured implements Tool { public IntWritable getCurrentValue() { return value; } public void close() throws IOException { } public float getProgress() throws IOException { - return records / ((float)count); + return count == 0 ? 100 : records / ((float)count); } }; } @@ -129,7 +132,7 @@ public class SleepJob extends Configured implements Tool { Configuration conf = context.getConfiguration(); this.mapSleepCount = conf.getInt(MAP_SLEEP_COUNT, mapSleepCount); - this.mapSleepDuration = + this.mapSleepDuration = mapSleepCount == 0 ? 0 : conf.getLong(MAP_SLEEP_TIME , 100) / mapSleepCount; } @@ -166,7 +169,7 @@ public class SleepJob extends Configured implements Tool { Configuration conf = context.getConfiguration(); this.reduceSleepCount = conf.getInt(REDUCE_SLEEP_COUNT, reduceSleepCount); - this.reduceSleepDuration = + this.reduceSleepDuration = reduceSleepCount == 0 ? 0 : conf.getLong(REDUCE_SLEEP_TIME , 100) / reduceSleepCount; }