Search in sources :

Example 66 with ProjectFilesystem

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));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Test(org.junit.Test)

Example 67 with ProjectFilesystem

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));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Test(org.junit.Test)

Example 68 with ProjectFilesystem

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));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) BorrowablePath(com.facebook.buck.io.BorrowablePath) LazyPath(com.facebook.buck.io.LazyPath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 69 with ProjectFilesystem

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());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) BorrowablePath(com.facebook.buck.io.BorrowablePath) LazyPath(com.facebook.buck.io.LazyPath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 70 with ProjectFilesystem

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));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) BorrowablePath(com.facebook.buck.io.BorrowablePath) LazyPath(com.facebook.buck.io.LazyPath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)654 Test (org.junit.Test)542 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)401 Path (java.nio.file.Path)324 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)207 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)204 BuildTarget (com.facebook.buck.model.BuildTarget)203 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)126 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)121 TargetGraph (com.facebook.buck.rules.TargetGraph)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)96 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)92 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)90 SourcePath (com.facebook.buck.rules.SourcePath)79 ExecutionContext (com.facebook.buck.step.ExecutionContext)67 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)67 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)63 BuildRule (com.facebook.buck.rules.BuildRule)56 RuleKey (com.facebook.buck.rules.RuleKey)43 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)42