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));
}
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));
}
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));
}
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));
}
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());
}
Aggregations