use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.
the class ManifestTest method lookupHashMismatch.
@Test
public void lookupHashMismatch() throws IOException {
RuleKey key = new RuleKey("aa");
SourcePath input = new FakeSourcePath("input.h");
Manifest manifest = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), HashCode.fromInt(1))));
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input), HashCode.fromInt(2)));
assertThat(manifest.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input)), Matchers.equalTo(Optional.empty()));
}
use of com.facebook.buck.util.cache.FileHashCache 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.facebook.buck.util.cache.FileHashCache 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.facebook.buck.util.cache.FileHashCache 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))));
}
use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeysForOversizedRules.
@Test
public void ruleKeysForOversizedRules() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
final int sizeLimit = 200;
InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, sizeLimit);
// Create rule with inputs that make it go past the size limit, and verify the rule key factory
// doesn't create a rule key.
final int tooLargeRuleSize = 300;
assertThat(tooLargeRuleSize, Matchers.greaterThan(sizeLimit));
Path tooLargeInput = filesystem.getPath("too_large_input");
filesystem.writeBytesToPath(new byte[tooLargeRuleSize], tooLargeInput);
BuildRule tooLargeRule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:large_rule")).setOut("out").setSrc(new PathSourcePath(filesystem, tooLargeInput)).build(resolver, filesystem);
expectedException.expect(SizeLimiter.SizeLimitException.class);
factory.build(tooLargeRule);
}
Aggregations