@Before public void setup() { task = new StubTask(); ExitUtil.disableSystemExit(); }
ExitUtil.disableSystemExit(); threadExited = false; Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() {
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); }
/** 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. } }
@BeforeClass public static void before() { ExitUtil.disableSystemExit(); OPTIONS[1] = INVALID_OPTION; }
/** 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. } }
@BeforeClass public static void setUp() { ExitUtil.disableSystemExit(); }
@Before public void setUp() throws IOException { ExitUtil.disableSystemExit(); String baseDir = PathUtils.getTestDirName(getClass()); hdfsDir = new File(baseDir, "dfs/name"); if (hdfsDir.exists() && !FileUtil.fullyDelete(hdfsDir)) { throw new IOException("Could not delete test directory '" + hdfsDir + "'"); } LOG.info("hdfsdir is " + hdfsDir.getAbsolutePath()); // as some tests might change these values we reset them to defaults before // every test StartupOption.FORMAT.setForceFormat(false); StartupOption.FORMAT.setInteractiveFormat(true); config = new Configuration(); config.set(DFS_NAMENODE_NAME_DIR_KEY, hdfsDir.getPath()); }
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); } } }
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); } } }
/** * <p> * Throw {@code Error} inside thread and * check {@code YarnUncaughtExceptionHandler} instance * <p> * Used {@code ExitUtil} class to avoid jvm exit through * {@code System.exit(-1) } * * @throws InterruptedException */ @Test public void testUncaughtExceptionHandlerWithError() throws InterruptedException { ExitUtil.disableSystemExit(); final YarnUncaughtExceptionHandler spyErrorHandler = spy(exHandler); final java.lang.Error error = new java.lang.Error("test-error"); final Thread errorThread = new Thread(new Runnable() { @Override public void run() { throw error; } }); errorThread.setUncaughtExceptionHandler(spyErrorHandler); assertSame(spyErrorHandler, errorThread.getUncaughtExceptionHandler()); errorThread.start(); errorThread.join(); verify(spyErrorHandler).uncaughtException(errorThread, error); }
/** * <p> * Throw {@code Error} inside thread and * check {@code YarnUncaughtExceptionHandler} instance * <p> * Used {@code ExitUtil} class to avoid jvm exit through * {@code System.exit(-1) } * * @throws InterruptedException */ @Test public void testUncaughtExceptionHandlerWithError() throws InterruptedException { ExitUtil.disableSystemExit(); final YarnUncaughtExceptionHandler spyErrorHandler = spy(exHandler); final java.lang.Error error = new java.lang.Error("test-error"); final Thread errorThread = new Thread(new Runnable() { @Override public void run() { throw error; } }); errorThread.setUncaughtExceptionHandler(spyErrorHandler); assertSame(spyErrorHandler, errorThread.getUncaughtExceptionHandler()); errorThread.start(); errorThread.join(); verify(spyErrorHandler).uncaughtException(errorThread, error); }
/** * <p> * Throw {@code Error} inside thread and * check {@code YarnUncaughtExceptionHandler} instance * <p> * Used {@code ExitUtil} class to avoid jvm exit through * {@code System.exit(-1) } * * @throws InterruptedException */ @Test public void testUncaughtExceptionHandlerWithError() throws InterruptedException { ExitUtil.disableSystemExit(); final YarnUncaughtExceptionHandler spyErrorHandler = spy(exHandler); final java.lang.Error error = new java.lang.Error("test-error"); final Thread errorThread = new Thread(new Runnable() { @Override public void run() { throw error; } }); errorThread.setUncaughtExceptionHandler(spyErrorHandler); assertSame(spyErrorHandler, errorThread.getUncaughtExceptionHandler()); errorThread.start(); errorThread.join(); verify(spyErrorHandler).uncaughtException(errorThread, error); }
@Before public void setup() { Logger rootLogger = LogManager.getRootLogger(); rootLogger.setLevel(Level.DEBUG); ExitUtil.disableSystemExit(); testConf = new YarnConfiguration(); testConf .set(YarnConfiguration.RM_STORE, MemoryRMStateStore.class.getName()); UserGroupInformation.setLoginUser(null); UserGroupInformation.setConfiguration(testConf); }
@Before public void setup() { Logger rootLogger = LogManager.getRootLogger(); rootLogger.setLevel(Level.DEBUG); ExitUtil.disableSystemExit(); testConf = new YarnConfiguration(); UserGroupInformation.setLoginUser(null); UserGroupInformation.setConfiguration(testConf); testConf.set(YarnConfiguration.RM_STORE, MemoryRMStateStore.class.getName()); }
@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(); } }
@Test(timeout = 60000) public void testLaunchWithArguments() throws Exception { ExitUtil.disableSystemExit(); ApplicationHistoryServer historyServer = null; try { // Not able to modify the config of this test case, // but others have been customized to avoid conflicts String[] args = new String[2]; args[0]="-D" + YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS + "=4000"; args[1]="-D" + YarnConfiguration.TIMELINE_SERVICE_TTL_MS + "=200"; historyServer = ApplicationHistoryServer.launchAppHistoryServer(args); Configuration conf = historyServer.getConfig(); assertEquals("4000", conf.get(YarnConfiguration.TIMELINE_SERVICE_LEVELDB_TTL_INTERVAL_MS)); assertEquals("200", conf.get(YarnConfiguration.TIMELINE_SERVICE_TTL_MS)); } catch (ExitUtil.ExitException e) { assertEquals(0, e.status); ExitUtil.resetFirstExitException(); fail(); } finally { if (historyServer != null) { historyServer.stop(); } } } @Test(timeout = 240000)
@Test(timeout = 60000) public void testLaunch() throws Exception { ExitUtil.disableSystemExit(); ApplicationHistoryServer historyServer = null; try { // Not able to modify the config of this test case, // but others have been customized to avoid conflicts historyServer = ApplicationHistoryServer.launchAppHistoryServer(new String[0]); } catch (ExitUtil.ExitException e) { assertEquals(0, e.status); ExitUtil.resetFirstExitException(); fail(); } finally { if (historyServer != null) { historyServer.stop(); } } }
@Test public void testNativeLibraryChecker() { ExitUtil.disableSystemExit(); // help should return normally NativeLibraryChecker.main(new String[] {"-h"}); // illegal argmuments should exit expectExit(new String[] {"-a", "-h"}); expectExit(new String[] {"aaa"}); if (NativeCodeLoader.isNativeCodeLoaded()) { // no argument should return normally NativeLibraryChecker.main(new String[0]); } else { // no argument should exit expectExit(new String[0]); } }
@Test public void testNativeLibraryChecker() { ExitUtil.disableSystemExit(); // help should return normally NativeLibraryChecker.main(new String[] {"-h"}); // illegal argmuments should exit expectExit(new String[] {"-a", "-h"}); expectExit(new String[] {"aaa"}); if (NativeCodeLoader.isNativeCodeLoaded()) { // no argument should return normally NativeLibraryChecker.main(new String[0]); } else { // no argument should exit expectExit(new String[0]); } }