use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class ContentAgnosticRuleKeyFactoryTest method ruleKeyDoesNotChangeWhenFileContentsChange.
@Test
public void ruleKeyDoesNotChangeWhenFileContentsChange() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Changing the contents of a file should not alter the rulekey.
RuleKey ruleKey1 = createRuleKey(filesystem, "output_file", "contents");
RuleKey ruleKey2 = createRuleKey(filesystem, "output_file", "diff_contents");
assertThat(ruleKey1, Matchers.equalTo(ruleKey2));
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class DirArtifactCacheTest method testNoStoreMisses.
@Test
public void testNoStoreMisses() throws IOException {
Path cacheDir = tmpDir.newFolder();
Path fileX = tmpDir.newFile("x");
Path fileY = tmpDir.newFile("y");
Path fileZ = tmpDir.newFile("z");
fileHashCache = new FakeFileHashCache(ImmutableMap.of(fileX, HashCode.fromInt(0), fileY, HashCode.fromInt(1), fileZ, HashCode.fromInt(2)));
dirArtifactCache = new DirArtifactCache("dir", new ProjectFilesystem(cacheDir), Paths.get("."), /* doStore */
false, /* maxCacheSizeBytes */
Optional.of(0L));
Files.write(fileX, "x".getBytes(UTF_8));
Files.write(fileY, "y".getBytes(UTF_8));
Files.write(fileZ, "z".getBytes(UTF_8));
BuildRule inputRuleX = new BuildRuleForTest(fileX);
BuildRule inputRuleY = new BuildRuleForTest(fileY);
BuildRule inputRuleZ = new BuildRuleForTest(fileZ);
assertFalse(inputRuleX.equals(inputRuleY));
assertFalse(inputRuleX.equals(inputRuleZ));
assertFalse(inputRuleY.equals(inputRuleZ));
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleResolver.addToIndex(inputRuleX);
ruleResolver.addToIndex(inputRuleY);
ruleResolver.addToIndex(inputRuleZ);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
DefaultRuleKeyFactory fakeRuleKeyFactory = new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder);
RuleKey ruleKeyX = fakeRuleKeyFactory.build(inputRuleX);
RuleKey ruleKeyY = fakeRuleKeyFactory.build(inputRuleY);
RuleKey ruleKeyZ = fakeRuleKeyFactory.build(inputRuleZ);
assertEquals(CacheResultType.MISS, dirArtifactCache.fetch(ruleKeyX, LazyPath.ofInstance(fileX)).getType());
assertEquals(CacheResultType.MISS, dirArtifactCache.fetch(ruleKeyY, LazyPath.ofInstance(fileY)).getType());
assertEquals(CacheResultType.MISS, dirArtifactCache.fetch(ruleKeyZ, LazyPath.ofInstance(fileZ)).getType());
dirArtifactCache.store(ArtifactInfo.builder().addRuleKeys(ruleKeyX).build(), BorrowablePath.notBorrowablePath(fileX));
dirArtifactCache.store(ArtifactInfo.builder().addRuleKeys(ruleKeyY).build(), BorrowablePath.notBorrowablePath(fileY));
dirArtifactCache.store(ArtifactInfo.builder().addRuleKeys(ruleKeyZ).build(), BorrowablePath.notBorrowablePath(fileZ));
Files.delete(fileX);
Files.delete(fileY);
Files.delete(fileZ);
assertEquals(CacheResultType.MISS, dirArtifactCache.fetch(ruleKeyX, LazyPath.ofInstance(fileX)).getType());
assertEquals(CacheResultType.MISS, dirArtifactCache.fetch(ruleKeyY, LazyPath.ofInstance(fileY)).getType());
assertEquals(CacheResultType.MISS, dirArtifactCache.fetch(ruleKeyZ, LazyPath.ofInstance(fileZ)).getType());
assertEquals(inputRuleX, new BuildRuleForTest(fileX));
assertEquals(inputRuleY, new BuildRuleForTest(fileY));
assertEquals(inputRuleZ, new BuildRuleForTest(fileZ));
assertEquals(0, cacheDir.toFile().listFiles().length);
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class DirArtifactCacheTest method testCacheStoresAndBorrowsPaths.
@Test
public void testCacheStoresAndBorrowsPaths() throws IOException {
Path cacheDir = tmpDir.newFolder();
Path fileX = tmpDir.newFile("x");
Path fileY = tmpDir.newFile("y");
fileHashCache = new FakeFileHashCache(ImmutableMap.of(fileX, HashCode.fromInt(0), fileY, HashCode.fromInt(1)));
dirArtifactCache = new DirArtifactCache("dir", new ProjectFilesystem(cacheDir), Paths.get("."), /* doStore */
true, /* maxCacheSizeBytes */
Optional.empty());
Files.write(fileX, "x".getBytes(UTF_8));
Files.write(fileY, "y".getBytes(UTF_8));
BuildRule inputRuleX = new BuildRuleForTest(fileX);
BuildRule inputRuleY = new BuildRuleForTest(fileY);
assertFalse(inputRuleX.equals(inputRuleY));
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleResolver.addToIndex(inputRuleX);
ruleResolver.addToIndex(inputRuleY);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
DefaultRuleKeyFactory fakeRuleKeyFactory = new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder);
RuleKey ruleKeyX = fakeRuleKeyFactory.build(inputRuleX);
RuleKey ruleKeyY = fakeRuleKeyFactory.build(inputRuleY);
dirArtifactCache.store(ArtifactInfo.builder().addRuleKeys(ruleKeyX).build(), BorrowablePath.borrowablePath(fileX));
dirArtifactCache.store(ArtifactInfo.builder().addRuleKeys(ruleKeyY).build(), BorrowablePath.notBorrowablePath(fileY));
assertThat(Files.exists(fileX), Matchers.is(false));
assertThat(Files.exists(fileY), Matchers.is(true));
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class DirArtifactCacheTest method testCacheStoreMultipleKeys.
@Test
public void testCacheStoreMultipleKeys() throws IOException {
Path cacheDir = tmpDir.newFolder();
Path fileX = tmpDir.newFile("x");
fileHashCache = new FakeFileHashCache(ImmutableMap.of(fileX, HashCode.fromInt(0)));
dirArtifactCache = new DirArtifactCache("dir", new ProjectFilesystem(cacheDir), Paths.get("."), /* doStore */
true, /* maxCacheSizeBytes */
Optional.empty());
Files.write(fileX, "x".getBytes(UTF_8));
RuleKey ruleKey1 = new RuleKey("aaaa");
RuleKey ruleKey2 = new RuleKey("bbbb");
dirArtifactCache.store(ArtifactInfo.builder().addRuleKeys(ruleKey1, ruleKey2).build(), BorrowablePath.notBorrowablePath(fileX));
// Test that artifact is available via both keys.
assertEquals(CacheResultType.HIT, dirArtifactCache.fetch(ruleKey1, LazyPath.ofInstance(fileX)).getType());
assertEquals(CacheResultType.HIT, dirArtifactCache.fetch(ruleKey2, LazyPath.ofInstance(fileX)).getType());
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class DirArtifactCacheTest method testCacheStoreOverwrite.
@Test
public void testCacheStoreOverwrite() throws IOException {
Path cacheDir = tmpDir.newFolder();
Path fileX = tmpDir.newFile("x");
fileHashCache = new FakeFileHashCache(ImmutableMap.of(fileX, HashCode.fromInt(0)));
dirArtifactCache = new DirArtifactCache("dir", new ProjectFilesystem(cacheDir), Paths.get("."), /* doStore */
true, /* maxCacheSizeBytes */
Optional.empty());
Files.write(fileX, "x".getBytes(UTF_8));
BuildRule inputRuleX = new BuildRuleForTest(fileX);
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleResolver.addToIndex(inputRuleX);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
RuleKey ruleKeyX = new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder).build(inputRuleX);
dirArtifactCache.store(ArtifactInfo.builder().addRuleKeys(ruleKeyX).build(), BorrowablePath.notBorrowablePath(fileX));
// Overwrite.
dirArtifactCache.store(ArtifactInfo.builder().addRuleKeys(ruleKeyX).build(), BorrowablePath.notBorrowablePath(fileX));
assertEquals(CacheResultType.HIT, dirArtifactCache.fetch(ruleKeyX, LazyPath.ofInstance(fileX)).getType());
assertEquals(inputRuleX, new BuildRuleForTest(fileX));
}
Aggregations