From c5c90ff8f58805880f27be66d28a811fe22a6152 Mon Sep 17 00:00:00 2001 From: Jason Darrell Lowe Date: Wed, 7 Aug 2013 20:02:10 +0000 Subject: [PATCH] MAPREDUCE-5425. Junit in TestJobHistoryServer failing in jdk 7. Contributed by Robert Parker git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1511464 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 +++ .../mapreduce/v2/hs/JobHistoryServer.java | 16 +++++++++++---- .../mapreduce/v2/hs/TestJobHistoryServer.java | 20 +++++-------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index 3a7ff9274e..cc6eae3ec4 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -217,6 +217,9 @@ Release 2.1.1-beta - UNRELEASED MAPREDUCE-5367. Local jobs all use same local working directory (Sandy Ryza) + MAPREDUCE-5425. Junit in TestJobHistoryServer failing in jdk 7 (Robert + Parker via jlowe) + Release 2.1.0-beta - 2013-08-06 INCOMPATIBLE CHANGES diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/JobHistoryServer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/JobHistoryServer.java index d6f509f144..a5e2f1794a 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/JobHistoryServer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/JobHistoryServer.java @@ -32,6 +32,7 @@ import org.apache.hadoop.metrics2.source.JvmMetrics; import org.apache.hadoop.security.SecurityUtil; import org.apache.hadoop.service.CompositeService; +import org.apache.hadoop.util.ExitUtil; import org.apache.hadoop.util.ShutdownHookManager; import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler; @@ -139,11 +140,13 @@ public HistoryClientService getClientService() { return this.clientService; } - public static void main(String[] args) { - Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler()); + static JobHistoryServer launchJobHistoryServer(String[] args) { + Thread. + setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler()); StringUtils.startupShutdownMessage(JobHistoryServer.class, args, LOG); + JobHistoryServer jobHistoryServer = null; try { - JobHistoryServer jobHistoryServer = new JobHistoryServer(); + jobHistoryServer = new JobHistoryServer(); ShutdownHookManager.get().addShutdownHook( new CompositeServiceShutdownHook(jobHistoryServer), SHUTDOWN_HOOK_PRIORITY); @@ -152,7 +155,12 @@ public static void main(String[] args) { jobHistoryServer.start(); } catch (Throwable t) { LOG.fatal("Error starting JobHistoryServer", t); - System.exit(-1); + ExitUtil.terminate(-1, "Error starting JobHistoryServer"); } + return jobHistoryServer; + } + + public static void main(String[] args) { + launchJobHistoryServer(args); } } diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestJobHistoryServer.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestJobHistoryServer.java index 0a1c638226..109601e41b 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestJobHistoryServer.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/TestJobHistoryServer.java @@ -63,14 +63,11 @@ public class TestJobHistoryServer { private static RecordFactory recordFactory = RecordFactoryProvider .getRecordFactory(null); - - JobHistoryServer historyServer=null; + // simple test init/start/stop JobHistoryServer. Status should change. - @Test (timeout= 50000 ) public void testStartStopServer() throws Exception { - historyServer = new JobHistoryServer(); Configuration config = new Configuration(); historyServer.init(config); @@ -86,15 +83,9 @@ public void testStartStopServer() throws Exception { historyServer.stop(); assertEquals(STATE.STOPPED, historyServer.getServiceState()); assertNotNull(historyService.getClientHandler().getConnectAddress()); - - - } - - //Test reports of JobHistoryServer. History server should get log files from MRApp and read them - @Test (timeout= 50000 ) public void testReports() throws Exception { Configuration config = new Configuration(); @@ -128,7 +119,6 @@ public void testReports() throws Exception { assertEquals(1, jobs.size()); assertEquals("job_0_0000",jobs.keySet().iterator().next().toString()); - Task task = job.getTasks().values().iterator().next(); TaskAttempt attempt = task.getAttempts().values().iterator().next(); @@ -188,14 +178,14 @@ public void testReports() throws Exception { assertEquals("", diagnosticResponse.getDiagnostics(0)); } - // test main method + + // test launch method @Test (timeout =60000) - public void testMainMethod() throws Exception { + public void testLaunch() throws Exception { ExitUtil.disableSystemExit(); try { - JobHistoryServer.main(new String[0]); - + historyServer = JobHistoryServer.launchJobHistoryServer(new String[0]); } catch (ExitUtil.ExitException e) { assertEquals(0,e.status); ExitUtil.resetFirstExitException();