Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Rename LocalCache to LocalCacheStorage
Browse files Browse the repository at this point in the history
Summary: Renamed LocalCache to LocalCacheStorage.

Reviewed By: bobyangyf

fbshipit-source-id: 677265dec0
  • Loading branch information
Lubomir Litchev authored and facebook-github-bot committed Oct 26, 2018
1 parent 77c91ea commit 3f10e81
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/com/facebook/buck/parser/cache/ParserCacheException.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package com.facebook.buck.parser.cache;

/** This exception is thrown when there are failures while doing {@link ParserCache} operations. */
/**
* This exception is thrown when there are failures while doing {@link ParserCacheStorage}
* operations.
*/
public class ParserCacheException extends Exception {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.common.hash.HashCode;

/** This is the main interface for interacting with the cache. */
public interface ParserCache {
public interface ParserCacheStorage {

/**
* Stores a {@link BuildFileManifest} object to the cache.
Expand All @@ -43,7 +43,7 @@ void storeBuildFileManifest(
* @return an {@link BuildFileManifest} object status operation if the operation is successful. In
* case of failure an appropriate exception is thrown.
* @throws ParserCacheException thrown when there is an error constructing the {@link
* BuildFileManifest} from the {@link ParserCache}.
* BuildFileManifest} from the {@link ParserCacheStorage}.
*/
BuildFileManifest getBuildFileManifest(HashCode weakFingerprint, HashCode strongFingerprint)
throws ParserCacheException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.facebook.buck.core.util.log.Logger;
import com.facebook.buck.io.filesystem.ProjectFilesystem;
import com.facebook.buck.parser.api.BuildFileManifest;
import com.facebook.buck.parser.cache.ParserCache;
import com.facebook.buck.parser.cache.ParserCacheException;
import com.facebook.buck.parser.cache.ParserCacheStorage;
import com.facebook.buck.parser.cache.json.BuildFileManifestSerializer;
import com.google.common.base.Preconditions;
import com.google.common.base.Stopwatch;
Expand All @@ -31,14 +31,14 @@
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;

/** A local filesystem backed implementation for the {@link ParserCache} interface. */
public class LocalCache implements ParserCache {
private static final Logger LOG = Logger.get(LocalCache.class);
/** An local filesystem backed implementation for the {@link ParserCacheStorage} interface. */
public class LocalCacheStorage implements ParserCacheStorage {
private static final Logger LOG = Logger.get(LocalCacheStorage.class);

private final Path localCachePath;
private final ProjectFilesystem filesystem;

private LocalCache(Path localCachePath, ProjectFilesystem filesystem) {
private LocalCacheStorage(Path localCachePath, ProjectFilesystem filesystem) {
this.filesystem = filesystem;
this.localCachePath = localCachePath;
}
Expand All @@ -64,20 +64,20 @@ private static Path createLocalCachePathFromConfig(
}

/**
* Static factory for creating {@link LocalCache} objects.
* Static factory for creating {@link LocalCacheStorage} objects.
*
* @param parserCacheConfig the {@code parserCacheConfig} object to be used for this parsing.
* @return a new instance of fully instantiated local cache object.
* @throws ParserCacheException when the {@link LocalCache} object cannot be constructed.
* @throws ParserCacheException when the {@link LocalCacheStorage} object cannot be constructed.
*/
public static LocalCache newInstance(
public static LocalCacheStorage newInstance(
AbstractParserCacheConfig parserCacheConfig, ProjectFilesystem filesystem)
throws ParserCacheException {
Preconditions.checkState(
parserCacheConfig.isDirParserCacheEnabled(),
"Invalid state: LocalCache should not be instantiated if the cache is disabled.");
"Invalid state: LocalCacheStorage should not be instantiated if the cache is disabled.");
Path localCachePath = createLocalCachePathFromConfig(parserCacheConfig, filesystem);
return new LocalCache(localCachePath, filesystem);
return new LocalCacheStorage(localCachePath, filesystem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class LocalCacheTest {
public class LocalCacheStorageTest {
@Rule public ExpectedException expectedException = ExpectedException.none();
@Rule public TemporaryPaths tempDir = new TemporaryPaths();

Expand Down Expand Up @@ -113,7 +113,7 @@ public void setUp() {
assumeThat(Platform.detect(), not(Platform.WINDOWS));
filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem("/");
localHandler = new LocalHandler();
Logger.get(LocalCache.class).addHandler(localHandler);
Logger.get(LocalCacheStorage.class).addHandler(localHandler);
}

@Test
Expand All @@ -122,13 +122,14 @@ public void createLocalCacheWithAbsolutePathAndException()
expectedException.expect(ParserCacheException.class);
expectedException.expectMessage("Failed to create local cache directory - /foo/bar");
filesystem.createNewFile(Paths.get("/foo"));
LocalCache.newInstance(getParserCacheConfig(true, filesystem.getPath("/foo/bar")), filesystem);
LocalCacheStorage.newInstance(
getParserCacheConfig(true, filesystem.getPath("/foo/bar")), filesystem);
}

@Test
public void createLocalCacheWithAbsolutePath() throws ParserCacheException {
Path absPath = filesystem.getBuckPaths().getBuckOut().resolve("/foo/bar").toAbsolutePath();
LocalCache.newInstance(getParserCacheConfig(true, absPath), filesystem);
LocalCacheStorage.newInstance(getParserCacheConfig(true, absPath), filesystem);
List<LogRecord> events = localHandler.messages;
assertEquals(1, events.size());
LogRecord event = events.get(0);
Expand All @@ -139,7 +140,7 @@ public void createLocalCacheWithAbsolutePath() throws ParserCacheException {
@Test
public void createLocalCacheWithRelativePath() throws ParserCacheException {
Path path = filesystem.getPath("foo/bar");
LocalCache.newInstance(getParserCacheConfig(true, path), filesystem);
LocalCacheStorage.newInstance(getParserCacheConfig(true, path), filesystem);
List<LogRecord> events = localHandler.messages;
assertEquals(1, events.size());
LogRecord event = events.get(0);
Expand All @@ -153,15 +154,15 @@ public void createLocalCacheWithRelativePath() throws ParserCacheException {
public void createLocalCacheWhenCachingDisabled() throws ParserCacheException {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage(
"Invalid state: LocalCache should not be instantiated if the cache is disabled.");
LocalCache.newInstance(
"Invalid state: LocalCacheStorage should not be instantiated if the cache is disabled.");
LocalCacheStorage.newInstance(
getParserCacheConfig(false, filesystem.getPath(tempDir.getRoot().toString())), filesystem);
}

@Test
public void createLocalCacheWhenCacheDefaultDirectory() throws ParserCacheException {
Path emptyPathForDefaultCacheLocation = filesystem.getPath("\"\"");
LocalCache.newInstance(
LocalCacheStorage.newInstance(
getParserCacheConfig(true, emptyPathForDefaultCacheLocation), filesystem);
List<LogRecord> events = localHandler.messages;
assertEquals(1, events.size());
Expand All @@ -172,16 +173,16 @@ public void createLocalCacheWhenCacheDefaultDirectory() throws ParserCacheExcept

@Test
public void createLocalCacheWFPDirectoryNonExisting() throws IOException, ParserCacheException {
LocalCache localCache =
LocalCache.newInstance(
LocalCacheStorage localCacheStorage =
LocalCacheStorage.newInstance(
getParserCacheConfig(
true,
filesystem.getPath(tempDir.getRoot().toString() + File.separator + FOO_BAR_PATH)),
filesystem);
Path buildPath = filesystem.getPath(FOO_BAR_PATH);
HashCode weakFingerprint = Fingerprinter.getWeakFingerprint(buildPath, getConfig().getConfig());
HashCode strongFingerprint = Fingerprinter.getStrongFingerprint(filesystem, ImmutableList.of());
localCache.storeBuildFileManifest(weakFingerprint, strongFingerprint, null);
localCacheStorage.storeBuildFileManifest(weakFingerprint, strongFingerprint, null);
Path localCachePath = tempDir.getRoot().resolve(FOO_BAR_PATH);
assertNotNull(localCachePath);
Path weakFingerprintPath =
Expand All @@ -193,8 +194,8 @@ public void createLocalCacheWFPDirectoryNonExisting() throws IOException, Parser
@Test
public void createLocalCacheWFPDirectoryExistingAndKeepIt()
throws IOException, ParserCacheException {
LocalCache localCache =
LocalCache.newInstance(
LocalCacheStorage localCacheStorage =
LocalCacheStorage.newInstance(
getParserCacheConfig(
true,
filesystem.getPath(tempDir.getRoot().toString() + File.separator + FOO_BAR_PATH)),
Expand All @@ -211,7 +212,7 @@ public void createLocalCacheWFPDirectoryExistingAndKeepIt()
assertTrue(filesystem.exists(newFilePath));
HashCode weakFingerprint = Fingerprinter.getWeakFingerprint(buildPath, getConfig().getConfig());
HashCode strongFingerprint = Fingerprinter.getStrongFingerprint(filesystem, ImmutableList.of());
localCache.storeBuildFileManifest(weakFingerprint, strongFingerprint, null);
localCacheStorage.storeBuildFileManifest(weakFingerprint, strongFingerprint, null);
assertNotNull(localCachePath);
assertTrue(filesystem.exists(wfpPath));
assertTrue(filesystem.exists(newFilePath));
Expand All @@ -220,8 +221,8 @@ public void createLocalCacheWFPDirectoryExistingAndKeepIt()
@Test
public void stroreInLocalCacheAndGetFromLocalCacheAndVerifyMatch()
throws IOException, ParserCacheException {
LocalCache localCache =
LocalCache.newInstance(
LocalCacheStorage localCacheStorage =
LocalCacheStorage.newInstance(
getParserCacheConfig(
true,
filesystem.getPath(tempDir.getRoot().toString() + File.separator + FOO_BAR_PATH)),
Expand Down Expand Up @@ -295,7 +296,8 @@ public void stroreInLocalCacheAndGetFromLocalCacheAndVerifyMatch()
HashCode strongFingerprinter = Fingerprinter.getStrongFingerprint(filesystem, includes);

// Store in local cache
localCache.storeBuildFileManifest(weakFingerprinter, strongFingerprinter, buildFileManifest);
localCacheStorage.storeBuildFileManifest(
weakFingerprinter, strongFingerprinter, buildFileManifest);

Path serializedDataFile =
localCachePath
Expand All @@ -305,7 +307,7 @@ public void stroreInLocalCacheAndGetFromLocalCacheAndVerifyMatch()

// Get from local cache
BuildFileManifest buildFileManifestResult =
localCache.getBuildFileManifest(weakFingerprinter, strongFingerprinter);
localCacheStorage.getBuildFileManifest(weakFingerprinter, strongFingerprinter);
assertEquals(buildFileManifest, buildFileManifestResult);
}

Expand Down

0 comments on commit 3f10e81

Please sign in to comment.