use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.
the class ExportFileTest method modifyingTheContentsOfTheFileChangesTheRuleKey.
@Test
public void modifyingTheContentsOfTheFileChangesTheRuleKey() throws Exception {
Path root = Files.createTempDirectory("root");
FakeProjectFilesystem filesystem = new FakeProjectFilesystem(root);
Path temp = Paths.get("example_file");
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder);
filesystem.writeContentsToPath("I like cheese", temp);
ExportFileBuilder builder = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//some:file")).setSrc(new PathSourcePath(filesystem, temp));
ExportFile rule = builder.build(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), filesystem);
RuleKey original = ruleKeyFactory.build(rule);
filesystem.writeContentsToPath("I really like cheese", temp);
// Create a new rule. The FileHashCache held by the existing rule will retain a reference to the
// previous content of the file, so we need to create an identical rule.
rule = builder.build(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), filesystem);
hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
resolver = new SourcePathResolver(ruleFinder);
ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder);
RuleKey refreshed = ruleKeyFactory.build(rule);
assertNotEquals(original, refreshed);
}
Aggregations