Search in sources :

Example 1 with JavaCommand

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

the class JavaProcessLauncherImplTest method properties_are_passed_to_command_via_a_temporary_properties_file.

@Test
public void properties_are_passed_to_command_via_a_temporary_properties_file() throws Exception {
    File tempDir = temp.newFolder();
    TestProcessBuilder processBuilder = new TestProcessBuilder();
    JavaProcessLauncher underTest = new JavaProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    JavaCommand command = new JavaCommand(ProcessId.ELASTICSEARCH);
    command.setArgument("foo", "bar");
    command.setArgument("baz", "woo");
    underTest.launch(command);
    String propsFilePath = processBuilder.commands.get(processBuilder.commands.size() - 1);
    File file = new File(propsFilePath);
    assertThat(file).exists().isFile();
    try (FileReader reader = new FileReader(file)) {
        Properties props = new Properties();
        props.load(reader);
        assertThat(props).containsOnly(entry("foo", "bar"), entry("baz", "woo"), entry("process.terminationTimeout", "60000"), entry("process.key", ProcessId.ELASTICSEARCH.getKey()), entry("process.index", String.valueOf(ProcessId.ELASTICSEARCH.getIpcIndex())), entry("process.sharedDir", tempDir.getAbsolutePath()));
    }
}
Also used : JavaProcessLauncher(org.sonar.application.process.JavaProcessLauncher) JavaCommand(org.sonar.application.process.JavaCommand) JavaProcessLauncherImpl(org.sonar.application.process.JavaProcessLauncherImpl) FileReader(java.io.FileReader) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 2 with JavaCommand

use of org.sonar.application.process.JavaCommand 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)

Example 3 with JavaCommand

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

the class JavaProcessLauncherImplTest method throw_ISE_if_command_fails.

@Test
public void throw_ISE_if_command_fails() throws IOException {
    File tempDir = temp.newFolder();
    JavaProcessLauncher.SystemProcessBuilder processBuilder = mock(JavaProcessLauncher.SystemProcessBuilder.class, RETURNS_MOCKS);
    when(processBuilder.start()).thenThrow(new IOException("error"));
    JavaProcessLauncher underTest = new JavaProcessLauncherImpl(tempDir, commands, () -> processBuilder);
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Fail to launch process [es]");
    underTest.launch(new JavaCommand(ProcessId.ELASTICSEARCH));
}
Also used : JavaProcessLauncher(org.sonar.application.process.JavaProcessLauncher) JavaCommand(org.sonar.application.process.JavaCommand) JavaProcessLauncherImpl(org.sonar.application.process.JavaProcessLauncherImpl) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)3 Test (org.junit.Test)3 JavaCommand (org.sonar.application.process.JavaCommand)3 JavaProcessLauncher (org.sonar.application.process.JavaProcessLauncher)3 JavaProcessLauncherImpl (org.sonar.application.process.JavaProcessLauncherImpl)3 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 ProcessMonitor (org.sonar.application.process.ProcessMonitor)1