Adapt to ProjectCache interface change
Change-Id: I8ae19e4d2914230536ba932fba18b9c923859f77
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
index 1524c2a..7e4298b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -14,6 +14,7 @@
package com.googlesource.gerrit.plugins.replication;
+import static com.google.gerrit.server.project.ProjectCache.noSuchProject;
import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.resolveNodeName;
import static com.googlesource.gerrit.plugins.replication.ReplicationFileBasedConfig.replaceName;
import static org.eclipse.jgit.transport.RemoteRefUpdate.Status.NON_EXISTING;
@@ -30,6 +31,7 @@
import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RefNames;
+import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.extensions.config.FactoryModule;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.extensions.restapi.AuthException;
@@ -302,13 +304,10 @@
() -> {
ProjectState projectState;
try {
- projectState = projectCache.checkedGet(project);
- } catch (IOException e) {
+ projectState = projectCache.get(project).orElseThrow(noSuchProject(project));
+ } catch (StorageException e) {
return false;
}
- if (projectState == null) {
- throw new NoSuchProjectException(project);
- }
if (!projectState.statePermitsRead()) {
return false;
}
@@ -346,13 +345,10 @@
() -> {
ProjectState projectState;
try {
- projectState = projectCache.checkedGet(project);
- } catch (IOException e) {
+ projectState = projectCache.get(project).orElseThrow(noSuchProject(project));
+ } catch (StorageException e) {
return false;
}
- if (projectState == null) {
- throw new NoSuchProjectException(project);
- }
return shouldReplicate(projectState, userProvider.get());
})
.call();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
index df6cc42..8208264 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java
@@ -54,6 +54,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.jgit.errors.NoRemoteRepositoryException;
@@ -494,8 +495,8 @@
private List<RemoteRefUpdate> generateUpdates(Transport tn)
throws IOException, PermissionBackendException {
- ProjectState projectState = projectCache.checkedGet(projectName);
- if (projectState == null) {
+ Optional<ProjectState> projectState = projectCache.get(projectName);
+ if (!projectState.isPresent()) {
return Collections.emptyList();
}
@@ -504,7 +505,7 @@
boolean filter;
PermissionBackend.ForProject forProject = permissionBackend.currentUser().project(projectName);
try {
- projectState.checkStatePermitsRead();
+ projectState.get().checkStatePermitsRead();
forProject.check(ProjectPermission.READ);
filter = false;
} catch (AuthException | ResourceConflictException e) {
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/PushOneTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/PushOneTest.java
index c09fcd1..94f0dc4 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/PushOneTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/PushOneTest.java
@@ -41,6 +41,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -245,9 +246,9 @@
return push;
}
- private void setupProjectCacheMock() throws IOException {
+ private void setupProjectCacheMock() {
projectCacheMock = mock(ProjectCache.class);
- when(projectCacheMock.checkedGet(projectNameKey)).thenReturn(projectStateMock);
+ when(projectCacheMock.get(projectNameKey)).thenReturn(Optional.of(projectStateMock));
}
private void setupTransportMock() throws NotSupportedException, TransportException {