e2e-tests: Add the CreateProjectUsingMultiGerritTwice scenario

Add the CreateProjectUsingMultiGerritTwice scenario to test if deleting
a project carries over to the other HA Gerrit node. Adapt the
CloneUsingMultiGerrit1 scenario to reuse it so.

Make the create and delete project scenario names unique, so they can be
used multiple times that way. Otherwise, Gatling won't allow duplicated
scenario names in the same run.

The added CreateProjectUsingMultiGerritTwice scenario is solely reusing
existing scenarios, then. This is why its corresponding json test data
file is empty. Each scenario that it aggregates ends up using their own
json data, as the core framework prescribes.

Change-Id: I64b86f0de0a33b0aaf30ce594612b6d4e0bb7c4c
diff --git a/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerritTwice.json b/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerritTwice.json
new file mode 100644
index 0000000..da1a058
--- /dev/null
+++ b/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerritTwice.json
@@ -0,0 +1,4 @@
+[
+  {
+  }
+]
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CloneUsingMultiGerrit1.scala b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CloneUsingMultiGerrit1.scala
index bc51a39..c831979 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CloneUsingMultiGerrit1.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CloneUsingMultiGerrit1.scala
@@ -23,14 +23,19 @@
 
 class CloneUsingMultiGerrit1 extends GitSimulation {
   private val data: FileBasedFeederBuilder[Any]#F#F = jsonFile(resource).convert(url).queue
-  private val default: String = name
+  private var default: String = name
+
+  def this(default: String) {
+    this()
+    this.default = default
+  }
 
   override def replaceOverride(in: String): String = {
     val next = replaceProperty("http_port1", 8081, in)
     replaceKeyWith("_project", default, next)
   }
 
-  private val test: ScenarioBuilder = scenario(name)
+  val test: ScenarioBuilder = scenario(name)
     .feed(data)
     .exec(gitRequest)
 
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerrit.scala b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerrit.scala
index 3ae12b5..721d581 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerrit.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerrit.scala
@@ -27,7 +27,7 @@
     this.default = default
   }
 
-  val test: ScenarioBuilder = scenario(name)
+  val test: ScenarioBuilder = scenario(unique)
     .feed(data)
     .exec(httpRequest)
 
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerritTwice.scala b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerritTwice.scala
new file mode 100644
index 0000000..81e7578
--- /dev/null
+++ b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerritTwice.scala
@@ -0,0 +1,52 @@
+// 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.googlesource.gerrit.plugins.multisite.scenarios
+
+import com.google.gerrit.scenarios.GitSimulation
+import io.gatling.core.Predef.{atOnceUsers, _}
+
+import scala.concurrent.duration._
+
+class CreateProjectUsingMultiGerritTwice extends GitSimulation {
+  private val default: String = name
+
+  private val createProject = new CreateProjectUsingMultiGerrit(default)
+  private val deleteProject = new DeleteProjectUsingMultiGerrit(default)
+  private val createItAgain = new CreateProjectUsingMultiGerrit(default)
+  private val verifyProject = new CloneUsingMultiGerrit1(default)
+  private val deleteItAfter = new DeleteProjectUsingMultiGerrit(default)
+
+  setUp(
+    createProject.test.inject(
+      atOnceUsers(1)
+    ),
+    deleteProject.test.inject(
+      nothingFor(21 seconds),
+      atOnceUsers(1)
+    ),
+    createItAgain.test.inject(
+      nothingFor(43 seconds),
+      atOnceUsers(1)
+    ),
+    verifyProject.test.inject(
+      nothingFor(70 seconds),
+      atOnceUsers(1)
+    ),
+    deleteItAfter.test.inject(
+      nothingFor(72 seconds),
+      atOnceUsers(1)
+    ),
+  ).protocols(gitProtocol, httpProtocol)
+}
diff --git a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteProjectUsingMultiGerrit.scala b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteProjectUsingMultiGerrit.scala
index ee645a9..674f1b3 100644
--- a/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteProjectUsingMultiGerrit.scala
+++ b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteProjectUsingMultiGerrit.scala
@@ -27,7 +27,7 @@
     this.default = default
   }
 
-  val test: ScenarioBuilder = scenario(name)
+  val test: ScenarioBuilder = scenario(unique)
     .feed(data)
     .exec(httpRequest)