Skip to contentSkip to conversation

TasksStorage: Remove delete() only used by tests

PATCH New Adithya Chakilam 1 participant 1 message Aug 5, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 TasksStorage: Remove delete() only used by tests

From: Nasser Grainawi <[email protected]>

In general we shouldn't have methods that provide behavior only for tests. Callers of delete() in pre-3.1 code should move to start() and finish() in 3.1. To facilitate that, update start(), reset(), and finish() methods to not require a PushOne object. These methods can instead use a new interface that PushOne already can implement without functional changes.

Change-Id: Id82d2ec3125075832134c8dbe56b342e5a874bbc

---
 .../gerrit/plugins/replication/PushOne.java   |  8 ++-
 .../replication/ReplicationTasksStorage.java  | 52 +++++++-------
 .../plugins/replication/ReplicationIT.java    | 15 +++-
 .../ReplicationTasksStorageTest.java          | 68 ++++++++++++-------
 .../plugins/replication/TestUriUpdates.java   | 52 ++++++++++++++
 5 files changed, 139 insertions(+), 56 deletions(-)
 create mode 100644 src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java
src/main/java/com/googlesource/gerrit/plugins/replication/PushOne.java +5 -3
index 634f44d..3124940 100644
@@ -84,7 +84,7 @@ import org.slf4j.MDC;
  * <p>Instance members are protected by the lock within PushQueue. Callers must take that lock to
  * ensure they are working with a current view of the object.
  */
-class PushOne implements ProjectRunnable, CanceledWhileRunning {
+class PushOne implements ProjectRunnable, CanceledWhileRunning, ReplicationTasksStorage.UriUpdates {
   private final ReplicationStateListener stateLog;
   static final String ALL_REFS = "..all..";
   static final String ID_MDC_KEY = "pushOneId";
@@ -230,7 +230,8 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning {
     return canceled || canceledWhileRunning.get();
   }
 
-  URIish getURI() {
+  @Override
+  public URIish getURI() {
     return uri;
   }
 
@@ -244,7 +245,8 @@ class PushOne implements ProjectRunnable, CanceledWhileRunning {
     }
   }
 
-  Set<String> getRefs() {
+  @Override
+  public Set<String> getRefs() {
     return pushAllRefs ? Sets.newHashSet(ALL_REFS) : delta;
   }
 
src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorage.java +27 -25

97 lines not on this page · raw message

src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java +13 -2
index 31cd75d..bb0f283 100644
@@ -36,7 +36,9 @@ import com.google.gerrit.server.config.SitePaths;
 import com.google.inject.Inject;
 import com.google.inject.Key;
 import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.ReplicateRefUpdate;
+import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.UriUpdates;
 import java.io.IOException;
+import java.net.URISyntaxException;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -449,7 +451,7 @@ public class ReplicationIT extends LightweightPluginDaemonTest {
   }
 
   @Test
-  public void shouldFirePendingOnlyToStoredUri() throws Exception {
+  public void shouldFirePendingOnlyToRemainingUris() throws Exception {
     String suffix1 = "replica1";
     String suffix2 = "replica2";
     Project.NameKey target1 = createTestProject(project + suffix1);
@@ -463,7 +465,16 @@ public class ReplicationIT extends LightweightPluginDaemonTest {
     String changeRef = createChange().getPatchSet().refName();
 
     tasksStorage.disableDeleteForTesting(false);
-    changeReplicationTasksForRemote(changeRef, remote1).forEach(tasksStorage::delete);
+    changeReplicationTasksForRemote(changeRef, remote1)
+        .forEach(
+            (update) -> {
+              try {
+                UriUpdates uriUpdates = TestUriUpdates.create(update);
+                tasksStorage.start(uriUpdates);
+                tasksStorage.finish(uriUpdates);
+              } catch (URISyntaxException e) {
+              }
+            });
     tasksStorage.disableDeleteForTesting(true);
 
     setReplicationDestination(remote1, suffix1, ALL_PROJECTS);
src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageTest.java +42 -26

143 lines not on this page · raw message

src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.24.3 (Apple Git-128)