use of com.facebook.buck.rules.RuleKeyAppendable in project buck by facebook.
the class RuleKeyCacheRecyclerTest method overflowWatchEventInvalidatesEverything.
@Test
public void overflowWatchEventInvalidatesEverything() {
DefaultRuleKeyCache<Void> cache = new DefaultRuleKeyCache<>();
// Create a rule key appendable with an input and cache it.
RuleKeyInput input1 = RuleKeyInput.of(FILESYSTEM, FILESYSTEM.getPath("input1"));
RuleKeyAppendable appendable1 = sink -> {
};
cache.get(appendable1, a -> new RuleKeyResult<>(null, ImmutableList.of(), ImmutableList.of(input1)));
// Create another rule key appendable with an input and cache it.
RuleKeyInput input2 = RuleKeyInput.of(FILESYSTEM, FILESYSTEM.getPath("input2"));
RuleKeyAppendable appendable2 = sink -> {
};
cache.get(appendable2, a -> new RuleKeyResult<>(null, ImmutableList.of(), ImmutableList.of(input2)));
RuleKeyCacheRecycler<Void> recycler = RuleKeyCacheRecycler.createAndRegister(EVENT_BUS, cache, ImmutableSet.of(FILESYSTEM));
// Verify that everything is cached before the overflow event.
assertTrue(cache.isCached(appendable1));
assertTrue(cache.isCached(appendable2));
// Send an overflow event and verify everything was invalidated.
recycler.onFilesystemChange(WatchEventsForTests.createOverflowEvent());
assertFalse(cache.isCached(appendable1));
assertFalse(cache.isCached(appendable2));
}
use of com.facebook.buck.rules.RuleKeyAppendable in project buck by facebook.
the class DefaultRuleKeyFactory method newBuilder.
private RuleKeyBuilder<RuleKeyResult<RuleKey>> newBuilder() {
return new RuleKeyBuilder<RuleKeyResult<RuleKey>>(ruleFinder, pathResolver, hashLoader) {
private final ImmutableList.Builder<Object> deps = ImmutableList.builder();
private final ImmutableList.Builder<RuleKeyInput> inputs = ImmutableList.builder();
@Override
protected RuleKeyBuilder<RuleKeyResult<RuleKey>> setBuildRule(BuildRule rule) {
// Record the `BuildRule` as an immediate dep.
deps.add(rule);
return setBuildRuleKey(DefaultRuleKeyFactory.this.build(rule));
}
private RuleKeyResult<RuleKey> calculateRuleKeyAppendableKey(RuleKeyAppendable appendable) {
RuleKeyBuilder<RuleKeyResult<RuleKey>> subKeyBuilder = newBuilder();
appendable.appendToRuleKey(subKeyBuilder);
return subKeyBuilder.build();
}
@Override
protected RuleKeyBuilder<RuleKeyResult<RuleKey>> setAppendableRuleKey(RuleKeyAppendable appendable) {
// Record the `RuleKeyAppendable` as an immediate dep.
deps.add(appendable);
// Calculate the rule key for the rule key appendable.
RuleKey ruleKey = ruleKeyCache.get(appendable, this::calculateRuleKeyAppendableKey);
return setAppendableRuleKey(ruleKey);
}
@Override
protected RuleKeyBuilder<RuleKeyResult<RuleKey>> setSourcePath(SourcePath sourcePath) throws IOException {
if (sourcePath instanceof BuildTargetSourcePath) {
return setSourcePathAsRule((BuildTargetSourcePath<?>) sourcePath);
} else {
// Add `PathSourcePath`s to our tracked inputs.
pathResolver.getPathSourcePath(sourcePath).ifPresent(path -> inputs.add(RuleKeyInput.of(path.getFilesystem(), path.getRelativePath())));
return setSourcePathDirectly(sourcePath);
}
}
@Override
protected RuleKeyBuilder<RuleKeyResult<RuleKey>> setNonHashingSourcePath(SourcePath sourcePath) {
try {
// changes to dependent rulekeys.
return setSourcePath(sourcePath);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public RuleKeyResult<RuleKey> build() {
return new RuleKeyResult<>(buildRuleKey(), deps.build(), inputs.build());
}
};
}
Aggregations