use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class ArtifactCachesTest method testCreateHttpCacheOnly.
@Test
public void testCreateHttpCacheOnly() throws Exception {
ArtifactCacheBuckConfig cacheConfig = ArtifactCacheBuckConfigTest.createFromText("[cache]", "mode = http");
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
ArtifactCache artifactCache = new ArtifactCaches(cacheConfig, buckEventBus, projectFilesystem, Optional.empty(), MoreExecutors.newDirectExecutorService(), Optional.empty()).newInstance();
assertThat(stripDecorators(artifactCache), Matchers.instanceOf(HttpArtifactCache.class));
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class ArtifactCachesTest method testCreateReadOnlyDirCacheExperimentalCache.
@Test
public void testCreateReadOnlyDirCacheExperimentalCache() throws Exception {
assumeThat(Platform.detect(), Matchers.not(Matchers.equalTo(Platform.WINDOWS)));
ArtifactCacheBuckConfig cacheConfig = ArtifactCacheBuckConfigTest.createFromText("[cache]", "mode = dir, http", "_exp_propagation = true", "_exp_propagation_force_control_group = true");
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
ArtifactCache artifactCache = new ArtifactCaches(cacheConfig, buckEventBus, projectFilesystem, Optional.empty(), MoreExecutors.newDirectExecutorService(), Optional.empty()).newInstance();
ArtifactCache result = stripDecorators(artifactCache);
assertThat(result, Matchers.instanceOf(RemoteArtifactsInLocalCacheArtifactCache.class));
RemoteArtifactsInLocalCacheArtifactCache experimentalCache = (RemoteArtifactsInLocalCacheArtifactCache) result;
assertThat(experimentalCache.getLocalCaches(), Matchers.instanceOf(MultiArtifactCache.class));
assertThat(experimentalCache.getLocalCaches().getArtifactCaches().get(0), Matchers.instanceOf(CacheDecorator.class));
CacheDecorator decorator = (CacheDecorator) experimentalCache.getLocalCaches().getArtifactCaches().get(0);
assertThat(decorator.getDelegate(), Matchers.instanceOf(DirArtifactCache.class));
assertThat(experimentalCache.getRemoteCaches(), Matchers.instanceOf(MultiArtifactCache.class));
assertThat(experimentalCache.getRemoteCaches().getArtifactCaches().get(0), Matchers.instanceOf(HttpArtifactCache.class));
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class DirArtifactCacheTest method testDeleteSome.
@Test
public void testDeleteSome() throws IOException {
Path cacheDir = tmpDir.newFolder();
Path fileW = cacheDir.resolve("11").resolve("11").resolve("w");
Path fileX = cacheDir.resolve("22").resolve("22").resolve("x");
Path fileY = cacheDir.resolve("33").resolve("33").resolve("y");
Path fileZ = cacheDir.resolve("44").resolve("44").resolve("z");
Files.createDirectories(fileW.getParent());
Files.createDirectories(fileX.getParent());
Files.createDirectories(fileY.getParent());
Files.createDirectories(fileZ.getParent());
dirArtifactCache = new DirArtifactCache("dir", new ProjectFilesystem(cacheDir), Paths.get("."), /* doStore */
true, /* maxCacheSizeBytes */
Optional.of(3L));
Files.write(fileW, "w".getBytes(UTF_8));
Files.write(fileX, "x".getBytes(UTF_8));
Files.write(fileY, "y".getBytes(UTF_8));
Files.write(fileZ, "z".getBytes(UTF_8));
Files.setAttribute(fileW, "lastAccessTime", FileTime.fromMillis(9000));
Files.setAttribute(fileX, "lastAccessTime", FileTime.fromMillis(0));
Files.setAttribute(fileY, "lastAccessTime", FileTime.fromMillis(1000));
Files.setAttribute(fileZ, "lastAccessTime", FileTime.fromMillis(2000));
// On some filesystems, setting creationTime silently fails. So don't test that here.
assertEquals(4, cacheDir.toFile().listFiles().length);
dirArtifactCache.deleteOldFiles();
List<Path> filesInCache = dirArtifactCache.getAllFilesInCache();
assertEquals(ImmutableSet.of(fileZ, fileW), ImmutableSet.copyOf(filesInCache));
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class DirArtifactCacheTest method testCacheFetchMiss.
@Test
public void testCacheFetchMiss() 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.of(0L));
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);
assertEquals(CacheResultType.MISS, dirArtifactCache.fetch(ruleKeyX, LazyPath.ofInstance(fileX)).getType());
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class DirArtifactCacheTest method testCacheCreation.
@Test
public void testCacheCreation() throws IOException {
Path cacheDir = tmpDir.newFolder();
dirArtifactCache = new DirArtifactCache("dir", new ProjectFilesystem(cacheDir), Paths.get("."), /* doStore */
true, /* maxCacheSizeBytes */
Optional.of(0L));
}
Aggregations