Search in sources :

Example 1 with ProcessCommands

use of org.sonar.process.sharedmemoryfile.ProcessCommands in project sonarqube by SonarSource.

the class StopWatcherTest method stop_watching_on_interruption.

@Test
public void stop_watching_on_interruption() throws Exception {
    ProcessCommands commands = mock(ProcessCommands.class);
    when(commands.askedForHardStop()).thenReturn(false);
    Stoppable stoppable = mock(Stoppable.class);
    StopWatcher underTest = new StopWatcher("TheThreadName", stoppable::hardStopAsync, commands::askedForHardStop, 1L);
    underTest.start();
    underTest.interrupt();
    while (underTest.isAlive()) {
        Thread.sleep(1L);
    }
    verify(stoppable, never()).hardStopAsync();
    assertThat(underTest.getName()).isEqualTo("TheThreadName");
}
Also used : ProcessCommands(org.sonar.process.sharedmemoryfile.ProcessCommands) Test(org.junit.Test)

Example 2 with ProcessCommands

use of org.sonar.process.sharedmemoryfile.ProcessCommands in project sonarqube by SonarSource.

the class ProcessEntryPoint method createForArguments.

public static ProcessEntryPoint createForArguments(String[] args) {
    Props props = ConfigurationUtils.loadPropsFromCommandLineArgs(args);
    File sharedDir = getSharedDir(props);
    int processNumber = getProcessNumber(props);
    ProcessCommands commands = DefaultProcessCommands.main(sharedDir, processNumber);
    return new ProcessEntryPoint(props, new SystemExit(), commands, Runtime.getRuntime());
}
Also used : DefaultProcessCommands(org.sonar.process.sharedmemoryfile.DefaultProcessCommands) ProcessCommands(org.sonar.process.sharedmemoryfile.ProcessCommands) File(java.io.File)

Example 3 with ProcessCommands

use of org.sonar.process.sharedmemoryfile.ProcessCommands in project sonarqube by SonarSource.

the class StopWatcherTest method stop_if_receive_command.

@Test
public void stop_if_receive_command() throws Exception {
    ProcessCommands commands = mock(ProcessCommands.class);
    when(commands.askedForHardStop()).thenReturn(false, true);
    Stoppable stoppable = mock(Stoppable.class);
    StopWatcher underTest = new StopWatcher("TheThreadName", stoppable::hardStopAsync, commands::askedForHardStop, 1L);
    underTest.start();
    while (underTest.isAlive()) {
        Thread.sleep(1L);
    }
    verify(stoppable).hardStopAsync();
    assertThat(underTest.getName()).isEqualTo("TheThreadName");
}
Also used : ProcessCommands(org.sonar.process.sharedmemoryfile.ProcessCommands) Test(org.junit.Test)

Example 4 with ProcessCommands

use of org.sonar.process.sharedmemoryfile.ProcessCommands in project sonarqube by SonarSource.

the class ProcessLauncherImpl method launch.

public ManagedProcess launch(AbstractCommand command) {
    EsInstallation esInstallation = command.getEsInstallation();
    if (esInstallation != null) {
        cleanupOutdatedEsData(esInstallation);
        writeConfFiles(esInstallation);
    }
    Process process;
    if (command instanceof EsScriptCommand) {
        process = launchExternal((EsScriptCommand) command);
    } else if (command instanceof JavaCommand) {
        process = launchJava((JavaCommand<?>) command);
    } else {
        throw new IllegalStateException("Unexpected type of command: " + command.getClass());
    }
    ProcessId processId = command.getProcessId();
    try {
        if (processId == ProcessId.ELASTICSEARCH) {
            checkArgument(esInstallation != null, "Incorrect configuration EsInstallation is null");
            EsConnectorImpl esConnector = new EsConnectorImpl(singleton(HostAndPort.fromParts(esInstallation.getHost(), esInstallation.getHttpPort())), esInstallation.getBootstrapPassword());
            return new EsManagedProcess(process, processId, esConnector);
        } else {
            ProcessCommands commands = allProcessesCommands.createAfterClean(processId.getIpcIndex());
            return new ProcessCommandsManagedProcess(process, processId, commands);
        }
    } catch (Exception e) {
        // just in case
        if (process != null) {
            process.destroyForcibly();
        }
        throw new IllegalStateException(format("Fail to launch monitor of process [%s]", processId.getKey()), e);
    }
}
Also used : JavaCommand(org.sonar.application.command.JavaCommand) EsInstallation(org.sonar.application.es.EsInstallation) EsScriptCommand(org.sonar.application.command.EsScriptCommand) ProcessCommands(org.sonar.process.sharedmemoryfile.ProcessCommands) EsManagedProcess(org.sonar.application.process.EsManagedProcess) ProcessCommandsManagedProcess(org.sonar.application.process.ProcessCommandsManagedProcess) ManagedProcess(org.sonar.application.process.ManagedProcess) ProcessId(org.sonar.process.ProcessId) EsConnectorImpl(org.sonar.application.es.EsConnectorImpl) ProcessCommandsManagedProcess(org.sonar.application.process.ProcessCommandsManagedProcess) EsManagedProcess(org.sonar.application.process.EsManagedProcess) IOException(java.io.IOException)

Example 5 with ProcessCommands

use of org.sonar.process.sharedmemoryfile.ProcessCommands in project sonarqube by SonarSource.

the class ProcessCommandsManagedProcessTest method closeStreams_ignores_null_stream.

@Test
public void closeStreams_ignores_null_stream() {
    ProcessCommands commands = mock(ProcessCommands.class);
    Process process = mock(Process.class);
    when(process.getInputStream()).thenReturn(null);
    ProcessCommandsManagedProcess underTest = new ProcessCommandsManagedProcess(process, null, commands);
    // no failures
    underTest.closeStreams();
}
Also used : ProcessCommands(org.sonar.process.sharedmemoryfile.ProcessCommands) Test(org.junit.Test)

Aggregations

ProcessCommands (org.sonar.process.sharedmemoryfile.ProcessCommands)7 Test (org.junit.Test)5 File (java.io.File)1 IOException (java.io.IOException)1 EsScriptCommand (org.sonar.application.command.EsScriptCommand)1 JavaCommand (org.sonar.application.command.JavaCommand)1 EsConnectorImpl (org.sonar.application.es.EsConnectorImpl)1 EsInstallation (org.sonar.application.es.EsInstallation)1 EsManagedProcess (org.sonar.application.process.EsManagedProcess)1 ManagedProcess (org.sonar.application.process.ManagedProcess)1 ProcessCommandsManagedProcess (org.sonar.application.process.ProcessCommandsManagedProcess)1 ProcessId (org.sonar.process.ProcessId)1 DefaultProcessCommands (org.sonar.process.sharedmemoryfile.DefaultProcessCommands)1