use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry in project buck by facebook.
the class DistBuildService method uploadMissingFiles.
public ListenableFuture<Void> uploadMissingFiles(final List<BuildJobStateFileHashes> fileHashes, ListeningExecutorService executorService) {
List<FileInfo> requiredFiles = new ArrayList<>();
for (BuildJobStateFileHashes filesystem : fileHashes) {
if (!filesystem.isSetEntries()) {
continue;
}
for (BuildJobStateFileHashEntry file : filesystem.entries) {
if (file.isSetRootSymLink()) {
LOG.info("File with path [%s] is a symlink. Skipping upload..", file.path.getPath());
continue;
} else if (file.isIsDirectory()) {
LOG.info("Path [%s] is a directory. Skipping upload..", file.path.getPath());
continue;
} else if (file.isPathIsAbsolute()) {
LOG.info("Path [%s] is absolute. Skipping upload..", file.path.getPath());
continue;
}
// TODO(shivanker): Eventually, we won't have file contents in BuildJobState.
// Then change this code to load file contents inline (only for missing files)
FileInfo fileInfo = new FileInfo();
fileInfo.setContent(file.getContents());
fileInfo.setContentHash(file.getHashCode());
requiredFiles.add(fileInfo);
}
}
return uploadMissingFilesFromList(requiredFiles, executorService);
}
use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry in project buck by facebook.
the class DistBuildFileHashesTest method recordsFileHashes.
@Test
public void recordsFileHashes() throws Exception {
SingleFileFixture f = new SingleFileFixture(tempDir);
List<BuildJobStateFileHashes> recordedHashes = f.distributedBuildFileHashes.getFileHashes();
assertThat(recordedHashes, Matchers.hasSize(3));
BuildJobStateFileHashes rootCellHashes = getRootCellHashes(recordedHashes);
assertThat(rootCellHashes.entries, Matchers.hasSize(1));
BuildJobStateFileHashEntry fileHashEntry = rootCellHashes.entries.get(0);
// It's intentional that we hardcode the path as a string here as we expect the thrift data
// to contain unix-formated paths.
assertThat(fileHashEntry.getPath().getPath(), Matchers.equalTo("src/A.java"));
assertFalse(fileHashEntry.isPathIsAbsolute());
assertFalse(fileHashEntry.isIsDirectory());
}
use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry 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.BuildJobStateFileHashEntry in project buck by facebook.
the class LocalFsContentsProviderTest method setUp.
@Before
public void setUp() {
cacheRootDir = tempDir.getRoot().toPath();
entry = new BuildJobStateFileHashEntry();
entry.setHashCode("1237987abc");
targetAbsPath = cacheRootDir.resolve("topspin.file.txt");
}
use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry 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());
}
}
Aggregations