ServerProcessImpl implements ServerProcess { @Override public void start() { checkState(processResultHandler == null, "Server is already started"); checkState(server.version().isGreaterThanOrEquals(6, 2), "Minimum supported version of SonarQube is 6.2. Got %s.", server.version()); LOGGER.info("Start server {} from {}", server.version(), server.getHome().getAbsolutePath()); CommandLine command = serverCommandLineFactory.create(server); executor = new DefaultExecutor(); executor.setWatchdog(new ExecuteWatchdog(-1L)); executor.setWorkingDirectory(server.getHome()); StartupLogListener listener = new StartupLogListener(startupLogWatcher, server.getClusterNodeName().orElse(null)); executor.setStreamHandler(new PumpStreamHandler(listener)); processResultHandler = new DefaultExecuteResultHandler(); try { executor.execute(command, freshEnv(), processResultHandler); } catch (IOException e) { throw fail("Can not execute command: " + command, e); } for (int i = 0; i < startTimeoutMs / START_RETRY_TIMEOUT_MS; i++) { if (listener.isStarted()) { shutdownHook = new Thread(new StopShutdownHook()); Runtime.getRuntime().addShutdownHook(shutdownHook); return; } if (processResultHandler.hasResult()) { throw fail("Server startup failure", processResultHandler.getException()); } try { Thread.sleep(START_RETRY_TIMEOUT_MS); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); } } stop(); throw fail("Server did not start in timely fashion", null); } ServerProcessImpl(ServerCommandLineFactory serverCommandLineFactory, Server server,
    @Nullable StartupLogWatcher startupLogWatcher); @Override void start(); @Override void stop();  }
@Test public void fail_if_command_can_not_be_executed() throws Exception { when(server.version()).thenReturn(Version.create("6.7")); File invalidDir = temp.newFolder(); when(server.getHome()).thenReturn(invalidDir); invalidDir.delete(); when(commandLineFactory.create(server)).thenReturn(new CommandLine("command_does_not_exist")); expectedException.expectMessage("Can not execute command"); underTest.start(); }
@Test public void fail_if_server_version_is_older_than_6_2() throws Exception { when(server.version()).thenReturn(Version.create("5.6")); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Minimum supported version of SonarQube is 6.2. Got 5.6."); underTest.start(); }