diff options
author | Nasser Grainawi <nasser@codeaurora.org> | 2020-10-12 14:58:07 -0600 |
---|---|---|
committer | Nasser Grainawi <nasser@codeaurora.org> | 2020-10-26 18:49:54 -0600 |
commit | 186de4e68348af259fd2ad8b2fe726d832c4bee5 (patch) | |
tree | 7d716748cd7943a8b12e76a562d09646c60736ad | |
parent | 158bdf0d089fe98b4eb084f8c20644b803e95b2b (diff) |
ReplicationIT: Add shouldMatch* e2e tests
These new tests utilize creating a branch in a way that does not trigger
replication so that scheduleFullSync() is responsible for replicating
the update. In this way, the tests verify the destination receives the
update because scheduleFullSync() matched the given URI.
Change-Id: I4ae15d0301a308a12cbca3684915e89ca421e02f
-rw-r--r-- | src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java | 72 |
1 files changed, 72 insertions, 0 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 225aa3e..353beb9 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationIT.java @@ -16,6 +16,7 @@ package com.googlesource.gerrit.plugins.replication; import static com.google.common.truth.Truth.assertThat; import static com.google.gerrit.testing.GerritJUnit.assertThrows; +import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.NO_OP; import static java.util.stream.Collectors.toList; import com.google.common.flogger.FluentLogger; @@ -39,9 +40,12 @@ import java.util.List; import java.util.Optional; import java.util.function.Supplier; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.util.FS; import org.junit.Test; @@ -197,6 +201,58 @@ public class ReplicationIT extends LightweightPluginDaemonTest { } @Test + public void shouldMatchTemplatedURL() throws Exception { + Project.NameKey targetProject = createTestProject("projectreplica"); + + setReplicationDestination("foo", "replica", ALL_PROJECTS); + reloadConfig(); + + String newRef = "refs/heads/newForTest"; + ObjectId newRefTip = createNewBranchWithoutPush("refs/heads/master", newRef); + + String urlMatch = gitPath.resolve("${name}" + "replica" + ".git").toString(); + + plugin + .getSysInjector() + .getInstance(ReplicationQueue.class) + .scheduleFullSync(project, urlMatch, new ReplicationState(NO_OP), true); + + try (Repository repo = repoManager.openRepository(targetProject)) { + waitUntil(() -> checkedGetRef(repo, newRef) != null); + + Ref targetBranchRef = getRef(repo, newRef); + assertThat(targetBranchRef).isNotNull(); + assertThat(targetBranchRef.getObjectId()).isEqualTo(newRefTip); + } + } + + @Test + public void shouldMatchRealURL() throws Exception { + Project.NameKey targetProject = createTestProject("projectreplica"); + + setReplicationDestination("foo", "replica", ALL_PROJECTS); + reloadConfig(); + + String newRef = "refs/heads/newForTest"; + ObjectId newRefTip = createNewBranchWithoutPush("refs/heads/master", newRef); + + String urlMatch = gitPath.resolve(project + "replica" + ".git").toString(); + + plugin + .getSysInjector() + .getInstance(ReplicationQueue.class) + .scheduleFullSync(project, urlMatch, new ReplicationState(NO_OP), true); + + try (Repository repo = repoManager.openRepository(targetProject)) { + waitUntil(() -> checkedGetRef(repo, newRef) != null); + + Ref targetBranchRef = getRef(repo, newRef); + assertThat(targetBranchRef).isNotNull(); + assertThat(targetBranchRef.getObjectId()).isEqualTo(newRefTip); + } + } + + @Test public void shouldReplicateHeadUpdate() throws Exception { setReplicationDestination("foo", "replica", ALL_PROJECTS); reloadConfig(); @@ -343,4 +399,20 @@ public class ReplicationIT extends LightweightPluginDaemonTest { return false; } } + + private ObjectId createNewBranchWithoutPush(String fromBranch, String newBranch) + throws Exception { + try (Repository repo = repoManager.openRepository(project); + RevWalk walk = new RevWalk(repo)) { + Ref ref = repo.exactRef(fromBranch); + RevCommit tip = null; + if (ref != null) { + tip = walk.parseCommit(ref.getObjectId()); + } + RefUpdate update = repo.updateRef(newBranch); + update.setNewObjectId(tip); + update.update(walk); + return update.getNewObjectId(); + } + } } |