use of com.google.common.hash.HashCode in project buck by facebook.
the class ParserTest method twoBuildTargetHashCodesPopulatesCorrectly.
@Test
public void twoBuildTargetHashCodesPopulatesCorrectly() throws Exception {
tempDir.newFolder("foo");
Path testFooBuckFile = tempDir.newFile("foo/BUCK");
Files.write(testFooBuckFile, ("java_library(name = 'lib', visibility=['PUBLIC'])\n" + "java_library(name = 'lib2', visibility=['PUBLIC'])\n").getBytes(UTF_8));
BuildTarget fooLibTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
BuildTarget fooLib2Target = BuildTarget.builder(cellRoot, "//foo", "lib2").build();
ImmutableMap<BuildTarget, HashCode> hashes = buildTargetGraphAndGetHashCodes(parser, fooLibTarget, fooLib2Target);
assertNotNull(hashes.get(fooLibTarget));
assertNotNull(hashes.get(fooLib2Target));
assertNotEquals(hashes.get(fooLibTarget), hashes.get(fooLib2Target));
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class BuildInfoRecorderTest method testGetOutputHash.
@Test
public void testGetOutputHash() throws IOException {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
BuildInfoRecorder buildInfoRecorder = createBuildInfoRecorder(filesystem);
byte[] contents = "contents".getBytes();
Path file = Paths.get("file");
filesystem.writeBytesToPath(contents, file);
buildInfoRecorder.recordArtifact(file);
Path dir = Paths.get("dir");
filesystem.mkdirs(dir);
filesystem.writeBytesToPath(contents, dir.resolve("file1"));
filesystem.writeBytesToPath(contents, dir.resolve("file2"));
buildInfoRecorder.recordArtifact(dir);
fileHashCache.invalidateAll();
HashCode current = buildInfoRecorder.getOutputHash(fileHashCache);
// Test that getting the hash again results in the same hashcode.
fileHashCache.invalidateAll();
assertEquals(current, buildInfoRecorder.getOutputHash(fileHashCache));
// Verify that changing a file changes the hash.
filesystem.writeContentsToPath("something else", file);
fileHashCache.invalidateAll();
HashCode updated = buildInfoRecorder.getOutputHash(fileHashCache);
assertNotEquals(current, updated);
// Verify that changing a file under a directory changes the hash.
filesystem.writeContentsToPath("something else", dir.resolve("file1"));
current = updated;
fileHashCache.invalidateAll();
updated = buildInfoRecorder.getOutputHash(fileHashCache);
assertNotEquals(current, updated);
// Test that adding a file updates the hash.
Path added = Paths.get("added");
filesystem.writeBytesToPath(contents, added);
buildInfoRecorder.recordArtifact(added);
current = updated;
fileHashCache.invalidateAll();
updated = buildInfoRecorder.getOutputHash(fileHashCache);
assertNotEquals(current, updated);
// Test that adding a file under a recorded directory updates the hash.
Path addedUnderDir = dir.resolve("added");
filesystem.writeBytesToPath(contents, addedUnderDir);
current = updated;
fileHashCache.invalidateAll();
updated = buildInfoRecorder.getOutputHash(fileHashCache);
assertNotEquals(current, updated);
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class ManifestTest method lookupMatchWithSourcePathsThatHaveSameRelativePaths.
@Test
public void lookupMatchWithSourcePathsThatHaveSameRelativePaths() throws IOException {
RuleKey key = new RuleKey("aa");
Path tmp1 = Files.createTempDirectory("tmp1");
ProjectFilesystem filesystem1 = new FakeProjectFilesystem(tmp1);
SourcePath input1 = new PathSourcePath(filesystem1, Paths.get("input.h"));
HashCode hashCode1 = HashCode.fromInt(1);
Path tmp2 = Files.createTempDirectory("tmp2");
ProjectFilesystem filesystem2 = new FakeProjectFilesystem(tmp2);
SourcePath input2 = new PathSourcePath(filesystem2, Paths.get("input.h"));
HashCode hashCode2 = HashCode.fromInt(1);
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input1), hashCode1, RESOLVER.getAbsolutePath(input2), hashCode2));
Manifest manifest1 = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input1).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2)))));
assertThat(manifest1.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input1, input2)), Matchers.equalTo(Optional.of(key)));
Manifest manifest2 = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input2).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2)))));
assertThat(manifest2.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input1, input2)), Matchers.equalTo(Optional.of(key)));
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class TargetGraphHashingTest method hashChangesWhenSrcContentChanges.
@Test
public void hashChangesWhenSrcContentChanges() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
TargetNode<?, ?> node = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//foo:lib"), HashCode.fromLong(64738), ImmutableSet.of(Paths.get("foo/FooLib.java")));
TargetGraph targetGraph = TargetGraphFactory.newInstance(node);
FileHashCache baseCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef")));
FileHashCache modifiedCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abc1ef")));
Map<BuildTarget, HashCode> baseResult = new TargetGraphHashing(eventBus, targetGraph, baseCache, ImmutableList.of(node)).hashTargetGraph();
Map<BuildTarget, HashCode> modifiedResult = new TargetGraphHashing(eventBus, targetGraph, modifiedCache, ImmutableList.of(node)).hashTargetGraph();
assertThat(baseResult, aMapWithSize(1));
assertThat(baseResult, hasKey(node.getBuildTarget()));
assertThat(modifiedResult, aMapWithSize(1));
assertThat(modifiedResult, hasKey(node.getBuildTarget()));
assertThat(modifiedResult.get(node.getBuildTarget()), not(equalTo(baseResult.get(node.getBuildTarget()))));
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class TargetGraphHashingTest method hashChangesForDependentNodeWhenDepsChange.
@Test
public void hashChangesForDependentNodeWhenDepsChange() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
BuildTarget nodeTarget = BuildTargetFactory.newInstance("//foo:lib");
BuildTarget depTarget = BuildTargetFactory.newInstance("//dep:lib");
TargetGraph targetGraphA = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(64738));
TargetGraph targetGraphB = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(84552));
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("dep/DepLib.java"), HashCode.fromString("123456")));
Map<BuildTarget, HashCode> resultA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(targetGraphA.get(nodeTarget))).hashTargetGraph();
Map<BuildTarget, HashCode> resultB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(targetGraphB.get(nodeTarget))).hashTargetGraph();
assertThat(resultA, aMapWithSize(2));
assertThat(resultA, hasKey(nodeTarget));
assertThat(resultA, hasKey(depTarget));
assertThat(resultB, aMapWithSize(2));
assertThat(resultB, hasKey(nodeTarget));
assertThat(resultB, hasKey(depTarget));
assertThat(resultA.get(nodeTarget), not(equalTo(resultB.get(nodeTarget))));
assertThat(resultA.get(depTarget), not(equalTo(resultB.get(depTarget))));
}
Aggregations