/** * Like {@link #terminate(int, Throwable)} without a message. * * @param status exit code * @throws ExitException if {@link System#exit(int)} is disabled. */ public static void terminate(int status) throws ExitException { terminate(status, EXIT_EXCEPTION_MESSAGE); }
/** * Main entry point. * @param argv args list */ public static void main(String[] argv) { try { ExitUtil.terminate(exec(new Configuration(), argv)); } catch (ExitUtil.ExitException e) { LOG.error(e.toString()); System.exit(e.status); } catch (Exception e) { LOG.error(e.toString(), e); ExitUtil.halt(-1, e); } }
ExitUtil.haltOnOutOfMemory((OutOfMemoryError) exception); } else { ExitUtil.terminate(ee.status, ee);
/** MRAppMaster exit method which has been instrumented for both runtime and * unit testing. * If the main thread has not been started, this method was called from a * test. In that case, configure the ExitUtil object to not exit the JVM. * * @param status integer indicating exit status * @param t throwable exception that could be null */ private void exitMRAppMaster(int status, Throwable t) { if (!mainStarted) { ExitUtil.disableSystemExit(); } try { if (t != null) { ExitUtil.terminate(status, t); } else { ExitUtil.terminate(status); } } catch (ExitUtil.ExitException ee) { // ExitUtil.ExitException is only thrown from the ExitUtil test code when // SystemExit has been disabled. It is always thrown in in the test code, // even when no error occurs. Ignore the exception so that tests don't // need to handle it. } }
@Before public void setup() { task = new StubTask(); ExitUtil.disableSystemExit(); }
private void expectOutput(String [] args) { ExitUtil.disableSystemExit(); ByteArrayOutputStream outContent = new ByteArrayOutputStream(); PrintStream originalPs = System.out; System.setOut(new PrintStream(outContent)); try { NativeLibraryChecker.main(args); } catch (ExitException e) { ExitUtil.resetFirstExitException(); } finally { if (Shell.WINDOWS) { assertEquals(outContent.toString().indexOf("winutils: true") != -1, true); } if (NativeCodeLoader.isNativeCodeLoaded()) { assertEquals(outContent.toString().indexOf("hadoop: true") != -1, true); } System.setOut(originalPs); } } }
/** * Forcibly terminates the currently running Java virtual machine. * @param status status code * @throws HaltException if {@link Runtime#halt(int)} is disabled. */ public static void halt(int status) throws HaltException { halt(status, HALT_EXCEPTION_MESSAGE); }
@Before public void resetSystemExit() { ExitUtil.resetFirstExitException(); }
/** MRAppMaster exit method which has been instrumented for both runtime and * unit testing. * If the main thread has not been started, this method was called from a * test. In that case, configure the ExitUtil object to not exit the JVM. * * @param status integer indicating exit status * @param t throwable exception that could be null */ private void exitMRAppMaster(int status, Throwable t) { if (!mainStarted) { ExitUtil.disableSystemExit(); } try { if (t != null) { ExitUtil.terminate(status, t); } else { ExitUtil.terminate(status); } } catch (ExitUtil.ExitException ee) { // ExitUtil.ExitException is only thrown from the ExitUtil test code when // SystemExit has been disabled. It is always thrown in in the test code, // even when no error occurs. Ignore the exception so that tests don't // need to handle it. } }
ExitUtil.disableSystemExit(); threadExited = false; Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() {
private void expectOutput(String [] args) { ExitUtil.disableSystemExit(); ByteArrayOutputStream outContent = new ByteArrayOutputStream(); PrintStream originalPs = System.out; System.setOut(new PrintStream(outContent)); try { NativeLibraryChecker.main(args); } catch (ExitException e) { ExitUtil.resetFirstExitException(); } finally { if (Shell.WINDOWS) { assertEquals(outContent.toString().indexOf("winutils: true") != -1, true); } if (NativeCodeLoader.isNativeCodeLoaded()) { assertEquals(outContent.toString().indexOf("hadoop: true") != -1, true); } System.setOut(originalPs); } } }
/** * Forcibly terminates the currently running Java virtual machine. * * @param status exit code to use if the exception is not a HaltException. * @param t throwable which triggered the termination. If this exception * is a {@link HaltException} its status overrides that passed in. * @throws HaltException if {@link System#exit(int)} is disabled. */ public static void halt(int status, Throwable t) throws HaltException { if (t instanceof HaltException) { halt((HaltException) t); } else { halt(new HaltException(status, t)); } }
private void expectExit(String [] args) { try { // should throw exit exception NativeLibraryChecker.main(args); fail("should call exit"); } catch (ExitException e) { // pass ExitUtil.resetFirstExitException(); } }
/** * Exit the JVM. * * This is method can be overridden for testing, throwing an * exception instead. Any subclassed method MUST raise an * {@code ExitException} instance/subclass. * The service launcher code assumes that after this method is invoked, * no other code in the same method is called. * @param exitCode code to exit */ protected void exit(int exitCode, String message) { ExitUtil.terminate(exitCode, message); }
@Override public void uncaughtException(Thread t, Throwable e) { LOG.info("UncaughtExceptionHandler invoked"); if(ShutdownHookManager.isShutdownInProgress()) { LOG.warn("Thread {} threw a Throwable, but we are shutting down, so ignoring this", t, e); } else if(e instanceof Error) { try { LOG.error("Thread {} threw an Error. Shutting down now...", t, e); } catch (Throwable err) { //We don't want to not exit because of an issue with logging } if(e instanceof OutOfMemoryError) { //After catching an OOM java says it is undefined behavior, so don't //even try to clean up or we can get stuck on shutdown. try { System.err.println("Halting due to Out Of Memory Error..."); e.printStackTrace(); } catch (Throwable err) { //Again we done want to exit because of logging issues. } ExitUtil.halt(-1); } else { ExitUtil.terminate(-1); } } else { LOG.error("Thread {} threw an Exception. Shutting down now...", t, e); ExitUtil.terminate(-1); } } }
public void testScratchDirLimit(boolean fastFail, JobConf conf) throws Exception { ExitUtil.disableSystemExit(); threadExited = false; Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { if (ex instanceof ExitUtil.ExitException) { threadExited = true; th.interrupt(); } } }; Task task = new DummyTask(); task.setConf(conf); DummyTaskReporter reporter = new DummyTaskReporter(task); reporter.startDiskLimitCheckerThreadIfNeeded(); Thread t = new Thread(reporter); t.setUncaughtExceptionHandler(h); reporter.setProgressFlag(); t.start(); while (!reporter.taskLimitIsChecked) { Thread.yield(); } task.done(fakeUmbilical, reporter); reporter.resetDoneFlag(); t.join(1000L); Assert.assertEquals(fastFail, threadExited); }
@Test(timeout = 60000) public void testLaunch() throws Exception { ExitUtil.disableSystemExit(); try { auxService = PerNodeTimelineCollectorsAuxService.launchServer(new String[0], createCollectorManager(), conf); } catch (ExitUtil.ExitException e) { assertEquals(0, e.status); ExitUtil.resetFirstExitException(); fail(); } }
/** * Forcibly terminates the currently running Java virtual machine. * @param status status code * @param message message * @throws HaltException if {@link Runtime#halt(int)} is disabled. */ public static void halt(int status, String message) throws HaltException { halt(new HaltException(status, message)); }
private void expectExit(String [] args) { try { // should throw exit exception NativeLibraryChecker.main(args); fail("should call exit"); } catch (ExitException e) { // pass ExitUtil.resetFirstExitException(); } }
/** * Exit the JVM using an exception for the exit code and message, * invoking {@link ExitUtil#terminate(ExitUtil.ExitException)}. * * This is the standard way a launched service exits. * An error code of 0 means success -nothing is printed. * * If {@link ExitUtil#disableSystemExit()} has been called, this * method will throw the exception. * * The method <i>may</i> be subclassed for testing * @param ee exit exception * @throws ExitUtil.ExitException if ExitUtil exceptions are disabled */ protected void exit(ExitUtil.ExitException ee) { ExitUtil.terminate(ee); }