Remove ProjectCache#checkedGet and move callers to #get

In an effort to make it impossible to use the ProjectCache interface the
wrong way, we are simplifying the interface to just a single option for
getting a project. The #get method throws a StorageException in case loading
failed and returns Optional#empty in case the project does not exist.

Change-Id: I7e3ecf2de3bc975d1c35ee8a848ac61def7af252
This commit is contained in:
Patrick Hiesel
2020-03-06 15:11:28 +01:00
parent 3a0ad58890
commit a6a44c5ab5
69 changed files with 344 additions and 256 deletions

View File

@@ -23,6 +23,7 @@ import static com.google.common.truth.TruthJUnit.assume;
import static com.google.gerrit.entities.Patch.COMMIT_MSG;
import static com.google.gerrit.entities.Patch.MERGE_LIST;
import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.NON_VISIBLE_CHANGES;
import static com.google.gerrit.server.project.ProjectCache.illegalState;
import static com.google.gerrit.server.project.testing.TestLabels.label;
import static com.google.gerrit.server.project.testing.TestLabels.value;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -1185,9 +1186,8 @@ public abstract class AbstractDaemonTest {
GroupReference groupReference,
String ref,
boolean exclusive,
String... permissionNames)
throws IOException {
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
String... permissionNames) {
ProjectConfig cfg = projectCache.get(project).orElseThrow(illegalState(project)).getConfig();
AccessSection accessSection = cfg.getAccessSection(ref);
assertThat(accessSection).isNotNull();
for (String permissionName : permissionNames) {

View File

@@ -15,6 +15,7 @@
package com.google.gerrit.acceptance;
import static com.google.gerrit.server.git.receive.LazyPostReceiveHookChain.affectsSize;
import static com.google.gerrit.server.project.ProjectCache.illegalState;
import static com.google.gerrit.server.quota.QuotaGroupDefinitions.REPOSITORY_SIZE_GROUP;
import com.google.common.collect.ImmutableList;
@@ -241,15 +242,8 @@ class InProcessProtocol extends TestProtocol<Context> {
throw new RuntimeException(e);
}
ProjectState projectState;
try {
projectState = projectCache.checkedGet(req.project);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (projectState == null) {
throw new RuntimeException("can't load project state for " + req.project.get());
}
ProjectState projectState =
projectCache.get(req.project).orElseThrow(illegalState(req.project));
Repository permissionAwareRepository = PermissionAwareRepositoryManager.wrap(repo, perm);
UploadPack up = new UploadPack(permissionAwareRepository);
up.setPackConfig(transferConfig.getPackConfig());
@@ -320,10 +314,11 @@ class InProcessProtocol extends TestProtocol<Context> {
}
try {
IdentifiedUser identifiedUser = userProvider.get().asIdentifiedUser();
ProjectState projectState = projectCache.checkedGet(req.project);
if (projectState == null) {
throw new RuntimeException(String.format("project %s not found", req.project));
}
ProjectState projectState =
projectCache
.get(req.project)
.orElseThrow(
() -> new RuntimeException(String.format("project %s not found", req.project)));
AsyncReceiveCommits arc = factory.create(projectState, identifiedUser, db, null);
if (arc.canUpload() != Capable.OK) {