You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by jl...@apache.org on 2012/12/26 21:34:39 UTC
svn commit: r1426014 - in
/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common:
CHANGES.txt src/main/java/org/apache/hadoop/util/ExitUtil.java
Author: jlowe
Date: Wed Dec 26 20:34:39 2012
New Revision: 1426014
URL: http://svn.apache.org/viewvc?rev=1426014&view=rev
Log:
HADOOP-9169. Bring branch-0.23 ExitUtil up to same level as branch-2. Contributed by Robert Joseph Evans
Modified:
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java
Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1426014&r1=1426013&r2=1426014&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt Wed Dec 26 20:34:39 2012
@@ -42,6 +42,9 @@ Release 0.23.6 - UNRELEASED
HADOOP-9152. HDFS can report negative DFS Used on clusters with very
small amounts of data (Brock Noland via tgraves)
+ HADOOP-9169. Bring branch-0.23 ExitUtil up to same level as branch-2
+ (Robert Joseph Evans via jlowe)
+
Release 0.23.5 - UNRELEASED
INCOMPATIBLE CHANGES
Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java?rev=1426014&r1=1426013&r2=1426014&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java (original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ExitUtil.java Wed Dec 26 20:34:39 2012
@@ -30,7 +30,7 @@ import org.apache.hadoop.classification.
public final class ExitUtil {
private final static Log LOG = LogFactory.getLog(ExitUtil.class.getName());
private static volatile boolean systemExitDisabled = false;
- private static volatile boolean terminateCalled = false;
+ private static volatile ExitException firstExitException;
public static class ExitException extends RuntimeException {
private static final long serialVersionUID = 1L;
@@ -50,17 +50,34 @@ public final class ExitUtil {
}
/**
- * Clear the previous exit record.
+ * @return true if terminate has been called
*/
- public static void clearTerminateCalled() {
- terminateCalled = false;
+ public static boolean terminateCalled() {
+ // Either we set this member or we actually called System#exit
+ return firstExitException != null;
}
/**
- * @return true if terminate has been called
+ * @return the first ExitException thrown, null if none thrown yet
*/
- public static boolean terminateCalled() {
- return terminateCalled;
+ public static ExitException getFirstExitException() {
+ return firstExitException;
+ }
+
+ /**
+ * Reset the tracking of process termination. This is for use
+ * in unit tests where one test in the suite expects an exit
+ * but others do not.
+ */
+ public static void resetFirstExitException() {
+ firstExitException = null;
+ }
+
+ /**
+ * Clear the previous exit record.
+ */
+ public static void clearTerminateCalled() {
+ resetFirstExitException();
}
/**
@@ -72,17 +89,32 @@ public final class ExitUtil {
*/
public static void terminate(int status, String msg) throws ExitException {
LOG.info("Exiting with status " + status);
- terminateCalled = true;
if (systemExitDisabled) {
- throw new ExitException(status, msg);
+ ExitException ee = new ExitException(status, msg);
+ LOG.fatal("Terminate called", ee);
+ if (null == firstExitException) {
+ firstExitException = ee;
+ }
+ throw ee;
}
System.exit(status);
}
/**
+ * Like {@link terminate(int, String)} but uses the given throwable to
+ * initialize the ExitException.
+ * @param status
+ * @param t throwable used to create the ExitException
+ * @throws ExitException if System.exit is disabled for test purposes
+ */
+ public static void terminate(int status, Throwable t) throws ExitException {
+ terminate(status, StringUtils.stringifyException(t));
+ }
+
+ /**
* Like {@link terminate(int, String)} without a message.
* @param status
- * @throws ExitException
+ * @throws ExitException if System.exit is disabled for test purposes
*/
public static void terminate(int status) throws ExitException {
terminate(status, "ExitException");