Search in sources :

Example 6 with ArtifactCache

use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.

the class ServedCacheIntegrationTest method whenNoCacheIsServedLookupsAreErrors.

@Test
public void whenNoCacheIsServedLookupsAreErrors() throws Exception {
    webServer = new WebServer(/* port */
    0, projectFilesystem, "/static/", MAPPER);
    webServer.updateAndStartIfNeeded(Optional.empty());
    ArtifactCache serverBackedCache = createArtifactCache(createMockLocalHttpCacheConfig(webServer.getPort().get()));
    LazyPath fetchedContents = LazyPath.ofInstance(tmpDir.newFile());
    CacheResult cacheResult = serverBackedCache.fetch(A_FILE_RULE_KEY, fetchedContents);
    assertThat(cacheResult.getType(), Matchers.equalTo(CacheResultType.ERROR));
}
Also used : CacheResult(com.facebook.buck.artifact_cache.CacheResult) LazyPath(com.facebook.buck.io.LazyPath) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Example 7 with ArtifactCache

use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.

the class ServedCacheIntegrationTest method testFetchFromServedDircache.

@Test
public void testFetchFromServedDircache() throws Exception {
    webServer = new WebServer(/* port */
    0, projectFilesystem, "/static/", MAPPER);
    webServer.updateAndStartIfNeeded(Optional.of(dirCache));
    ArtifactCache serverBackedCache = createArtifactCache(createMockLocalHttpCacheConfig(webServer.getPort().get()));
    Path fetchedContents = tmpDir.newFile();
    CacheResult cacheResult = serverBackedCache.fetch(A_FILE_RULE_KEY, LazyPath.ofInstance(fetchedContents));
    assertThat(cacheResult.getType().isSuccess(), Matchers.is(true));
    assertThat(cacheResult.getMetadata(), Matchers.equalTo(A_FILE_METADATA));
    assertThat(projectFilesystem.readFileIfItExists(fetchedContents).get(), Matchers.equalTo(A_FILE_DATA));
}
Also used : Path(java.nio.file.Path) BorrowablePath(com.facebook.buck.io.BorrowablePath) LazyPath(com.facebook.buck.io.LazyPath) CacheResult(com.facebook.buck.artifact_cache.CacheResult) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Example 8 with ArtifactCache

use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.

the class ServedCacheIntegrationTest method canSetArtifactCacheWithoutRestartingServer.

@Test
public void canSetArtifactCacheWithoutRestartingServer() throws Exception {
    webServer = new WebServer(/* port */
    0, projectFilesystem, "/static/", MAPPER);
    webServer.updateAndStartIfNeeded(Optional.empty());
    ArtifactCache serverBackedCache = createArtifactCache(createMockLocalHttpCacheConfig(webServer.getPort().get()));
    LazyPath fetchedContents = LazyPath.ofInstance(tmpDir.newFile());
    assertThat(serverBackedCache.fetch(A_FILE_RULE_KEY, fetchedContents).getType(), Matchers.equalTo(CacheResultType.ERROR));
    webServer.updateAndStartIfNeeded(Optional.of(dirCache));
    assertThat(serverBackedCache.fetch(A_FILE_RULE_KEY, fetchedContents).getType(), Matchers.equalTo(CacheResultType.HIT));
    webServer.updateAndStartIfNeeded(Optional.empty());
    assertThat(serverBackedCache.fetch(A_FILE_RULE_KEY, fetchedContents).getType(), Matchers.equalTo(CacheResultType.ERROR));
}
Also used : LazyPath(com.facebook.buck.io.LazyPath) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Example 9 with ArtifactCache

use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.

the class ServedCacheIntegrationTest method testExceptionDuringTheRead.

@Test
public void testExceptionDuringTheRead() throws Exception {
    ProjectFilesystem throwingStreamFilesystem = new ProjectFilesystem(tmpDir.getRoot()) {

        private boolean throwingStreamServed = false;

        @Override
        public InputStream newFileInputStream(Path pathRelativeToProjectRoot) throws IOException {
            InputStream inputStream = super.newFileInputStream(pathRelativeToProjectRoot);
            if (!throwingStreamServed && pathRelativeToProjectRoot.toString().contains("outgoing_rulekey")) {
                throwingStreamServed = true;
                return new ThrowAfterXBytesStream(inputStream, 10L);
            }
            return inputStream;
        }
    };
    webServer = new WebServer(/* port */
    0, throwingStreamFilesystem, "/static/", MAPPER);
    webServer.updateAndStartIfNeeded(Optional.of(dirCache));
    ArtifactCache serverBackedCache = createArtifactCache(createMockLocalHttpCacheConfig(webServer.getPort().get()));
    LazyPath fetchedContents = LazyPath.ofInstance(tmpDir.newFile());
    CacheResult cacheResult = serverBackedCache.fetch(A_FILE_RULE_KEY, fetchedContents);
    assertThat(cacheResult.getType(), Matchers.equalTo(CacheResultType.ERROR));
    // Try again to make sure the exception didn't kill the server.
    cacheResult = serverBackedCache.fetch(A_FILE_RULE_KEY, fetchedContents);
    assertThat(cacheResult.getType(), Matchers.equalTo(CacheResultType.HIT));
}
Also used : Path(java.nio.file.Path) BorrowablePath(com.facebook.buck.io.BorrowablePath) LazyPath(com.facebook.buck.io.LazyPath) FilterInputStream(java.io.FilterInputStream) InputStream(java.io.InputStream) CacheResult(com.facebook.buck.artifact_cache.CacheResult) LazyPath(com.facebook.buck.io.LazyPath) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Example 10 with ArtifactCache

use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.

the class ServedCacheIntegrationTest method testStoreAndFetchNotBorrowable.

@Test
public void testStoreAndFetchNotBorrowable() throws Exception {
    webServer = new WebServer(/* port */
    0, projectFilesystem, "/static/", MAPPER);
    webServer.updateAndStartIfNeeded(ArtifactCaches.newServedCache(createMockLocalConfig("[cache]", "dir = test-cache", "serve_local_cache = true", "served_local_cache_mode = readwrite"), projectFilesystem));
    ArtifactCache serverBackedCache = createArtifactCache(createMockLocalHttpCacheConfig(webServer.getPort().get()));
    RuleKey ruleKey = new RuleKey("00111222333444");
    ImmutableMap<String, String> metadata = ImmutableMap.of("some key", "some value");
    Path originalDataPath = tmpDir.newFile();
    String data = "you won't believe this!";
    projectFilesystem.writeContentsToPath(data, originalDataPath);
    LazyPath fetchedContents = LazyPath.ofInstance(tmpDir.newFile());
    CacheResult cacheResult = serverBackedCache.fetch(ruleKey, fetchedContents);
    assertThat(cacheResult.getType().isSuccess(), Matchers.is(false));
    serverBackedCache.store(ArtifactInfo.builder().addRuleKeys(ruleKey).setMetadata(metadata).build(), BorrowablePath.notBorrowablePath(originalDataPath));
    cacheResult = serverBackedCache.fetch(ruleKey, fetchedContents);
    assertThat(cacheResult.getType().isSuccess(), Matchers.is(true));
    assertThat(cacheResult.getMetadata(), Matchers.equalTo(metadata));
    assertThat(projectFilesystem.readFileIfItExists(fetchedContents.get()).get(), Matchers.equalTo(data));
}
Also used : Path(java.nio.file.Path) BorrowablePath(com.facebook.buck.io.BorrowablePath) LazyPath(com.facebook.buck.io.LazyPath) RuleKey(com.facebook.buck.rules.RuleKey) CacheResult(com.facebook.buck.artifact_cache.CacheResult) LazyPath(com.facebook.buck.io.LazyPath) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Aggregations

ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)21 Test (org.junit.Test)16 LazyPath (com.facebook.buck.io.LazyPath)13 Path (java.nio.file.Path)13 BorrowablePath (com.facebook.buck.io.BorrowablePath)9 RuleKey (com.facebook.buck.rules.RuleKey)9 CacheResult (com.facebook.buck.artifact_cache.CacheResult)7 BuckEventBus (com.facebook.buck.event.BuckEventBus)6 TestConsole (com.facebook.buck.testutil.TestConsole)5 NoopArtifactCache (com.facebook.buck.artifact_cache.NoopArtifactCache)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 Cell (com.facebook.buck.rules.Cell)4 IOException (java.io.IOException)4 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)3 FakeJavaPackageFinder (com.facebook.buck.jvm.java.FakeJavaPackageFinder)3 BuildId (com.facebook.buck.model.BuildId)3 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3 Before (org.junit.Before)3 AndroidDirectoryResolver (com.facebook.buck.android.AndroidDirectoryResolver)2