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");
}
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());
}
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");
}
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);
}
}
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();
}
Aggregations