use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.
the class ExternalJavacTest method externalJavacWillHashTheExternalIfNoVersionInformationIsReturned.
@Test
public void externalJavacWillHashTheExternalIfNoVersionInformationIsReturned() throws IOException {
Path javac = Files.createTempFile("fake", "javac");
javac.toFile().deleteOnExit();
ProcessExecutorParams javacExe = ProcessExecutorParams.builder().addCommand(javac.toAbsolutePath().toString(), "-version").build();
FakeProcess javacProc = new FakeProcess(0, "", "");
final FakeProcessExecutor executor = new FakeProcessExecutor(ImmutableMap.of(javacExe, javacProc));
ExternalJavac compiler = new ExternalJavac(Either.ofLeft(javac)) {
@Override
ProcessExecutor createProcessExecutor() {
return executor;
}
};
RuleKeyObjectSink sink = createMock(RuleKeyObjectSink.class);
expect(sink.setReflectively("javac", javac.toString())).andReturn(sink);
replay(sink);
compiler.appendToRuleKey(sink);
}
use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.
the class ExternalJavacTest method externalJavacWillHashTheJavacVersionIfPresent.
@Test
public void externalJavacWillHashTheJavacVersionIfPresent() throws IOException {
Path javac = Files.createTempFile("fake", "javac");
javac.toFile().deleteOnExit();
String reportedJavacVersion = "mozzarella";
JavacVersion javacVersion = JavacVersion.of(reportedJavacVersion);
ProcessExecutorParams javacExe = ProcessExecutorParams.builder().addCommand(javac.toAbsolutePath().toString(), "-version").build();
FakeProcess javacProc = new FakeProcess(0, "", reportedJavacVersion);
final FakeProcessExecutor executor = new FakeProcessExecutor(ImmutableMap.of(javacExe, javacProc));
ExternalJavac compiler = new ExternalJavac(Either.ofLeft(javac)) {
@Override
ProcessExecutor createProcessExecutor() {
return executor;
}
};
RuleKeyObjectSink sink = createMock(RuleKeyObjectSink.class);
expect(sink.setReflectively("javac.version", javacVersion.toString())).andReturn(sink);
replay(sink);
compiler.appendToRuleKey(sink);
}
use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.
the class KnownBuildRuleTypesTest method addXcodeSelectProcess.
private static void addXcodeSelectProcess(Map<ProcessExecutorParams, FakeProcess> processMap, String xcodeSelectPath) {
FakeProcess xcodeSelectOutputProcess = new FakeProcess(0, xcodeSelectPath, "");
ProcessExecutorParams xcodeSelectParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("xcode-select", "--print-path")).build();
processMap.put(xcodeSelectParams, xcodeSelectOutputProcess);
}
use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.
the class ShellStepTest method testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr.
@Test
public void testStdErrNotPrintedOnSuccessIfNotShouldPrintStdErr() throws Exception {
ShellStep command = createCommand(/*shouldPrintStdErr*/
false, /*shouldPrintStdOut*/
false);
ProcessExecutorParams params = createParams();
FakeProcess process = new FakeProcess(EXIT_SUCCESS, OUTPUT_MSG, ERROR_MSG);
TestConsole console = new TestConsole(Verbosity.STANDARD_INFORMATION);
ExecutionContext context = createContext(ImmutableMap.of(params, process), console);
command.launchAndInteractWithProcess(context, params);
assertEquals("", console.getTextWrittenToStdErr());
}
use of com.facebook.buck.util.ProcessExecutorParams in project buck by facebook.
the class WorkerShellStepTest method testMultipleWorkerProcesses.
@Test
public void testMultipleWorkerProcesses() throws IOException, InterruptedException {
String jobArgsA = "jobArgsA";
String jobArgsB = "jobArgsB";
final ImmutableMap<String, WorkerJobResult> jobResults = ImmutableMap.of(jobArgsA, WorkerJobResult.of(0, Optional.of("stdout A"), Optional.of("stderr A")), jobArgsB, WorkerJobResult.of(0, Optional.of("stdout B"), Optional.of("stderr B")));
class WorkerShellStepWithFakeProcesses extends WorkerShellStep {
WorkerShellStepWithFakeProcesses(WorkerJobParams jobParams) {
super(Optional.ofNullable(jobParams), Optional.empty(), Optional.empty(), new WorkerProcessPoolFactory(new FakeProjectFilesystem()) {
@Override
WorkerProcess createWorkerProcess(ProcessExecutorParams processParams, ExecutionContext context, Path tmpDir) throws IOException {
try {
sleep(5);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return new FakeWorkerProcess(jobResults);
}
});
}
}
ExecutionContext context = TestExecutionContext.newBuilder().setPlatform(Platform.LINUX).setConsole(new TestConsole(Verbosity.ALL)).setBuckEventBus(BuckEventBusFactory.newInstance()).build();
WorkerJobParams jobParamsA = createJobParams(ImmutableList.of(startupCommand), startupArgs, ImmutableMap.of(), jobArgsA, 2);
WorkerShellStep stepA = new WorkerShellStepWithFakeProcesses(jobParamsA);
WorkerShellStep stepB = new WorkerShellStepWithFakeProcesses(jobParamsA.withJobArgs(jobArgsB));
Thread[] threads = { new ConcurrentExecution(stepA, context), new ConcurrentExecution(stepB, context) };
for (Thread t : threads) {
t.start();
}
for (Thread t : threads) {
t.join();
}
Collection<WorkerProcessPool> pools = context.getWorkerProcessPools().values();
assertThat(pools.size(), Matchers.equalTo(1));
WorkerProcessPool pool = pools.iterator().next();
assertThat(pool.getCapacity(), Matchers.equalTo(2));
}
Aggregations