Search in sources :

Example 6 with BuildJobStateFileHashes

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.

the class DistBuildServiceTest method canUploadFiles.

@Test
public void canUploadFiles() throws Exception {
    final List<Boolean> fileExistence = Arrays.asList(true, false, true);
    Capture<FrontendRequest> containsRequest = EasyMock.newCapture();
    FrontendResponse containsResponse = new FrontendResponse();
    containsResponse.setType(FrontendRequestType.CAS_CONTAINS);
    CASContainsResponse casContainsResponse = new CASContainsResponse();
    casContainsResponse.setExists(fileExistence);
    containsResponse.setCasContainsResponse(casContainsResponse);
    containsResponse.setWasSuccessful(true);
    EasyMock.expect(frontendService.makeRequest(EasyMock.capture(containsRequest))).andReturn(containsResponse).once();
    Capture<FrontendRequest> storeRequest = EasyMock.newCapture();
    FrontendResponse storeResponse = new FrontendResponse();
    storeResponse.setType(FrontendRequestType.STORE_LOCAL_CHANGES);
    storeResponse.setWasSuccessful(true);
    EasyMock.expect(frontendService.makeRequest(EasyMock.capture(storeRequest))).andReturn(storeResponse).once();
    EasyMock.replay(frontendService);
    BuildJobStateFileHashEntry[] files = new BuildJobStateFileHashEntry[3];
    for (int i = 0; i < 3; i++) {
        files[i] = new BuildJobStateFileHashEntry();
        files[i].setHashCode(Integer.toString(i));
        files[i].setContents(("content" + Integer.toString(i)).getBytes());
        files[i].setPath(new PathWithUnixSeparators("/tmp/" + i));
    }
    List<BuildJobStateFileHashes> fileHashes = new ArrayList<>();
    fileHashes.add(new BuildJobStateFileHashes());
    fileHashes.get(0).setCellIndex(0);
    fileHashes.get(0).setEntries(new ArrayList<BuildJobStateFileHashEntry>());
    fileHashes.get(0).getEntries().add(files[0]);
    fileHashes.get(0).getEntries().add(files[1]);
    fileHashes.add(new BuildJobStateFileHashes());
    fileHashes.get(1).setCellIndex(1);
    fileHashes.get(1).setEntries(new ArrayList<BuildJobStateFileHashEntry>());
    fileHashes.get(1).getEntries().add(files[2]);
    distBuildService.uploadMissingFiles(fileHashes, executor).get();
    Assert.assertEquals(containsRequest.getValue().getType(), FrontendRequestType.CAS_CONTAINS);
    Assert.assertTrue(containsRequest.getValue().isSetCasContainsRequest());
    Assert.assertTrue(containsRequest.getValue().getCasContainsRequest().isSetContentSha1s());
    Assert.assertEquals(new HashSet<String>(containsRequest.getValue().getCasContainsRequest().getContentSha1s()), new HashSet<String>(Arrays.asList("0", "1", "2")));
    Assert.assertEquals(storeRequest.getValue().getType(), FrontendRequestType.STORE_LOCAL_CHANGES);
    Assert.assertTrue(storeRequest.getValue().isSetStoreLocalChangesRequest());
    Assert.assertTrue(storeRequest.getValue().getStoreLocalChangesRequest().isSetFiles());
    Assert.assertEquals(storeRequest.getValue().getStoreLocalChangesRequest().getFiles().size(), 1);
    Assert.assertEquals(storeRequest.getValue().getStoreLocalChangesRequest().getFiles().get(0).getContentHash(), "1");
    Assert.assertTrue(Arrays.equals(storeRequest.getValue().getStoreLocalChangesRequest().getFiles().get(0).getContent(), "content1".getBytes()));
}
Also used : ArrayList(java.util.ArrayList) PathWithUnixSeparators(com.facebook.buck.distributed.thrift.PathWithUnixSeparators) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) CASContainsResponse(com.facebook.buck.distributed.thrift.CASContainsResponse) Test(org.junit.Test)

Example 7 with BuildJobStateFileHashes

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.

the class DistBuildFileHashesTest method readsHashesForArchiveMembers.

@Test
public void readsHashesForArchiveMembers() throws Exception {
    try (ArchiveFilesFixture f = ArchiveFilesFixture.create(archiveTempDir)) {
        List<BuildJobStateFileHashes> recordedHashes = f.distributedBuildFileHashes.getFileHashes();
        ProjectFilesystem readProjectFilesystem = new ProjectFilesystem(tempDir.newFolder("read_hashes").toPath().toRealPath());
        ProjectFileHashCache mockCache = EasyMock.createMock(ProjectFileHashCache.class);
        EasyMock.expect(mockCache.getFilesystem()).andReturn(readProjectFilesystem).anyTimes();
        EasyMock.replay(mockCache);
        ProjectFileHashCache fileHashCache = DistBuildFileHashes.createFileHashCache(mockCache, recordedHashes.get(0));
        ArchiveMemberPath archiveMemberPath = ArchiveMemberPath.of(readProjectFilesystem.resolve(f.archivePath), f.archiveMemberPath);
        assertThat(fileHashCache.willGet(archiveMemberPath), Matchers.is(true));
        assertThat(fileHashCache.get(archiveMemberPath), Matchers.is(f.archiveMemberHash));
    }
}
Also used : BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 8 with BuildJobStateFileHashes

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.

the class DistBuildFileHashesTest method recordsArchiveHashes.

@Test
public void recordsArchiveHashes() throws Exception {
    try (ArchiveFilesFixture f = ArchiveFilesFixture.create(archiveTempDir)) {
        List<BuildJobStateFileHashes> recordedHashes = f.distributedBuildFileHashes.getFileHashes();
        assertThat(recordedHashes, Matchers.hasSize(3));
        BuildJobStateFileHashes hashes = getRootCellHashes(recordedHashes);
        assertThat(hashes.entries, Matchers.hasSize(1));
        BuildJobStateFileHashEntry fileHashEntry = hashes.entries.get(0);
        assertThat(fileHashEntry.getPath().getPath(), Matchers.equalTo("src/archive.jar"));
        assertTrue(fileHashEntry.isSetArchiveMemberPath());
        assertThat(fileHashEntry.getArchiveMemberPath(), Matchers.equalTo("Archive.class"));
        assertFalse(fileHashEntry.isPathIsAbsolute());
        assertFalse(fileHashEntry.isIsDirectory());
    }
}
Also used : BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) Test(org.junit.Test)

Example 9 with BuildJobStateFileHashes

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.

the class DistBuildFileHashesTest method worksCrossCell.

@Test
public void worksCrossCell() throws Exception {
    final Fixture f = new Fixture(tempDir) {

        @Override
        protected void setUpRules(BuildRuleResolver resolver, SourcePathResolver sourcePathResolver) throws Exception {
            Path firstPath = javaFs.getPath("src", "A.java");
            projectFilesystem.createParentDirs(firstPath);
            projectFilesystem.writeContentsToPath("public class A {}", firstPath);
            Path secondPath = secondJavaFs.getPath("B.java");
            secondProjectFilesystem.writeContentsToPath("public class B {}", secondPath);
            JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance(projectFilesystem, "//:java_lib_at_root"), projectFilesystem).addSrc(firstPath).build(resolver, projectFilesystem);
            JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance(secondProjectFilesystem, "//:java_lib_at_secondary"), secondProjectFilesystem).addSrc(secondPath).build(resolver, secondProjectFilesystem);
        }

        @Override
        protected BuckConfig createBuckConfig() {
            return FakeBuckConfig.builder().setSections("[repositories]", "second_repo = " + secondProjectFilesystem.getRootPath().toAbsolutePath()).build();
        }
    };
    List<BuildJobStateFileHashes> recordedHashes = f.distributedBuildFileHashes.getFileHashes();
    assertThat(recordedHashes, Matchers.hasSize(3));
    BuildJobStateFileHashes rootCellHash = getRootCellHashes(recordedHashes);
    Assert.assertEquals(1, rootCellHash.getEntriesSize());
    Assert.assertEquals("src/A.java", rootCellHash.getEntries().get(0).getPath().getPath());
    BuildJobStateFileHashes secondaryCellHashes = getCellHashesByIndex(recordedHashes, 1);
    Assert.assertEquals(1, secondaryCellHashes.getEntriesSize());
    Assert.assertEquals("B.java", secondaryCellHashes.getEntries().get(0).getPath().getPath());
}
Also used : ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 10 with BuildJobStateFileHashes

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.

the class DistBuildServiceTest method canUploadTargetGraph.

@Test
public void canUploadTargetGraph() throws IOException, ExecutionException, InterruptedException {
    Capture<FrontendRequest> request = EasyMock.newCapture();
    FrontendResponse response = new FrontendResponse();
    response.setType(FrontendRequestType.STORE_BUILD_GRAPH);
    response.setWasSuccessful(true);
    EasyMock.expect(frontendService.makeRequest(EasyMock.capture(request))).andReturn(response).once();
    EasyMock.replay(frontendService);
    BuildJobState buildJobState = new BuildJobState();
    List<BuildJobStateFileHashes> fileHashes = new ArrayList<>();
    buildJobState.setFileHashes(fileHashes);
    BuildJobStateTargetGraph graph = new BuildJobStateTargetGraph();
    graph.setNodes(new ArrayList<BuildJobStateTargetNode>());
    BuildJobStateTargetNode node1 = new BuildJobStateTargetNode();
    node1.setRawNode("node1");
    BuildJobStateTargetNode node2 = new BuildJobStateTargetNode();
    node2.setRawNode("node1");
    graph.addToNodes(node1);
    graph.addToNodes(node2);
    buildJobState.setTargetGraph(graph);
    StampedeId stampedeId = new StampedeId();
    stampedeId.setId("check-id");
    distBuildService.uploadTargetGraph(buildJobState, stampedeId, executor).get();
    Assert.assertTrue(request.getValue().isSetType());
    Assert.assertEquals(request.getValue().getType(), FrontendRequestType.STORE_BUILD_GRAPH);
    Assert.assertTrue(request.getValue().isSetStoreBuildGraphRequest());
    Assert.assertTrue(request.getValue().getStoreBuildGraphRequest().isSetStampedeId());
    Assert.assertEquals(request.getValue().getStoreBuildGraphRequest().getStampedeId(), stampedeId);
    Assert.assertTrue(request.getValue().getStoreBuildGraphRequest().isSetBuildGraph());
    BuildJobState sentState = BuildJobStateSerializer.deserialize(request.getValue().getStoreBuildGraphRequest().getBuildGraph());
    Assert.assertTrue(buildJobState.equals(sentState));
}
Also used : BuildJobStateTargetNode(com.facebook.buck.distributed.thrift.BuildJobStateTargetNode) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) BuildJobStateTargetGraph(com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph) StampedeId(com.facebook.buck.distributed.thrift.StampedeId) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) ArrayList(java.util.ArrayList) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) Test(org.junit.Test)

Aggregations

BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)21 Test (org.junit.Test)14 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)12 BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)11 ProjectFileHashCache (com.facebook.buck.util.cache.ProjectFileHashCache)9 Path (java.nio.file.Path)9 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)6 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)4 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)3 FakeProjectFileHashCache (com.facebook.buck.testutil.FakeProjectFileHashCache)3 ArrayList (java.util.ArrayList)3 BuckConfig (com.facebook.buck.cli.BuckConfig)2 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)2 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)2 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)2 Parser (com.facebook.buck.parser.Parser)2 ParserConfig (com.facebook.buck.parser.ParserConfig)2 ArchiveMemberSourcePath (com.facebook.buck.rules.ArchiveMemberSourcePath)2 Cell (com.facebook.buck.rules.Cell)2 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)2