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