e2e-tests: Add the CreateProjectUsingHAGerritTwice scenario

Add the CreateProjectUsingHAGerritTwice scenario to test if deleting a
project carries over to the other HA Gerrit node. Adapt the
CloneUsingHAGerrit2 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 CreateProjectUsingHAGerritTwice 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: I93ca6bed9b654ada976cb3ed132bc48bf3bd8635
diff --git a/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerritTwice.json b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerritTwice.json
new file mode 100644
index 0000000..da1a058
--- /dev/null
+++ b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerritTwice.json
@@ -0,0 +1,4 @@
+[
+  {
+  }
+]
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.scala
index 9d4d582..fc08099 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.scala
@@ -23,14 +23,19 @@
 
 class CloneUsingHAGerrit2 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_port2", 8082, 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/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.scala
index ad2cbd9..958fd1e 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.scala
@@ -32,7 +32,7 @@
     super.replaceOverride(next)
   }
 
-  val test: ScenarioBuilder = scenario(name)
+  val test: ScenarioBuilder = scenario(unique)
     .feed(data)
     .exec(httpRequest)
 
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerritTwice.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerritTwice.scala
new file mode 100644
index 0000000..44da7db
--- /dev/null
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerritTwice.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.ericsson.gerrit.plugins.highavailability.scenarios
+
+import com.google.gerrit.scenarios.GitSimulation
+import io.gatling.core.Predef.{atOnceUsers, _}
+
+import scala.concurrent.duration._
+
+class CreateProjectUsingHAGerritTwice extends GitSimulation {
+  private val default: String = name
+
+  private val createProject = new CreateProjectUsingHAGerrit1(default)
+  private val deleteProject = new DeleteProjectUsingHAGerrit(default)
+  private val createItAgain = new CreateProjectUsingHAGerrit1(default)
+  private val verifyProject = new CloneUsingHAGerrit2(default)
+  private val deleteItAfter = new DeleteProjectUsingHAGerrit(default)
+
+  setUp(
+    createProject.test.inject(
+      atOnceUsers(1)
+    ),
+    deleteProject.test.inject(
+      nothingFor(2 seconds),
+      atOnceUsers(1)
+    ),
+    createItAgain.test.inject(
+      nothingFor(4 seconds),
+      atOnceUsers(1)
+    ),
+    verifyProject.test.inject(
+      nothingFor(6 seconds),
+      atOnceUsers(1)
+    ),
+    deleteItAfter.test.inject(
+      nothingFor(8 seconds),
+      atOnceUsers(1)
+    ),
+  ).protocols(gitProtocol, httpProtocol)
+}
diff --git a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.scala b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.scala
index 091cd7b..b0232e6 100644
--- a/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.scala
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.scala
@@ -27,7 +27,7 @@
     this.default = default
   }
 
-  val test: ScenarioBuilder = scenario(name)
+  val test: ScenarioBuilder = scenario(unique)
     .feed(data)
     .exec(httpRequest)