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());
}
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);
}
Aggregations