From 7afb9aca709bc5d34a4661c816b6941189d85cb1 Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Thu, 29 Dec 2011 08:24:09 +0000 Subject: [PATCH] MAPREDUCE-3521. Fixed streaming to ensure it doesn't silently ignore unknown arguments. Contributed by Robert Evans. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1225471 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 +++ .../java/org/apache/hadoop/streaming/StreamJob.java | 7 +++++++ .../org/apache/hadoop/streaming/TestStreamJob.java | 13 ++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 926161a9b2..e1c1771509 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -375,6 +375,9 @@ Release 0.23.1 - Unreleased MAPREDUCE-3604. Fixed streaming to use new mapreduce.framework.name to check for local mode. (acmurthy) + MAPREDUCE-3521. Fixed streaming to ensure it doesn't silently ignore + unknown arguments. (Robert Evans via acmurthy) + Release 0.23.0 - 2011-11-01 INCOMPATIBLE CHANGES diff --git a/hadoop-tools/hadoop-streaming/src/main/java/org/apache/hadoop/streaming/StreamJob.java b/hadoop-tools/hadoop-streaming/src/main/java/org/apache/hadoop/streaming/StreamJob.java index 3a0689d870..39ba36d179 100644 --- a/hadoop-tools/hadoop-streaming/src/main/java/org/apache/hadoop/streaming/StreamJob.java +++ b/hadoop-tools/hadoop-streaming/src/main/java/org/apache/hadoop/streaming/StreamJob.java @@ -255,6 +255,13 @@ void parseArgv() { } if (cmdLine != null) { + @SuppressWarnings("unchecked") + List args = cmdLine.getArgList(); + if(args != null && args.size() > 0) { + fail("Found " + args.size() + " unexpected arguments on the " + + "command line " + args); + } + detailedUsage_ = cmdLine.hasOption("info"); if (cmdLine.hasOption("help") || detailedUsage_) { printUsage = true; diff --git a/hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/streaming/TestStreamJob.java b/hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/streaming/TestStreamJob.java index 3ba37a845d..3e9036fca9 100644 --- a/hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/streaming/TestStreamJob.java +++ b/hadoop-tools/hadoop-streaming/src/test/java/org/apache/hadoop/streaming/TestStreamJob.java @@ -32,7 +32,18 @@ * This class tests hadoop Streaming's StreamJob class. */ public class TestStreamJob { - + + @Test(expected = IllegalArgumentException.class) + public void testCreateJobWithExtraArgs() throws IOException { + ArrayList dummyArgs = new ArrayList(); + dummyArgs.add("-input"); dummyArgs.add("dummy"); + dummyArgs.add("-output"); dummyArgs.add("dummy"); + dummyArgs.add("-mapper"); dummyArgs.add("dummy"); + dummyArgs.add("dummy"); + dummyArgs.add("-reducer"); dummyArgs.add("dummy"); + StreamJob.createJob(dummyArgs.toArray(new String[] {})); + } + @Test public void testCreateJob() throws IOException { JobConf job;