Runtime { public static CharSequence jrun(final Class<?> classWithMain, final long timeoutMillis, final String... arguments) throws IOException, InterruptedException, ExecutionException, TimeoutException { final String classPath = ManagementFactory.getRuntimeMXBean().getClassPath(); return jrun(classWithMain, classPath, timeoutMillis, arguments); } private  Runtime(); static org.spf4j.base.Version getAppVersion(); static String getAppVersionString(); static ApplicationInfo getApplicationInfo(); static boolean isShuttingDown(); @SuppressWarnings("checkstyle:regexp") static void error(final String message); @SuppressWarnings("checkstyle:regexp") static void error(final String message, final Throwable t); @SuppressWarnings("checkstyle:regexp") static void errorNoPackageDetail(final String message, final Throwable t); static void goDownWithError(final SysExits exitCode); static void goDownWithError(@Nullable final Throwable t, final SysExits exitCode); @SuppressFBWarnings("MDM_RUNTIME_EXIT_OR_HALT") static void goDownWithError(@Nullable final Throwable t, final int exitCode); @Deprecated static boolean isMacOsx(); @Deprecated static boolean isWindows(); static boolean isTestFramework(); @Deprecated static boolean haveJnaPlatform(); @Deprecated static boolean haveJnaPlatformClib(); @CheckReturnValue @Deprecated static int getNrOpenFiles(); @Nullable @CheckReturnValue @Deprecated static CharSequence getLsofOutput(); @Deprecated static CharSequence run(final String[] command,
          final long timeoutMillis); @Deprecated static int killProcess(final Process proc, final long terminateTimeoutMillis,
          final long forceTerminateTimeoutMillis); static int run(final String[] command, final ProcOutputHandler handler,
          final long timeoutMillis); @SuppressFBWarnings("COMMAND_INJECTION") @Deprecated static int run(final String[] command, final ProcOutputHandler handler,
          final long timeoutMillis, final long terminationTimeoutMillis); static void queueHookAtBeginning(final Runnable runnable); static void queueHookAtEnd(final Runnable runnable); static void queueHook(final int priority, final Runnable runnable); static boolean removeQueuedShutdownHook(final Runnable runnable); @Deprecated static long getDeadline(); @Deprecated static long millisToDeadline(); @SuppressFBWarnings static boolean gc(final long timeoutMillis); static CharSequence jrun(final Class<?> classWithMain,
          final long timeoutMillis, final String... arguments); static CharSequence jrun(final Class<?> classWithMain, final String classPath, final long timeoutMillis,
          final String... arguments); static synchronized void setCurrentDir(final String sourceAbsolutePath); static synchronized String getCurrentDir(); static CharSequence jrun(final Class<?> classWithMain, final String classPath, final long timeoutMillis,
          final String[] jvmArgs,
          final String... arguments); static void jrunAndLog(final Class<?> classWithMain,
          final long timeoutMillis, final String... arguments); static void jrunAndLog(final Class<?> classWithMain, final String classPath, final long timeoutMillis,
          final String... arguments); static void jrunAndLog(final Class<?> classWithMain, final String classPath, final long timeoutMillis,
          final String[] jvmArgs,
          final String... arguments); @Nullable static Thread getMainThread(); @Nullable static Class<?> getMainClass(); static final boolean IS_LITTLE_ENDIAN; static final long WAIT_FOR_SHUTDOWN_NANOS; static final String TMP_FOLDER; static final Path TMP_FOLDER_PATH; static final String JAVA_VERSION; static final String USER_NAME; static final String USER_DIR; static final String USER_HOME; static final String JAVA_HOME; static final int PID; static final String PROCESS_NAME; static final String OS_NAME; static final String PROCESS_ID; static final int NR_PROCESSORS; static final Version JAVA_PLATFORM; }
@Test(expected = ExecutionException.class, timeout = 60000) @ExpectLog(category = "org.spf4j.os", level = Level.ERROR, nrTimes = 2) public void testExitCode() throws IOException, InterruptedException, ExecutionException, TimeoutException { Runtime.jrun(RuntimeTest.TestError.class, 60000); }
@ExpectLog(category = "org.spf4j.os", level = Level.ERROR, nrTimes = 2) @Test(expected = ExecutionException.class, timeout = 60000) public void testExitCode2() throws IOException, InterruptedException, ExecutionException, TimeoutException { Runtime.jrun(RuntimeTest.TestError2.class, 60000); }
@Test(expected = TimeoutException.class, timeout = 30000) public void testExitCode3() throws IOException, InterruptedException, ExecutionException, TimeoutException { LogCollection<Long> collect = TestLoggers.sys().collect(StdOutToStringProcessHandler.class.getName(), Level.ERROR, Level.ERROR, false, Collectors.counting()); Runtime.jrun(RuntimeTest.TestError3.class, 10000); Assert.assertTrue(collect.get() > 0); }
@Test(expected = InterruptedException.class, timeout = 30000) public void testExitCode4() throws IOException, InterruptedException, ExecutionException, TimeoutException { final Thread t = Thread.currentThread(); DefaultScheduler.INSTANCE.schedule(() -> { t.interrupt(); }, 1, TimeUnit.SECONDS); Runtime.jrun(RuntimeTest.TestSleeping.class, 10000); }
@SuppressFBWarnings("SIC_INNER_SHOULD_BE_STATIC_ANON") @Test(expected = CancellationException.class, timeout = 30000) public void testExitCode5() throws InterruptedException, ExecutionException, TimeoutException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch canCancel = new CountDownLatch(1); Future<?> submit = DefaultExecutor.INSTANCE.submit(new AbstractRunnable() { @Override public void doRun() throws IOException, InterruptedException, ExecutionException, TimeoutException { try { canCancel.countDown(); Runtime.jrun(RuntimeTest.TestError3.class, 10000); } catch (InterruptedException ex) { LOG.info("Interrupted jrun TestError3", ex); latch.countDown(); } catch (Exception ex) { LOG.info("Exception jrun TestError3", ex); } } }); if (!canCancel.await(3000, TimeUnit.MILLISECONDS)) { Assert.fail("exec should happen"); } LOG.debug("cancelling {}", submit); submit.cancel(true); if (!latch.await(1, TimeUnit.SECONDS)) { Assert.fail("exec should be cancelled"); } submit.get(10000, TimeUnit.MILLISECONDS); }