use of com.facebook.buck.io.BorrowablePath 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();
}
}
Aggregations