Search in sources :

Example 1 with ProcessMonitor

use of org.sonar.application.process.ProcessMonitor in project sonarqube by SonarSource.

the class JavaProcessLauncherImplTest method launch_forks_a_new_process.

@Test
public void launch_forks_a_new_process() throws Exception {
    File tempDir = temp.newFolder();
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    JavaProcessLauncher underTest = new JavaProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    JavaCommand command = new JavaCommand(ProcessId.ELASTICSEARCH);
    command.addClasspath("lib/*.class");
    command.addClasspath("lib/*.jar");
    command.setArgument("foo", "bar");
    command.setClassName("org.sonarqube.Main");
    command.setEnvVariable("VAR1", "valueOfVar1");
    command.setWorkDir(temp.newFolder());
    ProcessMonitor monitor = underTest.launch(command);
    assertThat(monitor).isNotNull();
    assertThat(processBuilder.started).isTrue();
    assertThat(processBuilder.commands.get(0)).endsWith("java");
    assertThat(processBuilder.commands).containsSequence("-Djava.io.tmpdir=" + tempDir.getAbsolutePath(), "-cp", "lib/*.class" + System.getProperty("path.separator") + "lib/*.jar", "org.sonarqube.Main");
    assertThat(processBuilder.dir).isEqualTo(command.getWorkDir());
    assertThat(processBuilder.redirectErrorStream).isTrue();
    assertThat(processBuilder.environment).contains(entry("VAR1", "valueOfVar1")).containsAllEntriesOf(command.getEnvVariables());
}
Also used : JavaProcessLauncher(org.sonar.application.process.JavaProcessLauncher) JavaCommand(org.sonar.application.process.JavaCommand) JavaProcessLauncherImpl(org.sonar.application.process.JavaProcessLauncherImpl) ProcessMonitor(org.sonar.application.process.ProcessMonitor) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Test (org.junit.Test)1 JavaCommand (org.sonar.application.process.JavaCommand)1 JavaProcessLauncher (org.sonar.application.process.JavaProcessLauncher)1 JavaProcessLauncherImpl (org.sonar.application.process.JavaProcessLauncherImpl)1 ProcessMonitor (org.sonar.application.process.ProcessMonitor)1