FetchJob creation fails in replica when FetchAction is invoked with async=true Register filters 'PullReplicationApiMetricsFilter` and `PullReplicationFilter` in this order to avoid binding problems in runtime. Bug: Issue 16301 Change-Id: I195c5fee60225b84494838002b365e33e2b9c49c
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/HttpModule.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/HttpModule.java index b140cb4..83e8487 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/HttpModule.java +++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/HttpModule.java
@@ -31,6 +31,10 @@ @Override protected void configureServlets() { + DynamicSet.bind(binder(), AllRequestFilter.class) + .to(PullReplicationApiMetricsFilter.class) + .in(Scopes.SINGLETON); + if (isReplica) { DynamicSet.bind(binder(), AllRequestFilter.class) .to(PullReplicationFilter.class) @@ -38,9 +42,5 @@ } else { serveRegex("/init-project/.*$").with(ProjectInitializationAction.class); } - - DynamicSet.bind(binder(), AllRequestFilter.class) - .to(PullReplicationApiMetricsFilter.class) - .in(Scopes.SINGLETON); } }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java index 55ad15c..6691fdf 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/ActionITBase.java
@@ -66,7 +66,7 @@ httpModule = "com.googlesource.gerrit.plugins.replication.pull.api.HttpModule") public abstract class ActionITBase extends LightweightPluginDaemonTest { protected static final Optional<String> ALL_PROJECTS = Optional.empty(); - protected static final int TEST_REPLICATION_DELAY = 60; + protected static final int TEST_REPLICATION_DELAY = 1; protected static final String TEST_REPLICATION_SUFFIX = "suffix1"; protected static final String TEST_REPLICATION_REMOTE = "remote1";
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java index 5634b2a..440de99 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchActionIT.java
@@ -42,6 +42,24 @@ @Test @GerritConfig(name = "container.replica", value = "true") + public void shouldFetchRefAsyncWhenNodeIsAReplica() throws Exception { + String refName = createRef(); + String sendObjectPayload = + "{\"label\":\"" + + TEST_REPLICATION_REMOTE + + "\", \"ref_name\": \"" + + refName + + "\", \"async\":true}"; + + httpClientFactory + .create(source) + .execute( + withBasicAuthenticationAsAdmin(createRequest(sendObjectPayload)), + assertHttpResponseCode(202)); + } + + @Test + @GerritConfig(name = "container.replica", value = "true") public void shouldFetchRefWhenNodeIsAReplicaAndProjectNameContainsSlash() throws Exception { NameKey projectName = Project.nameKey("test/repo"); String refName = createRef(projectName);