diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java index 5642a2340d7..dbe6663b2e7 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java @@ -38,6 +38,10 @@ public final class ExitUtil { private static volatile boolean systemHaltDisabled = false; private static volatile ExitException firstExitException; private static volatile HaltException firstHaltException; + /** Message raised from an exit exception if none were provided: {@value}. */ + public static final String EXIT_EXCEPTION_MESSAGE = "ExitException"; + /** Message raised from a halt exception if none were provided: {@value}. */ + public static final String HALT_EXCEPTION_MESSAGE = "HaltException"; private ExitUtil() { } @@ -285,7 +289,7 @@ public final class ExitUtil { * @throws ExitException if {@link System#exit(int)} is disabled. */ public static void terminate(int status) throws ExitException { - terminate(status, ""); + terminate(status, EXIT_EXCEPTION_MESSAGE); } /** @@ -306,7 +310,7 @@ public final class ExitUtil { * @throws HaltException if {@link Runtime#halt(int)} is disabled. */ public static void halt(int status) throws HaltException { - halt(status, ""); + halt(status, HALT_EXCEPTION_MESSAGE); } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java index dc8f70a5b5b..e1663e29615 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestMetadataVersionOutput.java @@ -24,6 +24,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants; +import org.apache.hadoop.util.ExitUtil; + import org.junit.After; import org.junit.Test; @@ -78,7 +80,7 @@ public class TestMetadataVersionOutput { try { NameNode.createNameNode(new String[] { "-metadataVersion" }, conf); } catch (Exception e) { - assertExceptionContains("ExitException", e); + assertExceptionContains(ExitUtil.EXIT_EXCEPTION_MESSAGE, e); } /* Check if meta data version is printed correctly. */ final String verNumStr = HdfsServerConstants.NAMENODE_LAYOUT_VERSION + ""; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStartup.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStartup.java index 2fe25e0e716..f8a033641d3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStartup.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestStartup.java @@ -437,8 +437,9 @@ public class TestStartup { SecondaryNameNode.main(argv); fail("Failed to handle runtime exceptions during SNN startup!"); } catch (ExitException ee) { - GenericTestUtils.assertExceptionContains("ExitException", ee); - assertTrue("Didn't termiated properly ", ExitUtil.terminateCalled()); + GenericTestUtils.assertExceptionContains( + ExitUtil.EXIT_EXCEPTION_MESSAGE, ee); + assertTrue("Didn't terminate properly ", ExitUtil.terminateCalled()); } } diff --git a/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixSubmission.java b/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixSubmission.java index f1800c177aa..d4bfddcc1ed 100644 --- a/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixSubmission.java +++ b/hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixSubmission.java @@ -39,6 +39,7 @@ import java.io.IOException; import java.io.PrintStream; import java.util.zip.GZIPInputStream; +import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains; import static org.junit.Assert.*; public class TestGridmixSubmission extends CommonJobTest { @@ -185,7 +186,7 @@ public class TestGridmixSubmission extends CommonJobTest { DebugGridmix.main(argv); } catch (ExitUtil.ExitException e) { - assertEquals("ExitException", e.getMessage()); + assertExceptionContains(ExitUtil.EXIT_EXCEPTION_MESSAGE, e); ExitUtil.resetFirstExitException(); } finally { System.setErr(oldOut);