use of java.nio.file.FileSystem in project buck by facebook.
the class EdenMountTest method getSha1DelegatesToThriftClient.
@Test
public void getSha1DelegatesToThriftClient() throws EdenError, TException {
List<MountInfo> mountInfos = ImmutableList.of(new MountInfo("/home/mbolin/src/buck", /* edenClientPath */
""));
EdenService.Client thriftClient = createMock(EdenService.Client.class);
expect(thriftClient.listMounts()).andReturn(mountInfos);
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path entry = fs.getPath("LICENSE");
HashCode hash = HashCode.fromString("2b8b815229aa8a61e483fb4ba0588b8b6c491890");
SHA1Result sha1Result = new SHA1Result();
sha1Result.setSha1(hash.asBytes());
expect(thriftClient.getSHA1("/home/mbolin/src/buck", ImmutableList.of("LICENSE"))).andReturn(ImmutableList.of(sha1Result));
replay(thriftClient);
EdenClient client = new EdenClient(thriftClient);
Path pathToBuck = fs.getPath("/home/mbolin/src/buck");
EdenMount mount = client.getMountFor(pathToBuck);
assertNotNull("Should find mount for path.", mount);
assertEquals(Sha1HashCode.fromHashCode(hash), mount.getSha1(entry));
verify(thriftClient);
}
use of java.nio.file.FileSystem in project buck by facebook.
the class EdenProjectFilesystemDelegateTest method computeSha1ForSymlinkUnderMountThatPointsToFileUnderMount.
@Test
public void computeSha1ForSymlinkUnderMountThatPointsToFileUnderMount() throws EdenError, TException, IOException {
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
// Create a symlink within the project root.
Path link = fs.getPath("/work/link");
Path target = fs.getPath("/work/target");
Files.createFile(target);
Files.createSymbolicLink(link, target);
// Eden will throw when the SHA-1 for the link is requested, but return a SHA-1 when the target
// is requested.
EdenMount mount = createMock(EdenMount.class);
expect(mount.getBindMounts()).andReturn(ImmutableList.of());
expect(mount.getPathRelativeToProjectRoot(link)).andReturn(Optional.of(fs.getPath("link")));
expect(mount.getPathRelativeToProjectRoot(target)).andReturn(Optional.of(fs.getPath("target")));
expect(mount.getSha1(fs.getPath("link"))).andThrow(new EdenError());
expect(mount.getSha1(fs.getPath("target"))).andReturn(DUMMY_SHA1);
replay(mount);
EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
assertEquals(DUMMY_SHA1, edenDelegate.computeSha1(link));
verify(mount);
}
use of java.nio.file.FileSystem in project buck by facebook.
the class EdenProjectFilesystemDelegateTest method computeSha1ForSymlinkUnderMountThatPointsToFileOutsideMount.
@Test
public void computeSha1ForSymlinkUnderMountThatPointsToFileOutsideMount() throws IOException, EdenError, TException {
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path root = fs.getPath(JIMFS_WORKING_DIRECTORY);
ProjectFilesystemDelegate delegate = new DefaultProjectFilesystemDelegate(root);
// Create a symlink within the project root.
Path link = fs.getPath("/work/link");
Path target = fs.getPath("/example");
Files.createFile(target);
byte[] bytes = new byte[] { 66, 85, 67, 75 };
Files.write(target, bytes);
Files.createSymbolicLink(link, target);
// Eden will throw when the SHA-1 for the link is requested, but return a SHA-1 when the target
// is requested.
EdenMount mount = createMock(EdenMount.class);
expect(mount.getBindMounts()).andReturn(ImmutableList.of());
expect(mount.getPathRelativeToProjectRoot(link)).andReturn(Optional.of(fs.getPath("link")));
expect(mount.getPathRelativeToProjectRoot(target)).andReturn(Optional.empty());
expect(mount.getSha1(fs.getPath("link"))).andThrow(new EdenError());
replay(mount);
EdenProjectFilesystemDelegate edenDelegate = new EdenProjectFilesystemDelegate(mount, delegate);
assertEquals("EdenProjectFilesystemDelegate.computeSha1() should return the SHA-1 of the target of " + "the symlink even though the target is outside of the EdenFS root.", Sha1HashCode.fromHashCode(Hashing.sha1().hashBytes(bytes)), edenDelegate.computeSha1(link));
verify(mount);
}
use of java.nio.file.FileSystem in project buck by facebook.
the class StackedDownloaderTest method createDownloadersForEachEntryInTheMavenRepositoriesSection.
@Test
public void createDownloadersForEachEntryInTheMavenRepositoriesSection() throws IOException {
boolean isWindows = Platform.detect() == Platform.WINDOWS;
Configuration configuration = isWindows ? Configuration.windows() : Configuration.unix();
FileSystem vfs = Jimfs.newFileSystem(configuration);
Path m2Root = vfs.getPath(jimfAbsolutePath("/home/user/.m2/repository"));
Files.createDirectories(m2Root);
// Set up a config so we expect to see both a local and a remote maven repo.
Path projectRoot = vfs.getPath(jimfAbsolutePath("/opt/local/src"));
Files.createDirectories(projectRoot);
BuckConfig config = FakeBuckConfig.builder().setFilesystem(new ProjectFilesystem(projectRoot)).setSections("[maven_repositories]", "local = " + m2Root.toString(), "central = https://repo1.maven.org/maven2").build();
Downloader downloader = StackedDownloader.createFromConfig(config, Optional.empty());
List<Downloader> downloaders = unpackDownloaders(downloader);
boolean seenRemote = false;
boolean seenLocal = false;
for (Downloader seen : downloaders) {
if (seen instanceof RemoteMavenDownloader) {
seenRemote = true;
} else if (seen instanceof OnDiskMavenDownloader) {
seenLocal = true;
}
}
assertTrue(seenLocal);
assertTrue(seenRemote);
}
use of java.nio.file.FileSystem in project buck by facebook.
the class AsynchronousDirectoryContentsCleanerTest method contentsOfTrashDirectoryCleanedAsynchronously.
@Test
public void contentsOfTrashDirectoryCleanedAsynchronously() throws Exception {
FileSystem vfs = Jimfs.newFileSystem(Configuration.unix());
Path dirToDelete = vfs.getPath("/tmp/fake-tmp-dir");
Path fooDir = dirToDelete.resolve("foo");
Path fooBarDir = fooDir.resolve("bar");
Files.createDirectories(fooBarDir.resolve("baz"));
Path fooBarBlechTxtFile = fooBarDir.resolve("blech.txt");
Files.write(fooBarBlechTxtFile, "hello world\n".getBytes(UTF_8));
AsynchronousDirectoryContentsCleaner cleaner = new AsynchronousDirectoryContentsCleaner(MoreExecutors.directExecutor());
assertThat(Files.exists(dirToDelete), is(true));
assertThat(Files.exists(fooBarDir), is(true));
assertThat(Files.exists(fooBarBlechTxtFile), is(true));
// This executes synchronously, since we passed in a direct executor above.
cleaner.startCleaningDirectory(dirToDelete);
assertThat(Files.exists(dirToDelete), is(true));
assertThat(Files.exists(fooBarDir), is(false));
assertThat(Files.exists(fooBarBlechTxtFile), is(false));
}
Aggregations