use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class JavacExecutionContextSerializerTest method testSerializingAndDeserializing.
@Test
public void testSerializingAndDeserializing() throws Exception {
Path tmp = Files.createTempDirectory("junit-temp-path").toRealPath();
JavacEventSink eventSink = new JavacEventSinkToBuckEventBusBridge(BuckEventBusFactory.newInstance());
PrintStream stdErr = new PrintStream(new ByteArrayOutputStream());
ClassLoaderCache classLoaderCache = new ClassLoaderCache();
ObjectMapper objectMapper = new ObjectMapper();
Verbosity verbosity = Verbosity.COMMANDS_AND_OUTPUT;
DefaultCellPathResolver cellPathResolver = new DefaultCellPathResolver(Paths.get("/some/cell/path/resolver/path"), ImmutableMap.of("key1", Paths.get("/path/1")));
DefaultJavaPackageFinder javaPackageFinder = new DefaultJavaPackageFinder(ImmutableSortedSet.of("paths", "from", "root"), ImmutableSet.of("path", "elements"));
ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmp);
NoOpClassUsageFileWriter classUsageFileWriter = NoOpClassUsageFileWriter.instance();
ImmutableMap<String, String> environment = ImmutableMap.of("k1", "v1", "k2", "v2");
ImmutableMap<String, String> processExecutorContext = ImmutableMap.of("pek1", "pev1", "pek2", "pev2");
ProcessExecutor processExecutor = new ContextualProcessExecutor(new DefaultProcessExecutor(new TestConsole()), processExecutorContext);
ImmutableList<Path> pathToInputs = ImmutableList.of(Paths.get("/path/one"), Paths.get("/path/two"));
DirectToJarOutputSettings directToJarOutputSettings = DirectToJarOutputSettings.of(Paths.get("/some/path"), ImmutableSet.of(Pattern.compile("[a-z]"), Pattern.compile("[0-9]", Pattern.MULTILINE)), ImmutableSortedSet.of(Paths.get("some/path"), Paths.get("/other path/")), Optional.of("hello I am main class"), Optional.of(Paths.get("/MANIFEST/FILE.TXT")));
JavacExecutionContext input = JavacExecutionContext.of(eventSink, stdErr, classLoaderCache, objectMapper, verbosity, cellPathResolver, javaPackageFinder, projectFilesystem, classUsageFileWriter, environment, processExecutor, pathToInputs, Optional.of(directToJarOutputSettings));
Map<String, Object> data = JavacExecutionContextSerializer.serialize(input);
JavacExecutionContext output = JavacExecutionContextSerializer.deserialize(data, eventSink, stdErr, classLoaderCache, objectMapper, new TestConsole());
assertThat(output.getEventSink(), Matchers.equalTo(eventSink));
assertThat(output.getStdErr(), Matchers.equalTo(stdErr));
assertThat(output.getClassLoaderCache(), Matchers.equalTo(classLoaderCache));
assertThat(output.getObjectMapper(), Matchers.equalTo(objectMapper));
assertThat(output.getVerbosity(), Matchers.equalTo(verbosity));
assertThat(output.getCellPathResolver(), Matchers.instanceOf(DefaultCellPathResolver.class));
DefaultCellPathResolver outCellPathResolver = (DefaultCellPathResolver) output.getCellPathResolver();
assertThat(outCellPathResolver.getRoot(), Matchers.equalToObject(cellPathResolver.getRoot()));
assertThat(outCellPathResolver.getCellPaths(), Matchers.equalToObject(cellPathResolver.getCellPaths()));
assertThat(output.getProcessExecutor(), Matchers.instanceOf(ContextualProcessExecutor.class));
ContextualProcessExecutor contextualProcessExecutor = (ContextualProcessExecutor) output.getProcessExecutor();
assertThat(contextualProcessExecutor.getContext(), Matchers.equalToObject(processExecutorContext));
assertThat(output.getJavaPackageFinder(), Matchers.instanceOf(DefaultJavaPackageFinder.class));
DefaultJavaPackageFinder outputJavaPackageFinder = (DefaultJavaPackageFinder) output.getJavaPackageFinder();
assertThat(outputJavaPackageFinder.getPathsFromRoot(), Matchers.equalToObject(javaPackageFinder.getPathsFromRoot()));
assertThat(outputJavaPackageFinder.getPathElements(), Matchers.equalToObject(javaPackageFinder.getPathElements()));
assertThat(output.getProjectFilesystem().getRootPath(), Matchers.equalToObject(projectFilesystem.getRootPath()));
assertThat(output.getUsedClassesFileWriter(), Matchers.instanceOf(NoOpClassUsageFileWriter.class));
assertThat(output.getEnvironment(), Matchers.equalToObject(environment));
assertThat(output.getAbsolutePathsForInputs(), Matchers.equalToObject(pathToInputs));
assertThat(output.getDirectToJarOutputSettings().get().getDirectToJarOutputPath(), Matchers.equalToObject(directToJarOutputSettings.getDirectToJarOutputPath()));
assertThat(output.getDirectToJarOutputSettings().get().getEntriesToJar(), Matchers.equalToObject(directToJarOutputSettings.getEntriesToJar()));
assertThat(output.getDirectToJarOutputSettings().get().getMainClass(), Matchers.equalToObject(directToJarOutputSettings.getMainClass()));
assertThat(output.getDirectToJarOutputSettings().get().getManifestFile(), Matchers.equalToObject(directToJarOutputSettings.getManifestFile()));
assertThat(output.getDirectToJarOutputSettings().get().getClassesToRemoveFromJar().size(), Matchers.equalToObject(directToJarOutputSettings.getClassesToRemoveFromJar().size()));
ImmutableList<Pattern> inputPatterns = directToJarOutputSettings.getClassesToRemoveFromJar().asList();
ImmutableList<Pattern> outputPatterns = output.getDirectToJarOutputSettings().get().getClassesToRemoveFromJar().asList();
for (int i = 0; i < inputPatterns.size(); i++) {
Pattern inputPattern = inputPatterns.get(i);
Pattern outputPattern = outputPatterns.get(i);
assertThat(outputPattern.pattern(), Matchers.equalToObject(inputPattern.pattern()));
assertThat(outputPattern.flags(), Matchers.equalTo(inputPattern.flags()));
}
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class RageCommandIntegrationTest method testUploadFailure.
@Test
public void testUploadFailure() throws Exception {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "interactive_report", temporaryFolder);
workspace.setUp();
try (HttpdForTests httpd = new HttpdForTests()) {
httpd.addHandler(new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
httpServletResponse.setStatus(500);
request.setHandled(true);
}
});
httpd.start();
RageConfig rageConfig = createRageConfig(httpd.getRootUri().getPort(), "", RageProtocolVersion.SIMPLE);
ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
Clock clock = new DefaultClock();
DefectReporter reporter = new DefaultDefectReporter(filesystem, objectMapper, rageConfig, BuckEventBusFactory.newInstance(clock), clock);
AutomatedReport automatedReport = new AutomatedReport(reporter, filesystem, objectMapper, new TestConsole(), TestBuildEnvironmentDescription.INSTANCE, VcsInfoCollector.create(new NoOpCmdLineInterface()), rageConfig, Optional::empty);
DefectSubmitResult submitReport = automatedReport.collectAndSubmitResult().get();
// If upload fails it should store the zip locally and inform the user.
assertFalse(submitReport.getReportSubmitErrorMessage().get().isEmpty());
ZipInspector zipInspector = new ZipInspector(filesystem.resolve(submitReport.getReportSubmitLocation().get()));
assertEquals(zipInspector.getZipFileEntries().size(), 7);
}
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class RageCommandIntegrationTest method testUpload.
@Test
public void testUpload() throws Exception {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "interactive_report", temporaryFolder);
workspace.setUp();
final AtomicReference<String> requestMethod = new AtomicReference<>();
final AtomicReference<String> requestPath = new AtomicReference<>();
final AtomicReference<byte[]> requestBody = new AtomicReference<>();
final String successMessage = "Upload successful";
try (HttpdForTests httpd = new HttpdForTests()) {
httpd.addHandler(new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
httpServletResponse.setStatus(200);
request.setHandled(true);
if (request.getUri().getPath().equals("/status.php")) {
return;
}
requestPath.set(request.getUri().getPath());
requestMethod.set(request.getMethod());
requestBody.set(ByteStreams.toByteArray(httpServletRequest.getInputStream()));
try (DataOutputStream out = new DataOutputStream(httpServletResponse.getOutputStream())) {
out.writeBytes(successMessage);
}
}
});
httpd.start();
RageConfig rageConfig = createRageConfig(httpd.getRootUri().getPort(), "", RageProtocolVersion.SIMPLE);
ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
Clock clock = new DefaultClock();
DefectReporter reporter = new DefaultDefectReporter(filesystem, objectMapper, rageConfig, BuckEventBusFactory.newInstance(clock), clock);
AutomatedReport automatedReport = new AutomatedReport(reporter, filesystem, objectMapper, new TestConsole(), TestBuildEnvironmentDescription.INSTANCE, VcsInfoCollector.create(new NoOpCmdLineInterface()), rageConfig, Optional::empty);
DefectSubmitResult defectSubmitResult = automatedReport.collectAndSubmitResult().get();
assertThat(defectSubmitResult.getReportSubmitMessage(), Matchers.equalTo(Optional.of(successMessage)));
assertThat(requestPath.get(), Matchers.equalTo(UPLOAD_PATH));
assertThat(requestMethod.get(), Matchers.equalTo("POST"));
filesystem.mkdirs(filesystem.getBuckPaths().getBuckOut());
Path report = filesystem.createTempFile(filesystem.getBuckPaths().getBuckOut(), "report", "zip");
filesystem.writeBytesToPath(requestBody.get(), report);
ZipInspector zipInspector = new ZipInspector(filesystem.resolve(report));
zipInspector.assertFileExists("report.json");
zipInspector.assertFileExists("buckconfig.local");
zipInspector.assertFileExists("bucklogging.local.properties");
zipInspector.assertFileExists(BUILD_COMMAND_DIR_PATH + "buck.log");
zipInspector.assertFileExists(AUTODEPS_COMMAND_DIR_PATH + "buck.log");
zipInspector.assertFileExists(BUILD_COMMAND_DIR_PATH + "buck-machine-log");
zipInspector.assertFileExists(AUTODEPS_COMMAND_DIR_PATH + "buck-machine-log");
}
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class RageCommandIntegrationTest method testJsonUpload.
@Test
public void testJsonUpload() throws Exception {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "interactive_report", temporaryFolder);
workspace.setUp();
try (HttpdForTests httpd = new HttpdForTests()) {
httpd.addHandler(new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
httpResponse.setStatus(200);
request.setHandled(true);
if (request.getUri().getPath().equals("/status.php")) {
return;
}
RageJsonResponse json = RageJsonResponse.of(/* isRequestSuccessful */
true, /* errorMessage */
Optional.empty(), /* rageUrl */
Optional.of("http://remoteUrlToVisit"), /* message */
Optional.of("This is supposed to be JSON."));
try (DataOutputStream out = new DataOutputStream(httpResponse.getOutputStream())) {
objectMapper.writeValue(out, json);
}
}
});
httpd.start();
RageConfig rageConfig = createRageConfig(httpd.getRootUri().getPort(), "", RageProtocolVersion.JSON);
ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
Clock clock = new DefaultClock();
DefectReporter reporter = new DefaultDefectReporter(filesystem, objectMapper, rageConfig, BuckEventBusFactory.newInstance(clock), clock);
AutomatedReport automatedReport = new AutomatedReport(reporter, filesystem, objectMapper, new TestConsole(), TestBuildEnvironmentDescription.INSTANCE, VcsInfoCollector.create(new NoOpCmdLineInterface()), rageConfig, Optional::empty);
DefectSubmitResult submitReport = automatedReport.collectAndSubmitResult().get();
assertEquals("http://remoteUrlToVisit", submitReport.getReportSubmitLocation().get());
assertEquals("This is supposed to be JSON.", submitReport.getReportSubmitMessage().get());
}
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class TestWithBuckd method before.
@Override
protected void before() throws IOException, InterruptedException {
// In case root_restrict_files is enabled in /etc/watchmanconfig, assume
// this is one of the entries so it doesn't give up.
temporaryPaths.newFolder(".git");
temporaryPaths.newFile(".arcconfig");
Watchman watchman = Watchman.build(ImmutableSet.of(temporaryPaths.getRoot()), getWatchmanEnv(), new TestConsole(), new FakeClock(0), Optional.empty());
// We assume watchman has been installed and configured properly on the system, and that setting
// up the watch is successful.
assumeFalse(watchman == Watchman.NULL_WATCHMAN);
}
Aggregations