Search in sources :

Example 21 with ArtifactCache

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

the class ServedCacheIntegrationTest method fullStackIntegrationTest.

@Test
public void fullStackIntegrationTest() 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(createMockLocalConfig("[cache]", "mode = dir,http", "two_level_cache_enabled=true", "two_level_cache_minimum_size=0b", "dir = server-backed-dir-cache", String.format("http_url = http://127.0.0.1:%d/", webServer.getPort().get())));
    ArtifactCache serverBackedDirCache = createArtifactCache(createMockLocalConfig("[cache]", "mode = dir", "dir = server-backed-dir-cache"));
    assertFalse(containsKey(serverBackedDirCache, A_FILE_RULE_KEY));
    assertTrue(containsKey(serverBackedCache, A_FILE_RULE_KEY));
    // The previous call should have propagated the key into the dir-cache.
    assertTrue(containsKey(serverBackedDirCache, A_FILE_RULE_KEY));
    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);
    assertFalse(containsKey(serverBackedCache, ruleKey));
    serverBackedCache.store(ArtifactInfo.builder().addRuleKeys(ruleKey).setMetadata(metadata).build(), BorrowablePath.borrowablePath(originalDataPath)).get();
    assertTrue(containsKey(serverBackedCache, ruleKey));
    assertTrue(containsKey(serverBackedDirCache, ruleKey));
}
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) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Aggregations

ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)21 Test (org.junit.Test)16 LazyPath (com.facebook.buck.io.LazyPath)13 Path (java.nio.file.Path)13 BorrowablePath (com.facebook.buck.io.BorrowablePath)9 RuleKey (com.facebook.buck.rules.RuleKey)9 CacheResult (com.facebook.buck.artifact_cache.CacheResult)7 BuckEventBus (com.facebook.buck.event.BuckEventBus)6 TestConsole (com.facebook.buck.testutil.TestConsole)5 NoopArtifactCache (com.facebook.buck.artifact_cache.NoopArtifactCache)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 Cell (com.facebook.buck.rules.Cell)4 IOException (java.io.IOException)4 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)3 FakeJavaPackageFinder (com.facebook.buck.jvm.java.FakeJavaPackageFinder)3 BuildId (com.facebook.buck.model.BuildId)3 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3 Before (org.junit.Before)3 AndroidDirectoryResolver (com.facebook.buck.android.AndroidDirectoryResolver)2