use of com.google.common.hash.Hasher in project buck by facebook.
the class DefaultFileHashCache method getDirHashCode.
private HashCodeAndFileType getDirHashCode(Path path) throws IOException {
Hasher hasher = Hashing.sha1().newHasher();
ImmutableSet<Path> children = PathHashing.hashPath(hasher, this, projectFilesystem, path);
return HashCodeAndFileType.ofDirectory(hasher.hash(), children);
}
use of com.google.common.hash.Hasher in project buck by facebook.
the class PathHashingTest method sameContentsSameNameHaveSameHash.
@Test
public void sameContentsSameNameHaveSameHash() throws IOException {
SettableFakeClock clock = new SettableFakeClock(1000, 0);
FakeProjectFilesystem filesystem1 = new FakeProjectFilesystem(clock);
filesystem1.touch(Paths.get("foo/bar.txt"));
FakeProjectFilesystem filesystem2 = new FakeProjectFilesystem(clock);
filesystem2.touch(Paths.get("foo/bar.txt"));
Hasher hasher1 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher1, fileHashCache, filesystem1, Paths.get("foo"));
Hasher hasher2 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher2, fileHashCache, filesystem2, Paths.get("foo"));
assertThat(hasher1.hash(), equalTo(hasher2.hash()));
}
use of com.google.common.hash.Hasher in project buck by facebook.
the class PathHashingTest method sameContentsDifferentNameHaveDifferentHashes.
@Test
public void sameContentsDifferentNameHaveDifferentHashes() throws IOException {
SettableFakeClock clock = new SettableFakeClock(1000, 0);
FakeProjectFilesystem filesystem1 = new FakeProjectFilesystem(clock);
filesystem1.touch(Paths.get("foo/bar.txt"));
FakeProjectFilesystem filesystem2 = new FakeProjectFilesystem(clock);
filesystem2.touch(Paths.get("foo/baz.txt"));
Hasher hasher1 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher1, fileHashCache, filesystem1, Paths.get("foo"));
Hasher hasher2 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher2, fileHashCache, filesystem2, Paths.get("foo"));
assertThat(hasher1.hash(), not(equalTo(hasher2.hash())));
}
use of com.google.common.hash.Hasher in project buck by facebook.
the class PathHashingTest method sameNameDifferentContentsHaveDifferentHashes.
@Test
public void sameNameDifferentContentsHaveDifferentHashes() throws IOException {
SettableFakeClock clock = new SettableFakeClock(1000, 0);
FakeProjectFilesystem filesystem1 = new FakeProjectFilesystem(clock);
filesystem1.touch(Paths.get("foo/bar.txt"));
FakeProjectFilesystem filesystem2 = new FakeProjectFilesystem(clock);
filesystem2.touch(Paths.get("foo/bar.txt"));
Hasher hasher1 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher1, fileHashCache, filesystem1, Paths.get("foo"));
Hasher hasher2 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher2, modifiedFileHashCache, filesystem2, Paths.get("foo"));
assertThat(hasher1.hash(), not(equalTo(hasher2.hash())));
}
use of com.google.common.hash.Hasher in project buck by facebook.
the class PathHashingTest method hashDoesNotDependOnFilesystemIterationOrder.
@Test
public void hashDoesNotDependOnFilesystemIterationOrder() throws IOException {
SettableFakeClock clock = new SettableFakeClock(1000, 0);
FakeProjectFilesystem filesystem1 = new FakeProjectFilesystem(clock);
filesystem1.touch(Paths.get("foo/foo.txt"));
filesystem1.touch(Paths.get("foo/bar.txt"));
filesystem1.touch(Paths.get("foo/baz.txt"));
FakeProjectFilesystem filesystem2 = new FakeProjectFilesystem(clock);
filesystem2.touch(Paths.get("foo/bar.txt"));
filesystem2.touch(Paths.get("foo/baz.txt"));
filesystem2.touch(Paths.get("foo/foo.txt"));
Hasher hasher1 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher1, fileHashCache, filesystem1, Paths.get("foo"));
Hasher hasher2 = Hashing.sha1().newHasher();
PathHashing.hashPath(hasher2, fileHashCache, filesystem2, Paths.get("foo"));
assertThat(hasher1.hash(), equalTo(hasher2.hash()));
}
Aggregations