use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.
the class MaterializerProjectFileHashCacheTest method testMaterializeDirectoryHelper.
private void testMaterializeDirectoryHelper(boolean materializeDuringPreloading, MaterializeFunction materializeFunction) throws IOException {
// Scenario:
// file hash entries for:
// /a - folder
// /a/b - folder
// /a/b/c - file
// /a/b/d - folder
// /a/e - file
// => preload: ensure all folders created and files touched
// => materialize(/a): ensure all folders and sub-directories/files created
assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
ProjectFilesystem projectFilesystem = new ProjectFilesystem(projectDir.getRoot().toPath());
Path pathDirA = projectFilesystem.resolve("a");
Path pathDirAb = projectFilesystem.resolve("a/b");
Path pathFileAbc = projectFilesystem.resolve("a/b/c");
Path pathDirAbd = projectFilesystem.resolve("a/b/d");
Path pathFileAe = projectFilesystem.resolve("a/e");
Path relativePathDirA = Paths.get("a");
Path relativePathDirAb = Paths.get("a/b");
Path relativePathFileAbc = Paths.get("a/b/c");
Path relativePathDirAbd = Paths.get("a/b/d");
Path relativePathFileAe = Paths.get("a/e");
BuildJobStateFileHashes fileHashes = new BuildJobStateFileHashes();
BuildJobStateFileHashEntry dirAFileHashEntry = new BuildJobStateFileHashEntry();
dirAFileHashEntry.setPath(unixPath(relativePathDirA));
dirAFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
dirAFileHashEntry.setIsDirectory(true);
dirAFileHashEntry.setChildren(ImmutableList.of(unixPath(relativePathDirAb), unixPath(relativePathFileAe)));
dirAFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
fileHashes.addToEntries(dirAFileHashEntry);
BuildJobStateFileHashEntry dirAbFileHashEntry = new BuildJobStateFileHashEntry();
dirAbFileHashEntry.setPath(unixPath(relativePathDirAb));
dirAbFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
dirAbFileHashEntry.setIsDirectory(true);
dirAbFileHashEntry.setChildren(ImmutableList.of(unixPath(relativePathFileAbc), unixPath(relativePathDirAbd)));
dirAbFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
fileHashes.addToEntries(dirAbFileHashEntry);
BuildJobStateFileHashEntry fileAbcFileHashEntry = new BuildJobStateFileHashEntry();
fileAbcFileHashEntry.setPath(unixPath(relativePathFileAbc));
fileAbcFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
fileAbcFileHashEntry.setContents(FILE_CONTENTS.getBytes(StandardCharsets.UTF_8));
fileAbcFileHashEntry.setIsDirectory(false);
fileAbcFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
fileHashes.addToEntries(fileAbcFileHashEntry);
BuildJobStateFileHashEntry dirAbdFileHashEntry = new BuildJobStateFileHashEntry();
dirAbdFileHashEntry.setPath(unixPath(relativePathDirAbd));
dirAbdFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
dirAbdFileHashEntry.setIsDirectory(true);
dirAbdFileHashEntry.setChildren(ImmutableList.of());
dirAbdFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
fileHashes.addToEntries(dirAbdFileHashEntry);
BuildJobStateFileHashEntry fileAeFileHashEntry = new BuildJobStateFileHashEntry();
fileAeFileHashEntry.setPath(unixPath(relativePathFileAe));
fileAeFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
fileAeFileHashEntry.setContents(FILE_CONTENTS_TWO.getBytes(StandardCharsets.UTF_8));
fileAeFileHashEntry.setIsDirectory(false);
fileAeFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
fileHashes.addToEntries(fileAeFileHashEntry);
InlineContentsProvider inlineProvider = new InlineContentsProvider();
ProjectFileHashCache mockFileHashCache = EasyMock.createNiceMock(ProjectFileHashCache.class);
expect(mockFileHashCache.getFilesystem()).andReturn(projectFilesystem).atLeastOnce();
replay(mockFileHashCache);
MaterializerProjectFileHashCache fileMaterializer = new MaterializerProjectFileHashCache(mockFileHashCache, fileHashes, inlineProvider);
assertFalse(pathDirA.toFile().exists());
assertFalse(pathDirAb.toFile().exists());
assertFalse(pathFileAbc.toFile().exists());
assertFalse(pathDirAbd.toFile().exists());
assertFalse(pathFileAe.toFile().exists());
materializeFunction.execute(fileMaterializer, pathDirA);
assertTrue(pathDirA.toFile().exists());
assertTrue(pathDirAb.toFile().exists());
assertTrue(pathFileAbc.toFile().exists());
assertTrue(pathDirAbd.toFile().exists());
assertTrue(pathFileAe.toFile().exists());
}
use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.
the class MaterializerProjectFileHashCacheTest method testSymlinkToFileWithinExternalDirectory.
public void testSymlinkToFileWithinExternalDirectory(HashCode fileHashEntryHashCode, HashCode actualHashCode, MaterializeFunction materializeFunction, int expectCallsToGetHashMethod) throws IOException {
// Scenario:
// path: /project/linktoexternaldir/externalfile
// symlink root: /project/linktoexternaldir -> /externalDir
// => check that /project/linktoexternaldir/externalfile -> /externalDir/externalfile
assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
ProjectFilesystem projectFilesystem = new ProjectFilesystem(projectDir.getRoot().toPath());
File externalFile = externalDir.newFile("externalfile");
Path symlinkRoot = projectFilesystem.resolve("linktoexternaldir");
Path relativeSymlinkRoot = Paths.get("linktoexternaldir");
// /project/linktoexternaldir/externalfile
Path symlink = symlinkRoot.resolve("externalfile");
Path relativeSymlink = projectFilesystem.getPathRelativeToProjectRoot(symlink).get();
BuildJobStateFileHashEntry symlinkFileHashEntry = new BuildJobStateFileHashEntry();
symlinkFileHashEntry.setRootSymLink(unixPath(relativeSymlinkRoot));
symlinkFileHashEntry.setRootSymLinkTarget(unixPath(externalDir.getRoot().toPath()));
symlinkFileHashEntry.setPath(unixPath(relativeSymlink));
symlinkFileHashEntry.setHashCode(fileHashEntryHashCode.toString());
BuildJobStateFileHashes fileHashes = new BuildJobStateFileHashes();
fileHashes.addToEntries(symlinkFileHashEntry);
FileContentsProvider mockFileProvider = EasyMock.createMock(FileContentsProvider.class);
ProjectFileHashCache mockFileHashCache = EasyMock.createNiceMock(ProjectFileHashCache.class);
expect(mockFileHashCache.getFilesystem()).andReturn(projectFilesystem).atLeastOnce();
if (expectCallsToGetHashMethod > 0) {
expect(mockFileHashCache.get(relativeSymlink)).andReturn(actualHashCode).times(expectCallsToGetHashMethod);
}
replay(mockFileHashCache);
MaterializerProjectFileHashCache fileMaterializer = new MaterializerProjectFileHashCache(mockFileHashCache, fileHashes, mockFileProvider);
assertFalse(symlink.toFile().exists());
materializeFunction.execute(fileMaterializer, relativeSymlink);
assertTrue(symlink.toFile().exists());
assertThat(symlink.toRealPath(), Matchers.equalTo(externalFile.toPath().toRealPath()));
verify(mockFileHashCache);
}
use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.
the class MaterializerProjectFileHashCacheTest method testEntryForRealFile.
private Path testEntryForRealFile(boolean materializeDuringPreloading, MaterializeFunction materializeFunction) throws IOException {
assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
ProjectFilesystem projectFilesystem = new ProjectFilesystem(projectDir.getRoot().toPath());
Path realFileAbsPath = projectFilesystem.resolve("realfile");
Path relativeRealFile = Paths.get("realfile");
BuildJobStateFileHashEntry realFileHashEntry = new BuildJobStateFileHashEntry();
realFileHashEntry.setPath(unixPath(relativeRealFile));
realFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
realFileHashEntry.setContents(FILE_CONTENTS.getBytes(StandardCharsets.UTF_8));
realFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
BuildJobStateFileHashes fileHashes = new BuildJobStateFileHashes();
fileHashes.addToEntries(realFileHashEntry);
InlineContentsProvider inlineProvider = new InlineContentsProvider();
ProjectFileHashCache mockFileHashCache = EasyMock.createNiceMock(ProjectFileHashCache.class);
expect(mockFileHashCache.getFilesystem()).andReturn(projectFilesystem).atLeastOnce();
replay(mockFileHashCache);
MaterializerProjectFileHashCache fileMaterializer = new MaterializerProjectFileHashCache(mockFileHashCache, fileHashes, inlineProvider);
materializeFunction.execute(fileMaterializer, realFileAbsPath);
return realFileAbsPath;
}
use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.
the class RecordingFileHashLoaderTest method testRecordsDirectSymlinkToFile.
@Test
public void testRecordsDirectSymlinkToFile() throws IOException {
// Scenario:
// /project/linktoexternal -> /externalDir/externalfile
// => create direct link: /project/linktoexternal -> /externalDir/externalfile
assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
ProjectFilesystem projectFilesystem = new ProjectFilesystem(projectDir.getRoot().toPath());
Path externalFile = externalDir.newFile("externalfile").toPath();
Path symlinkAbsPath = projectFilesystem.resolve("linktoexternal");
Path symlinkRelPath = projectFilesystem.relativize(symlinkAbsPath);
Files.createSymbolicLink(symlinkAbsPath, externalFile);
RecordedFileHashes recordedFileHashes = new RecordedFileHashes(0);
BuildJobStateFileHashes fileHashes = recordedFileHashes.getRemoteFileHashes();
FakeProjectFileHashCache delegateCache = new FakeProjectFileHashCache(projectFilesystem, ImmutableMap.of(symlinkRelPath, EXAMPLE_HASHCODE));
RecordingProjectFileHashCache recordingLoader = RecordingProjectFileHashCache.createForCellRoot(delegateCache, recordedFileHashes, new DistBuildConfig(FakeBuckConfig.builder().build()));
recordingLoader.get(symlinkRelPath);
assertThat(fileHashes.getEntries().size(), Matchers.equalTo(1));
BuildJobStateFileHashEntry fileHashEntry = fileHashes.getEntries().get(0);
assertTrue(fileHashEntry.isSetRootSymLink());
assertThat(fileHashEntry.getRootSymLink(), Matchers.equalTo((unixPath("linktoexternal"))));
assertTrue(fileHashEntry.isSetRootSymLink());
assertThat(fileHashEntry.getRootSymLinkTarget(), Matchers.equalTo((unixPath(externalFile.toRealPath().toString()))));
}
use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes in project buck by facebook.
the class DistBuildState method createRemoteFileHashCache.
public ProjectFileHashCache createRemoteFileHashCache(ProjectFileHashCache decoratedCache) {
BuildJobStateFileHashes remoteFileHashes = fileHashes.get(decoratedCache.getFilesystem());
if (remoteFileHashes == null) {
// decorated.
return decoratedCache;
}
ProjectFileHashCache remoteCache = DistBuildFileHashes.createFileHashCache(decoratedCache, remoteFileHashes);
return remoteCache;
}
Aggregations