use of com.facebook.buck.rules.RuleKeyAppendable in project buck by facebook.
the class DefaultRuleKeyFactoryTest method testFactoryReportsInputsAndDependenciesToCacheForRuleKeyAppendable.
@Test
public void testFactoryReportsInputsAndDependenciesToCacheForRuleKeyAppendable() throws IOException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
NoopRuleKeyCache<RuleKey> noopRuleKeyCache = new NoopRuleKeyCache<>();
ProjectFilesystem filesystem = new FakeProjectFilesystem();
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(new RuleKeyFieldLoader(0), new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder, noopRuleKeyCache);
// Create a sample input.
PathSourcePath input = new PathSourcePath(filesystem, filesystem.getPath("input"));
filesystem.touch(input.getRelativePath());
// Create a sample dep rule.
BuildRule dep = new EmptyRule(BuildTargetFactory.newInstance("//:dep"));
// Create a sample dep appendable.
RuleKeyAppendable depAppendable = sink -> {
};
// Create a sample rule key appendable.
RuleKeyAppendable appendable = sink -> {
sink.setReflectively("input", input);
sink.setReflectively("dep", dep);
sink.setReflectively("depAppendable", depAppendable);
};
// Create a dummy build rule that uses the input.
BuildRule rule = new NoopBuildRule(new FakeBuildRuleParamsBuilder("//:target").setProjectFilesystem(filesystem).build()) {
@AddToRuleKey
private final RuleKeyAppendable appendableField = appendable;
};
// Build the rule key.
factory.build(rule);
// Verify the input was properly reported to the rule key cache.
RuleKeyResult<RuleKey> result = noopRuleKeyCache.results.get(appendable);
assertThat(result, Matchers.notNullValue());
assertThat(result.inputs, Matchers.containsInAnyOrder(RuleKeyInput.of(filesystem, input.getRelativePath())));
assertThat(result.deps, Matchers.containsInAnyOrder(dep, depAppendable));
}
use of com.facebook.buck.rules.RuleKeyAppendable in project buck by facebook.
the class DefaultRuleKeyFactoryTest method testFactoryReportsInputsAndDependenciesToCacheForBuildRule.
@Test
public void testFactoryReportsInputsAndDependenciesToCacheForBuildRule() throws IOException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
NoopRuleKeyCache<RuleKey> noopRuleKeyCache = new NoopRuleKeyCache<>();
ProjectFilesystem filesystem = new FakeProjectFilesystem();
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(new RuleKeyFieldLoader(0), new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder, noopRuleKeyCache);
// Create a sample input.
PathSourcePath input = new PathSourcePath(filesystem, filesystem.getPath("input"));
filesystem.touch(input.getRelativePath());
// Create a sample dep rule.
BuildRule dep = new EmptyRule(BuildTargetFactory.newInstance("//:dep"));
// Create a sample rule key appendable.
RuleKeyAppendable appendable = sink -> {
};
// Create a dummy build rule that uses the input.
BuildRule rule = new NoopBuildRule(new FakeBuildRuleParamsBuilder("//:target").setProjectFilesystem(filesystem).setDeclaredDeps(ImmutableSortedSet.of(dep)).build()) {
@AddToRuleKey
private final SourcePath inputField = input;
@AddToRuleKey
private final RuleKeyAppendable appendableField = appendable;
};
// Build the rule key.
factory.build(rule);
// Verify the input was properly reported to the rule key cache.
RuleKeyResult<RuleKey> result = noopRuleKeyCache.results.get(rule);
assertThat(result, Matchers.notNullValue());
assertThat(result.inputs, Matchers.containsInAnyOrder(RuleKeyInput.of(filesystem, input.getRelativePath())));
assertThat(result.deps, Matchers.containsInAnyOrder(dep, appendable));
}
use of com.facebook.buck.rules.RuleKeyAppendable in project buck by facebook.
the class RuleKeyCacheRecyclerTest method pathWatchEventDoesNotInvalidateDifferentInput.
@Test
public void pathWatchEventDoesNotInvalidateDifferentInput() {
DefaultRuleKeyCache<Void> cache = new DefaultRuleKeyCache<>();
RuleKeyInput input1 = RuleKeyInput.of(FILESYSTEM, FILESYSTEM.getPath("input1"));
RuleKeyAppendable appendable1 = sink -> {
};
RuleKeyInput input2 = RuleKeyInput.of(FILESYSTEM, FILESYSTEM.getPath("input2"));
RuleKeyAppendable appendable2 = sink -> {
};
cache.get(appendable1, a -> new RuleKeyResult<>(null, ImmutableList.of(), ImmutableList.of(input1)));
cache.get(appendable2, a -> new RuleKeyResult<>(null, ImmutableList.of(), ImmutableList.of(input2)));
RuleKeyCacheRecycler<Void> recycler = RuleKeyCacheRecycler.createAndRegister(EVENT_BUS, cache, ImmutableSet.of(FILESYSTEM));
recycler.onFilesystemChange(WatchEventsForTests.createPathEvent(input2.getPath(), StandardWatchEventKinds.ENTRY_MODIFY));
assertTrue(cache.isCached(appendable1));
assertFalse(cache.isCached(appendable2));
}
use of com.facebook.buck.rules.RuleKeyAppendable in project buck by facebook.
the class RuleKeyCacheRecyclerTest method getCacheWithDifferentActionGraphInstanceInvalidates.
@Test
public void getCacheWithDifferentActionGraphInstanceInvalidates() {
DefaultRuleKeyCache<Void> cache = new DefaultRuleKeyCache<>();
RuleKeyCacheRecycler<Void> recycler = RuleKeyCacheRecycler.createAndRegister(EVENT_BUS, cache, ImmutableSet.of(FILESYSTEM));
RuleKeyAppendable appendable = sink -> {
};
recycler.withRecycledCache(BUCK_EVENT_BUS, SETTINGS, c -> {
cache.get(appendable, a -> new RuleKeyResult<>(null, ImmutableList.of(), ImmutableList.of()));
});
assertTrue(cache.isCached(appendable));
recycler.withRecycledCache(BUCK_EVENT_BUS, new RuleKeyCacheRecycler.SettingsAffectingCache(RULE_KEY_SEED, new ActionGraph(ImmutableList.of())), c -> {
});
assertFalse(cache.isCached(appendable));
}
use of com.facebook.buck.rules.RuleKeyAppendable in project buck by facebook.
the class RuleKeyCacheRecyclerTest method getCacheWithDifferentRuleKeySeedInvalidates.
@Test
public void getCacheWithDifferentRuleKeySeedInvalidates() {
DefaultRuleKeyCache<Void> cache = new DefaultRuleKeyCache<>();
RuleKeyCacheRecycler<Void> recycler = RuleKeyCacheRecycler.createAndRegister(EVENT_BUS, cache, ImmutableSet.of(FILESYSTEM));
RuleKeyAppendable appendable = sink -> {
};
recycler.withRecycledCache(BUCK_EVENT_BUS, SETTINGS, c -> {
cache.get(appendable, a -> new RuleKeyResult<>(null, ImmutableList.of(), ImmutableList.of()));
});
assertTrue(cache.isCached(appendable));
recycler.withRecycledCache(BUCK_EVENT_BUS, new RuleKeyCacheRecycler.SettingsAffectingCache(RULE_KEY_SEED + 1, ACTION_GRAPH), c -> {
});
assertFalse(cache.isCached(appendable));
}
Aggregations