use of com.facebook.buck.io.LazyPath in project buck by facebook.
the class ServedCacheIntegrationTest method testStoreAndFetchBorrowable.
@Test
public void testStoreAndFetchBorrowable() 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.borrowablePath(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.io.LazyPath 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.io.LazyPath 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));
}
use of com.facebook.buck.io.LazyPath 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.io.LazyPath 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));
}
Aggregations