e2e-tests: Add a CheckNewProjectReplica1 scenario

Add an initial CheckNewProjectReplica1 scenario, as an alternative to
CheckMasterBranchReplica1. The former verifies using a git clone, while
the latter verifies using the master branch endpoint. That endpoint may
not be available in some replica deployment environments, thus this new
scenario to clone the expected replica instead.

This new scenario is mostly based on the existing
CloneUsingBothProtocols core scenario.

Introduce a replication_delay [1] property [2]. Make its default value
match the similar replication plugin's replicationDelay one (15 seconds,
[3]). Add this new property to that same e2e-tests documentation page.

[1] -Dcom.google.gerrit.scenarios.replication_delay=15
[2] https://gerrit-documentation.storage.googleapis.com/Documentation/3.0.12/dev-e2e-tests.html#_environment_properties
[3] https://gerrit.googlesource.com/plugins/replication/+doc/master/src/main/resources/Documentation/config.md

Change-Id: I8966f0724cdd90b8433d6ffbb0afdbdff78c94ce
diff --git a/Documentation/dev-e2e-tests.txt b/Documentation/dev-e2e-tests.txt
index 6ee22bd..115239b 100644
--- a/Documentation/dev-e2e-tests.txt
+++ b/Documentation/dev-e2e-tests.txt
@@ -171,11 +171,12 @@
 * `-Dcom.google.gerrit.scenarios.ssh_port=29418`
 * `-Dcom.google.gerrit.scenarios.http_port=8080`
 * `-Dcom.google.gerrit.scenarios.http_scheme=http`
+* `-Dcom.google.gerrit.scenarios.replication_delay=15`
 
 Above, the properties can be set with values matching specific deployment topologies under test.
 The example values shown above are the currently coded default ones. For example, the `http` scheme
-above could be replaced with `https`. The framework could support differing or more properties over
-time.
+above could be replaced with `https`. The `replication_delay` property matches replication plugin's
+configuration with the same name. The framework may support differing or more properties over time.
 
 Plugin or otherwise non-core scenarios may do so just as well. The core java package
 `com.google.gerrit.scenarios` from the example above has to be replaced with the one under which
diff --git a/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/CheckNewProjectReplica1.json b/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/CheckNewProjectReplica1.json
new file mode 100644
index 0000000..f15ddae
--- /dev/null
+++ b/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/CheckNewProjectReplica1.json
@@ -0,0 +1,6 @@
+[
+  {
+    "url": "HTTP_SCHEME://HOSTNAME:HTTP_PORT1/_PROJECT",
+    "cmd": "clone"
+  }
+]
diff --git a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/CheckNewProjectReplica1.scala b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/CheckNewProjectReplica1.scala
new file mode 100644
index 0000000..61442fd
--- /dev/null
+++ b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/CheckNewProjectReplica1.scala
@@ -0,0 +1,58 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.scenarios
+
+import io.gatling.core.Predef._
+import io.gatling.core.feeder.FeederBuilder
+import io.gatling.core.structure.ScenarioBuilder
+
+import scala.concurrent.duration._
+
+class CheckNewProjectReplica1 extends GitSimulation {
+  private val data: FeederBuilder = jsonFile(resource).convert(keys).queue
+  private val default: String = name
+
+  private lazy val replicationDuration = replicationDelay + SecondsPerWeightUnit
+
+  override def relativeRuntimeWeight: Int = replicationDuration / SecondsPerWeightUnit + 2
+
+  override def replaceOverride(in: String): String = {
+    var next = replaceProperty("http_port1", 8081, in)
+    next = replaceKeyWith("_project", default, next)
+    super.replaceOverride(next)
+  }
+
+  private val test: ScenarioBuilder = scenario(unique)
+      .feed(data)
+      .exec(gitRequest)
+
+  private val createProject = new CreateProject(default)
+  private val deleteProject = new DeleteProject(default)
+
+  setUp(
+    createProject.test.inject(
+      nothingFor(stepWaitTime(createProject) seconds),
+      atOnceUsers(single)
+    ),
+    test.inject(
+      nothingFor(stepWaitTime(this) + replicationDuration seconds),
+      atOnceUsers(single)
+    ).protocols(gitProtocol),
+    deleteProject.test.inject(
+      nothingFor(stepWaitTime(deleteProject) seconds),
+      atOnceUsers(single)
+    ),
+  ).protocols(httpProtocol)
+}
diff --git a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GerritSimulation.scala b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GerritSimulation.scala
index 679320d..860c7df 100644
--- a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GerritSimulation.scala
+++ b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GerritSimulation.scala
@@ -32,6 +32,7 @@
   protected val unique: String = name + "-" + this.hashCode()
   protected val single = 1
 
+  val replicationDelay: Int = replaceProperty("replication_delay", 15).toInt
   private val powerFactor: Double = replaceProperty("power_factor", 1.0).toDouble
   protected val SecondsPerWeightUnit: Int = 2
   val maxExecutionTime: Int = (SecondsPerWeightUnit * relativeRuntimeWeight * powerFactor).toInt