Search in sources :

Example 16 with DefaultClock

use of com.facebook.buck.timing.DefaultClock 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");
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) DefaultClock(com.facebook.buck.timing.DefaultClock) Clock(com.facebook.buck.timing.Clock) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) DefaultClock(com.facebook.buck.timing.DefaultClock) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) HttpdForTests(com.facebook.buck.testutil.integration.HttpdForTests) Path(java.nio.file.Path) Optional(java.util.Optional) NoOpCmdLineInterface(com.facebook.buck.util.versioncontrol.NoOpCmdLineInterface) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 17 with DefaultClock

use of com.facebook.buck.timing.DefaultClock in project buck by facebook.

the class DefectReporterTest method testAttachesReport.

@Test
public void testAttachesReport() throws Exception {
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    RageConfig config = RageConfig.of(FakeBuckConfig.builder().build());
    Clock clock = new DefaultClock();
    DefectReporter reporter = new DefaultDefectReporter(filesystem, objectMapper, config, BuckEventBusFactory.newInstance(clock), clock);
    DefectSubmitResult defectSubmitResult = reporter.submitReport(DefectReport.builder().setBuildEnvironmentDescription(TEST_ENV_DESCRIPTION).setUserLocalConfiguration(TEST_USER_LOCAL_CONFIGURATION).build());
    Path reportPath = filesystem.resolve(defectSubmitResult.getReportSubmitLocation().get());
    try (ZipFile zipFile = new ZipFile(reportPath.toFile())) {
        ZipEntry entry = zipFile.getEntry("report.json");
        JsonNode reportNode = objectMapper.readTree(zipFile.getInputStream(entry));
        assertThat(reportNode.get("buildEnvironmentDescription").get("user").asText(), Matchers.equalTo("test_user"));
        assertThat(reportNode.get("userLocalConfiguration").get("noBuckCheckPresent").asBoolean(), Matchers.equalTo(true));
    }
}
Also used : Path(java.nio.file.Path) ZipFile(java.util.zip.ZipFile) DefaultClock(com.facebook.buck.timing.DefaultClock) ZipEntry(java.util.zip.ZipEntry) JsonNode(com.fasterxml.jackson.databind.JsonNode) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultClock(com.facebook.buck.timing.DefaultClock) Clock(com.facebook.buck.timing.Clock) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 18 with DefaultClock

use of com.facebook.buck.timing.DefaultClock in project buck by facebook.

the class DefectReporterTest method testAttachesPaths.

@Test
public void testAttachesPaths() throws Exception {
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    RageConfig config = RageConfig.of(FakeBuckConfig.builder().build());
    Clock clock = new DefaultClock();
    DefectReporter reporter = new DefaultDefectReporter(filesystem, ObjectMappers.newDefaultInstance(), config, BuckEventBusFactory.newInstance(clock), clock);
    Path fileToBeIncluded = Paths.get("FileToBeIncluded.txt");
    filesystem.touch(fileToBeIncluded);
    String fileToBeIncludedContent = "testcontentbehere";
    filesystem.writeContentsToPath(fileToBeIncludedContent, fileToBeIncluded);
    DefectSubmitResult defectSubmitResult = reporter.submitReport(DefectReport.builder().setBuildEnvironmentDescription(TEST_ENV_DESCRIPTION).setIncludedPaths(fileToBeIncluded).setUserLocalConfiguration(TEST_USER_LOCAL_CONFIGURATION).build());
    Path reportPath = filesystem.resolve(defectSubmitResult.getReportSubmitLocation().get());
    ZipInspector inspector = new ZipInspector(reportPath);
    inspector.assertFileContents(fileToBeIncluded, fileToBeIncludedContent);
}
Also used : Path(java.nio.file.Path) DefaultClock(com.facebook.buck.timing.DefaultClock) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultClock(com.facebook.buck.timing.DefaultClock) Clock(com.facebook.buck.timing.Clock) Test(org.junit.Test)

Example 19 with DefaultClock

use of com.facebook.buck.timing.DefaultClock 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());
    }
}
Also used : HttpdForTests(com.facebook.buck.testutil.integration.HttpdForTests) Optional(java.util.Optional) DataOutputStream(java.io.DataOutputStream) NoOpCmdLineInterface(com.facebook.buck.util.versioncontrol.NoOpCmdLineInterface) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) DefaultClock(com.facebook.buck.timing.DefaultClock) Clock(com.facebook.buck.timing.Clock) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) DefaultClock(com.facebook.buck.timing.DefaultClock) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 20 with DefaultClock

use of com.facebook.buck.timing.DefaultClock in project buck by facebook.

the class BuildInfoRecorderIntegrationTest method testPerformUploadToArtifactCache.

@Test
public void testPerformUploadToArtifactCache() throws IOException, InterruptedException {
    BuildInfoRecorder buildInfoRecorder = createBuildInfoRecorder(new FakeProjectFilesystem() {

        @Override
        public void createZip(Collection<Path> pathsToIncludeInZip, Path out) throws IOException {
            // For this test, nothing really cares about the content, so just write out the name.
            writeBytesToPath(out.toString().getBytes(), out);
        }
    });
    Path cacheDir = Files.createTempDirectory("root");
    ArtifactCache artifactCache = TestArtifactCaches.createDirCacheForTest(cacheDir, Paths.get("cache"));
    buildInfoRecorder.performUploadToArtifactCache(ImmutableSet.of(new RuleKey(RULE_KEY)), artifactCache, new BuckEventBus(new DefaultClock(), new BuildId()));
    assertTrue(cacheDir.resolve(DirArtifactCacheTestUtil.getPathForRuleKey(artifactCache, new RuleKey(RULE_KEY), Optional.empty())).toFile().exists());
}
Also used : Path(java.nio.file.Path) BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) DefaultClock(com.facebook.buck.timing.DefaultClock) IOException(java.io.IOException) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Aggregations

DefaultClock (com.facebook.buck.timing.DefaultClock)20 Test (org.junit.Test)12 Clock (com.facebook.buck.timing.Clock)10 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 IOException (java.io.IOException)7 TestConsole (com.facebook.buck.testutil.TestConsole)6 BuckEventBus (com.facebook.buck.event.BuckEventBus)5 BuildId (com.facebook.buck.model.BuildId)5 Path (java.nio.file.Path)5 HttpdForTests (com.facebook.buck.testutil.integration.HttpdForTests)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Optional (java.util.Optional)4 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)3 ZipInspector (com.facebook.buck.testutil.integration.ZipInspector)3 NoOpCmdLineInterface (com.facebook.buck.util.versioncontrol.NoOpCmdLineInterface)3 ServletException (javax.servlet.ServletException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Request (org.eclipse.jetty.server.Request)3 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)3