summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNasser Grainawi <nasser@codeaurora.org>2020-10-30 16:43:22 -0600
committerNasser Grainawi <nasser@codeaurora.org>2020-10-30 16:43:22 -0600
commite09b5a08e183d4f92410bfa06289a1784cefb43b (patch)
treeb28c0a961f546da0eec070df61900da7ee83c29c
parentf3fdc78f71dd4afcf30152e7b653050debf85bef (diff)
parent4604b01e43c3b4aee3d03cb84945b3238c150ede (diff)
Merge branch 'stable-3.0' into stable-3.1
* stable-3.0: ReplicationStorageIT: Wait for all pushes without order ReplicationTasksStorage: Add multi-primary unit tests Change-Id: I3961368f7bcf7d4aa923d07f7f89beeaaeb307d3
-rw-r--r--src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDaemon.java27
-rw-r--r--src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java15
-rw-r--r--src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java10
3 files changed, 47 insertions, 5 deletions
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDaemon.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDaemon.java
index 7432745..420cdf8 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDaemon.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationDaemon.java
@@ -28,7 +28,9 @@ import java.io.IOException;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -160,6 +162,31 @@ public class ReplicationDaemon extends LightweightPluginDaemonTest {
}
}
+ protected boolean isPushCompleted(Map<Project.NameKey, String> refsByProject, Duration timeOut) {
+ try {
+ WaitUtil.waitUntil(
+ () -> {
+ Iterator<Map.Entry<Project.NameKey, String>> iterator =
+ refsByProject.entrySet().iterator();
+ while (iterator.hasNext()) {
+ Map.Entry<Project.NameKey, String> entry = iterator.next();
+ try (Repository repo = repoManager.openRepository(entry.getKey())) {
+ if (checkedGetRef(repo, entry.getValue()) != null) {
+ iterator.remove();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot open repo for project" + entry.getKey(), e);
+ }
+ }
+ return refsByProject.isEmpty();
+ },
+ timeOut);
+ } catch (InterruptedException e) {
+ return false;
+ }
+ return true;
+ }
+
protected Ref checkedGetRef(Repository repo, String branchName) {
try {
return repo.getRefDatabase().exactRef(branchName);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java
index 9e28b24..88b8f87 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java
@@ -26,7 +26,9 @@ import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.Repli
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
import java.util.stream.Stream;
@@ -182,15 +184,20 @@ public class ReplicationStorageIT extends ReplicationDaemon {
String changeRef1 = createChange().getPatchSet().refName();
String changeRef2 = createChange().getPatchSet().refName();
+ Map<Project.NameKey, String> refsByProject = new HashMap<>();
+ refsByProject.put(target1, changeRef1);
+ refsByProject.put(target2, changeRef1);
+ refsByProject.put(target1, changeRef2);
+ refsByProject.put(target2, changeRef2);
setReplicationDestination(remote1, suffix1, ALL_PROJECTS);
setReplicationDestination(remote2, suffix2, ALL_PROJECTS);
reloadConfig();
- assertThat(isPushCompleted(target1, changeRef1, TEST_PUSH_TIMEOUT)).isEqualTo(true);
- assertThat(isPushCompleted(target2, changeRef1, TEST_PUSH_TIMEOUT)).isEqualTo(true);
- assertThat(isPushCompleted(target1, changeRef2, TEST_PUSH_TIMEOUT)).isEqualTo(true);
- assertThat(isPushCompleted(target2, changeRef2, TEST_PUSH_TIMEOUT)).isEqualTo(true);
+ // Wait for completion within the time 2 pushes should take because each remote only has 1
+ // thread and needs to push 2 events
+ assertThat(isPushCompleted(refsByProject, TEST_PUSH_TIMEOUT.plus(TEST_PUSH_TIMEOUT)))
+ .isEqualTo(true);
}
@Test
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java
index 75912fa..42c0914 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java
@@ -32,7 +32,7 @@ public class ReplicationTasksStorageMPTest {
protected static final String REF = "myRef";
protected static final String REMOTE = "myDest";
protected static final URIish URISH =
- ReplicationTasksStorageTaskTest.getUrish("http://example.com/" + PROJECT + ".git");
+ ReplicationTasksStorageTest.getUrish("http://example.com/" + PROJECT + ".git");
protected static final ReplicationTasksStorage.ReplicateRefUpdate REF_UPDATE =
new ReplicationTasksStorage.ReplicateRefUpdate(PROJECT, REF, URISH, REMOTE);
protected static final UriUpdates URI_UPDATES = getUriUpdates(REF_UPDATE);
@@ -60,6 +60,14 @@ public class ReplicationTasksStorageMPTest {
}
@Test
+ public void sameTaskCreatedByOtherNodeIsDeduped() {
+ nodeA.create(REF_UPDATE);
+
+ nodeB.create(REF_UPDATE);
+ assertContainsExactly(persistedView.listWaiting(), REF_UPDATE);
+ }
+
+ @Test
public void waitingTaskCanBeCompletedByOtherNode() {
nodeA.create(REF_UPDATE);