use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.
the class CacheCommandTest method testRunCommandAndFetchArtifactsUnsuccessfully.
@Test
public void testRunCommandAndFetchArtifactsUnsuccessfully() throws IOException, InterruptedException {
final String ruleKeyHash = "b64009ae3762a42a1651c139ec452f0d18f48e21";
ArtifactCache cache = createMock(ArtifactCache.class);
expect(cache.fetch(eq(new RuleKey(ruleKeyHash)), isA(LazyPath.class))).andReturn(CacheResult.miss());
TestConsole console = new TestConsole();
console.printErrorText("Failed to retrieve an artifact with id " + ruleKeyHash + ".");
CommandRunnerParams commandRunnerParams = CommandRunnerParamsForTesting.builder().setConsole(console).setArtifactCache(cache).build();
replayAll();
CacheCommand cacheCommand = new CacheCommand();
cacheCommand.setArguments(ImmutableList.of(ruleKeyHash));
int exitCode = cacheCommand.run(commandRunnerParams);
assertEquals(1, exitCode);
}
use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.
the class BuildInfoRecorderIntegrationTest method testPerformUploadToArtifactCache.
@Test
public void testPerformUploadToArtifactCache() throws IOException, InterruptedException {
BuildInfoRecorder buildInfoRecorder = createBuildInfoRecorder(new FakeProjectFilesystem() {
@Override
public void createZip(Collection<Path> pathsToIncludeInZip, Path out) throws IOException {
// For this test, nothing really cares about the content, so just write out the name.
writeBytesToPath(out.toString().getBytes(), out);
}
});
Path cacheDir = Files.createTempDirectory("root");
ArtifactCache artifactCache = TestArtifactCaches.createDirCacheForTest(cacheDir, Paths.get("cache"));
buildInfoRecorder.performUploadToArtifactCache(ImmutableSet.of(new RuleKey(RULE_KEY)), artifactCache, new BuckEventBus(new DefaultClock(), new BuildId()));
assertTrue(cacheDir.resolve(DirArtifactCacheTestUtil.getPathForRuleKey(artifactCache, new RuleKey(RULE_KEY), Optional.empty())).toFile().exists());
}
use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.
the class ServedCacheIntegrationTest method testMultipleNamedCaches.
@Test
public void testMultipleNamedCaches() throws Exception {
LazyPath fetchedContents = LazyPath.ofInstance(tmpDir.newFile());
final RuleKey bFileRuleKey = new RuleKey("baadbeef");
webServer = new WebServer(/* port */
0, projectFilesystem, "/static/", MAPPER);
webServer.updateAndStartIfNeeded(Optional.of(dirCache));
ArtifactCache secondCache = new ArtifactCache() {
@Override
public CacheResult fetch(RuleKey ruleKey, LazyPath output) {
if (ruleKey.equals(bFileRuleKey)) {
try {
projectFilesystem.writeContentsToPath("second", output.get());
} catch (IOException e) {
throw new RuntimeException(e);
}
return CacheResult.hit("secondCache");
}
return CacheResult.miss();
}
@Override
public ListenableFuture<Void> store(ArtifactInfo info, BorrowablePath output) {
return Futures.immediateFuture(null);
}
@Override
public boolean isStoreSupported() {
return true;
}
@Override
public void close() {
// Intentional no-op.
}
};
assertThat(secondCache.fetch(A_FILE_RULE_KEY, fetchedContents).getType(), Matchers.equalTo(CacheResultType.MISS));
assertThat(secondCache.fetch(bFileRuleKey, fetchedContents).getType(), Matchers.equalTo(CacheResultType.HIT));
WebServer secondWebServer = new WebServer(/* port */
0, projectFilesystem, "/static/", MAPPER);
try {
secondWebServer.updateAndStartIfNeeded(Optional.of(secondCache));
ArtifactCacheBuckConfig mutltiCacheConfig = createMockLocalConfig("[cache]", "mode = http", "http_cache_names = one, two", "[cache#two]", String.format("http_url = http://127.0.0.1:%d/", secondWebServer.getPort().get()), "[cache#one]", String.format("http_url = http://127.0.0.1:%d/", webServer.getPort().get()));
ArtifactCache serverBackedCache = createArtifactCache(mutltiCacheConfig);
assertThat(serverBackedCache.fetch(A_FILE_RULE_KEY, fetchedContents).getType(), Matchers.equalTo(CacheResultType.HIT));
assertThat(serverBackedCache.fetch(bFileRuleKey, fetchedContents).getType(), Matchers.equalTo(CacheResultType.HIT));
} finally {
secondWebServer.stop();
}
}
use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.
the class ServedCacheIntegrationTest method testStoreDisabled.
@Test
public void testStoreDisabled() 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 = readonly"), 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(false));
}
use of com.facebook.buck.artifact_cache.ArtifactCache in project buck by facebook.
the class ServedCacheIntegrationTest method testMalformedDirCacheMetaData.
@Test
public void testMalformedDirCacheMetaData() throws Exception {
ArtifactCache cache = TestArtifactCaches.createDirCacheForTest(projectFilesystem.getRootPath(), Paths.get("test-cache"));
Path cacheFilePath = DirArtifactCacheTestUtil.getPathForRuleKey(cache, A_FILE_RULE_KEY, Optional.of(".metadata"));
assertThat(projectFilesystem.exists(cacheFilePath), Matchers.is(true));
try (DataOutputStream outputStream = new DataOutputStream(projectFilesystem.newFileOutputStream(cacheFilePath))) {
outputStream.writeInt(1024);
}
webServer = new WebServer(/* port */
0, projectFilesystem, "/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.MISS));
}
Aggregations