use of com.google.common.hash.HashCode in project buck by facebook.
the class TargetGraphHashingTest method twoNodeIndependentRootsTargetGraphHasExpectedHashes.
@Test
public void twoNodeIndependentRootsTargetGraphHasExpectedHashes() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
TargetNode<?, ?> nodeA = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//foo:lib"), HashCode.fromLong(64738), ImmutableSet.of(Paths.get("foo/FooLib.java")));
TargetNode<?, ?> nodeB = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//bar:lib"), HashCode.fromLong(49152), ImmutableSet.of(Paths.get("bar/BarLib.java")));
TargetGraph targetGraphA = TargetGraphFactory.newInstance(nodeA);
TargetGraph targetGraphB = TargetGraphFactory.newInstance(nodeB);
TargetGraph commonTargetGraph = TargetGraphFactory.newInstance(nodeA, nodeB);
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("bar/BarLib.java"), HashCode.fromString("123456")));
Map<BuildTarget, HashCode> resultsA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(nodeA)).hashTargetGraph();
Map<BuildTarget, HashCode> resultsB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(nodeB)).hashTargetGraph();
Map<BuildTarget, HashCode> commonResults = new TargetGraphHashing(eventBus, commonTargetGraph, fileHashCache, ImmutableList.of(nodeA, nodeB)).hashTargetGraph();
assertThat(resultsA, aMapWithSize(1));
assertThat(resultsA, hasKey(nodeA.getBuildTarget()));
assertThat(resultsB, aMapWithSize(1));
assertThat(resultsB, hasKey(nodeB.getBuildTarget()));
assertThat(commonResults, aMapWithSize(2));
assertThat(commonResults, hasKey(nodeA.getBuildTarget()));
assertThat(commonResults, hasKey(nodeB.getBuildTarget()));
assertThat(resultsA.get(nodeA.getBuildTarget()), equalTo(commonResults.get(nodeA.getBuildTarget())));
assertThat(resultsB.get(nodeB.getBuildTarget()), equalTo(commonResults.get(nodeB.getBuildTarget())));
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class ManifestTest method addEntryWithSourcePathsThatHaveSameRelativePaths.
@Test
public void addEntryWithSourcePathsThatHaveSameRelativePaths() 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 = new Manifest();
manifest1.addEntry(fileHashCache, key, RESOLVER, ImmutableSet.of(input1, input2), ImmutableSet.of(input1));
assertThat(manifest1.toMap(), Matchers.equalTo(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input1).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2))))));
Manifest manifest2 = new Manifest();
manifest2.addEntry(fileHashCache, key, RESOLVER, ImmutableSet.of(input1, input2), ImmutableSet.of(input2));
assertThat(manifest2.toMap(), Matchers.equalTo(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input2).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2))))));
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class ManifestTest method lookupMatch.
@Test
public void lookupMatch() throws IOException {
RuleKey key = new RuleKey("aa");
SourcePath input = new FakeSourcePath("input.h");
HashCode hashCode = HashCode.fromInt(20);
Manifest manifest = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), hashCode)));
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input), hashCode));
assertThat(manifest.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input)), Matchers.equalTo(Optional.of(key)));
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class ManifestTest method addEntryFromArchive.
@Test
public void addEntryFromArchive() throws IOException {
Manifest manifest = new Manifest();
RuleKey key = new RuleKey("aa");
SourcePath input = new ArchiveMemberSourcePath(new FakeSourcePath("somewhere/a.jar"), Paths.get("Member.class"));
HashCode hashCode = HashCode.fromInt(20);
FileHashCache fileHashCache = new FakeFileHashCache(new HashMap<>(), ImmutableMap.of(RESOLVER.getAbsoluteArchiveMemberPath(input), hashCode), new HashMap<>());
manifest.addEntry(fileHashCache, key, RESOLVER, ImmutableSet.of(input), ImmutableSet.of(input));
assertThat(manifest.toMap(), Matchers.equalTo(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativeArchiveMemberPath(input).toString(), hashCode))));
}
use of com.google.common.hash.HashCode in project buck by facebook.
the class ManifestTest method addEntry.
@Test
public void addEntry() throws IOException {
Manifest manifest = new Manifest();
RuleKey key = new RuleKey("aa");
SourcePath input = new FakeSourcePath("input.h");
HashCode hashCode = HashCode.fromInt(20);
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input), hashCode));
manifest.addEntry(fileHashCache, key, RESOLVER, ImmutableSet.of(input), ImmutableSet.of(input));
assertThat(manifest.toMap(), Matchers.equalTo(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), hashCode))));
}
Aggregations