Search in sources :

Example 1 with SHA1Result

use of com.facebook.eden.thrift.SHA1Result 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);
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) FileSystem(java.nio.file.FileSystem) MountInfo(com.facebook.eden.thrift.MountInfo) EdenService(com.facebook.eden.thrift.EdenService) SHA1Result(com.facebook.eden.thrift.SHA1Result) Test(org.junit.Test)

Example 2 with SHA1Result

use of com.facebook.eden.thrift.SHA1Result in project buck by facebook.

the class EdenMount method getSha1.

/**
   * @param entry is a path that is relative to {@link #getProjectRoot()}.
   */
public Sha1HashCode getSha1(Path entry) throws EdenError, TException {
    List<SHA1Result> results = client.get().getSHA1(mountPoint, ImmutableList.of(normalizePathArg(entry)));
    SHA1Result result = Iterables.getOnlyElement(results);
    if (result.getSetField() == SHA1Result.SHA1) {
        return Sha1HashCode.fromBytes(result.getSha1());
    } else {
        throw result.getError();
    }
}
Also used : SHA1Result(com.facebook.eden.thrift.SHA1Result)

Aggregations

SHA1Result (com.facebook.eden.thrift.SHA1Result)2 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)1 EdenService (com.facebook.eden.thrift.EdenService)1 MountInfo (com.facebook.eden.thrift.MountInfo)1 HashCode (com.google.common.hash.HashCode)1 FileSystem (java.nio.file.FileSystem)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1