diff options
author | David Pursehouse <dpursehouse@digital.ai> | 2020-06-23 14:19:58 +0900 |
---|---|---|
committer | David Pursehouse <dpursehouse@digital.ai> | 2020-06-23 15:27:11 +0900 |
commit | 727d62d9d0dddc53fad52ac61d936155cad782ad (patch) | |
tree | fce286771d0788bbefbf4558e5d741c7676d5dac | |
parent | 116cbc11573e7afb0ce0782518a172cf798ec15c (diff) |
ReplicationIT: Test that branch deletion is replicated
When a branch is deleted, the deletion should be replicated to
the remote when "remote.name.mirror" is enabled.
Change-Id: If59a9bb15958f4559d62452a309afcf1ca6c3789
-rw-r--r-- | src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java index f982efb..7991216 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java @@ -318,6 +318,51 @@ public class ReplicationIT extends LightweightPluginDaemonTest { } @Test + public void shouldReplicateBranchDeletionWhenMirror() throws Exception { + replicateBranchDeletion(true); + } + + @Test + public void shouldNotReplicateBranchDeletionWhenNotMirror() throws Exception { + replicateBranchDeletion(false); + } + + private void replicateBranchDeletion(boolean mirror) throws Exception { + setReplicationDestination("foo", "replica", ALL_PROJECTS, mirror); + reloadConfig(); + + Project.NameKey targetProject = createTestProject(project + "replica"); + String branchToDelete = "refs/heads/todelete"; + String master = "refs/heads/master"; + BranchInput input = new BranchInput(); + input.revision = master; + gApi.projects().name(project.get()).branch(branchToDelete).create(input); + + assertThat(listReplicationTasks("refs/heads/(todelete|master)")).hasSize(2); + + try (Repository repo = repoManager.openRepository(targetProject)) { + waitUntil(() -> checkedGetRef(repo, branchToDelete) != null); + } + + gApi.projects().name(project.get()).branch(branchToDelete).delete(); + + assertThat(listReplicationTasks(branchToDelete)).hasSize(1); + + try (Repository repo = repoManager.openRepository(targetProject)) { + if (mirror) { + waitUntil(() -> checkedGetRef(repo, branchToDelete) == null); + } + + Ref targetBranchRef = getRef(repo, branchToDelete); + if (mirror) { + assertThat(targetBranchRef).isNull(); + } else { + assertThat(targetBranchRef).isNotNull(); + } + } + } + + @Test public void shouldNotDrainTheQueueWhenReloading() throws Exception { // Setup repo to replicate Project.NameKey targetProject = createTestProject(project + "replica"); @@ -401,13 +446,24 @@ public class ReplicationIT extends LightweightPluginDaemonTest { private void setReplicationDestination( String remoteName, String replicaSuffix, Optional<String> project) throws IOException { - setReplicationDestination(remoteName, Arrays.asList(replicaSuffix), project); + setReplicationDestination(remoteName, Arrays.asList(replicaSuffix), project, false); + } + + private void setReplicationDestination( + String remoteName, String replicaSuffix, Optional<String> project, boolean mirror) + throws IOException { + setReplicationDestination(remoteName, Arrays.asList(replicaSuffix), project, mirror); } private void setReplicationDestination( String remoteName, List<String> replicaSuffixes, Optional<String> project) throws IOException { + setReplicationDestination(remoteName, replicaSuffixes, project, false); + } + private void setReplicationDestination( + String remoteName, List<String> replicaSuffixes, Optional<String> project, boolean mirror) + throws IOException { List<String> replicaUrls = replicaSuffixes.stream() .map(suffix -> gitPath.resolve("${name}" + suffix + ".git").toString()) @@ -415,6 +471,7 @@ public class ReplicationIT extends LightweightPluginDaemonTest { config.setStringList("remote", remoteName, "url", replicaUrls); config.setInt("remote", remoteName, "replicationDelay", TEST_REPLICATION_DELAY); config.setInt("remote", remoteName, "replicationRetry", TEST_REPLICATION_RETRY); + config.setBoolean("remote", remoteName, "mirror", mirror); project.ifPresent(prj -> config.setString("remote", remoteName, "projects", prj)); config.save(); } |