Search in sources :

Example 1 with CACHE_DATA_FILENAME

use of com.google.idea.blaze.android.filecache.LocalArtifactCache.CACHE_DATA_FILENAME in project intellij by bazelbuild.

the class LocalArtifactCacheTest method noStateFile_existingArtifacts_initializesWithAConsistentStateFile.

@Test
public void noStateFile_existingArtifacts_initializesWithAConsistentStateFile() throws IOException {
    cacheDirectory.newFile("untracked_artifact.2.jar");
    cacheDirectory.newFile("untracked_artifact.1.jar");
    artifactCache.initialize();
    File expectedCacheStateFile = new File(cacheDirectory.getRoot(), CACHE_DATA_FILENAME);
    assertThat(cacheDirectory.getRoot().listFiles()).asList().contains(expectedCacheStateFile);
    ArtifactCacheData artifactCacheData = LocalArtifactCache.readJsonFromDisk(expectedCacheStateFile);
    // check that all files referenced in the serialized cache data exists
    artifactCacheData.getCacheEntries().stream().map(CacheEntry::getFileName).map(f -> new File(cacheDirectory.getRoot(), f)).forEach(f -> assertThat(f.exists()).isTrue());
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) RunWith(org.junit.runner.RunWith) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) ImmutableList(com.google.common.collect.ImmutableList) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) Path(java.nio.file.Path) IntellijRule(com.google.idea.testing.IntellijRule) Before(org.junit.Before) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) CACHE_DATA_FILENAME(com.google.idea.blaze.android.filecache.LocalArtifactCache.CACHE_DATA_FILENAME) IOException(java.io.IOException) Test(org.junit.Test) RemoteArtifactPrefetcher(com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) Objects(java.util.Objects) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Paths(java.nio.file.Paths) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) DefaultPrefetcher(com.google.idea.blaze.base.prefetch.DefaultPrefetcher) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) File(java.io.File) Test(org.junit.Test)

Example 2 with CACHE_DATA_FILENAME

use of com.google.idea.blaze.android.filecache.LocalArtifactCache.CACHE_DATA_FILENAME in project intellij by bazelbuild.

the class LocalArtifactCacheTest method put_addsArtifactInDirectory.

@Test
public void put_addsArtifactInDirectory() throws IOException {
    // Create blaze artifacts in FS
    ImmutableList<OutputArtifact> outputArtifacts = ImmutableList.of(newLocalOutputArtifact("relative/path_1/artifact_1.jar"), newLocalOutputArtifact("relative/path_2/artifact_2.jar"), newLocalOutputArtifact("relative/path_3/artifact_3.jar"));
    for (OutputArtifact a : outputArtifacts) {
        File file = ((LocalFileOutputArtifact) a).getFile();
        assertThat(Paths.get(file.getParent()).toFile().mkdirs()).isTrue();
        assertThat(file.createNewFile()).isTrue();
    }
    // Put blaze artifacts in cache
    artifactCache.initialize();
    artifactCache.putAll(outputArtifacts, blazeContext, false);
    // Check that the artifacts were added to the cache.
    ImmutableList<File> expectedFiles = Stream.concat(outputArtifacts.stream().map(a -> {
        try {
            return CacheEntry.forArtifact(a);
        } catch (ArtifactNotFoundException e) {
            return null;
        }
    }).filter(Objects::nonNull).map(CacheEntry::getFileName), Stream.of(CACHE_DATA_FILENAME)).map(f -> new File(cacheDirectory.getRoot(), f)).collect(ImmutableList.toImmutableList());
    assertThat(cacheDirectory.getRoot().listFiles()).asList().containsExactlyElementsIn(expectedFiles);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) RunWith(org.junit.runner.RunWith) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) ImmutableList(com.google.common.collect.ImmutableList) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) Path(java.nio.file.Path) IntellijRule(com.google.idea.testing.IntellijRule) Before(org.junit.Before) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) CACHE_DATA_FILENAME(com.google.idea.blaze.android.filecache.LocalArtifactCache.CACHE_DATA_FILENAME) IOException(java.io.IOException) Test(org.junit.Test) RemoteArtifactPrefetcher(com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) MockArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder) Objects(java.util.Objects) Stream(java.util.stream.Stream) Rule(org.junit.Rule) Paths(java.nio.file.Paths) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) DefaultPrefetcher(com.google.idea.blaze.base.prefetch.DefaultPrefetcher) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) Objects(java.util.Objects) LocalFileOutputArtifact(com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) File(java.io.File) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 CACHE_DATA_FILENAME (com.google.idea.blaze.android.filecache.LocalArtifactCache.CACHE_DATA_FILENAME)2 LocalFileOutputArtifact (com.google.idea.blaze.base.command.buildresult.LocalFileOutputArtifact)2 OutputArtifact (com.google.idea.blaze.base.command.buildresult.OutputArtifact)2 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)2 FileOperationProvider (com.google.idea.blaze.base.io.FileOperationProvider)2 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)2 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 DefaultPrefetcher (com.google.idea.blaze.base.prefetch.DefaultPrefetcher)2 RemoteArtifactPrefetcher (com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher)2 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)2 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)2 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)2 MockArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.MockArtifactLocationDecoder)2 IntellijRule (com.google.idea.testing.IntellijRule)2 File (java.io.File)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2