Search in sources :

Example 6 with CacheResult

use of com.facebook.buck.artifact_cache.CacheResult 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 CacheResult

use of com.facebook.buck.artifact_cache.CacheResult 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 CacheResult

use of com.facebook.buck.artifact_cache.CacheResult 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 9 with CacheResult

use of com.facebook.buck.artifact_cache.CacheResult 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)

Example 10 with CacheResult

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

the class BuckBuildLog method fromLogContents.

public static BuckBuildLog fromLogContents(Path root, List<String> logContents) {
    ImmutableMap.Builder<BuildTarget, BuildLogEntry> builder = ImmutableMap.builder();
    for (String line : logContents) {
        Matcher matcher = BUILD_LOG_FINISHED_RULE_REGEX.matcher(line);
        if (!matcher.matches()) {
            continue;
        }
        String buildTargetRaw = matcher.group("BuildTarget");
        BuildTarget buildTarget = BuildTargetFactory.newInstance(root, buildTargetRaw);
        String statusRaw = matcher.group("Status");
        BuildRuleStatus status = BuildRuleStatus.valueOf(statusRaw);
        String ruleKeyRaw = matcher.group("RuleKey");
        Sha1HashCode ruleKey = Sha1HashCode.of(ruleKeyRaw);
        CacheResult cacheResult = null;
        BuildRuleSuccessType successType = null;
        if (status == BuildRuleStatus.SUCCESS) {
            String cacheResultRaw = matcher.group("CacheResult");
            cacheResult = CacheResult.valueOf(cacheResultRaw);
            String successTypeRaw = matcher.group("SuccessType");
            successType = BuildRuleSuccessType.valueOf(successTypeRaw);
        }
        builder.put(buildTarget, new BuildLogEntry(status, Optional.ofNullable(successType), Optional.ofNullable(cacheResult), ruleKey));
    }
    return new BuckBuildLog(root, builder.build());
}
Also used : Matcher(java.util.regex.Matcher) BuildTarget(com.facebook.buck.model.BuildTarget) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) BuildRuleSuccessType(com.facebook.buck.rules.BuildRuleSuccessType) CacheResult(com.facebook.buck.artifact_cache.CacheResult) BuildRuleStatus(com.facebook.buck.rules.BuildRuleStatus) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

CacheResult (com.facebook.buck.artifact_cache.CacheResult)15 LazyPath (com.facebook.buck.io.LazyPath)12 BorrowablePath (com.facebook.buck.io.BorrowablePath)10 Path (java.nio.file.Path)10 ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)8 Test (org.junit.Test)7 RuleKey (com.facebook.buck.rules.RuleKey)5 InputStream (java.io.InputStream)4 SupportsDependencyFileRuleKey (com.facebook.buck.rules.keys.SupportsDependencyFileRuleKey)3 SupportsInputBasedRuleKey (com.facebook.buck.rules.keys.SupportsInputBasedRuleKey)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 BuildTarget (com.facebook.buck.model.BuildTarget)2 IOException (java.io.IOException)2 ArtifactInfo (com.facebook.buck.artifact_cache.ArtifactInfo)1 CacheResultType (com.facebook.buck.artifact_cache.CacheResultType)1 HttpArtifactCacheBinaryProtocol (com.facebook.buck.artifact_cache.HttpArtifactCacheBinaryProtocol)1 ArtifactCompressionEvent (com.facebook.buck.event.ArtifactCompressionEvent)1 BuckEvent (com.facebook.buck.event.BuckEvent)1 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)1