e2e-tests: Introduce a CloneUsingHAGerrit2 scenario

Do so in order to start testing basic HA through that example scenario.
Add a corresponding initial section to the docker tests documentation.
Base that HA plugin-specific scenario on Gerrit core's emerging Gatling
framework.

Add the CreateProjectUsingHAGerrit1 and DeleteProjectUsingHAGerrit
companion scenarios, reused by CloneUsingHAGerrit2, following the
recently established reusability aspect of the framework. As usual with
the framework so far, make these scenario classes automatically use
their corresponding json data files.

Change-Id: Ibd27120d1dcf629e465ba2c4ef37cb238c7984d0
(cherry picked from commit a147e4a8c45beea0fd33e377158fe523915b3d26)
diff --git a/src/test/README.md b/src/test/README.md
new file mode 100644
index 0000000..c7a5225
--- /dev/null
+++ b/src/test/README.md
@@ -0,0 +1,8 @@
+# About this directory structure
+
+Refer to docker/README.md for more about these directory structures:
+
+```
+  ./resources/com
+  ./scala
+```
diff --git a/src/test/docker/README.md b/src/test/docker/README.md
index 68030ae..d97e929 100644
--- a/src/test/docker/README.md
+++ b/src/test/docker/README.md
@@ -39,6 +39,30 @@
   $ docker-compose up
 ```
 
+## How to test
+
+Consider the
+[instructions](https://gerrit-review.googlesource.com/Documentation/dev-e2e-tests.html)
+on how to use Gerrit core's Gatling framework, to run non-core test
+scenarios such as this plugin one below:
+
+```
+  $ sbt "gatling:testOnly com.ericsson.gerrit.plugins.highavailability.scenarios.CloneUsingHAGerrit2"
+```
+
+This is a scenario that can serve as an example for how to start
+testing an HA Gerrit system. That scenario tries to clone a project
+created on gerrit 1 (port 8081) but from gerrit 2 (on 8082). The
+scenario therefore expects Gerrit HA to have properly synchronized
+the new project from 1 to 2. That project gets deleted after, here
+using HA Gerrit straight (no specific port).
+
+Scenario scala source files and their companion json resource ones are
+stored under the usual src/test directories. That structure follows the
+scala package one from the scenario classes. The core framework expects
+such a directory structure for both the scala and resources (json data)
+files.
+
 ## How to stop
 
 Simply type CTRL+C on the window that started the environment
@@ -53,4 +77,3 @@
 ```
   $ docker-compose down
 ```
-
diff --git a/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.json b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.json
new file mode 100644
index 0000000..228b5e8
--- /dev/null
+++ b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.json
@@ -0,0 +1,6 @@
+[
+  {
+    "url": "http://localhost:8082/loadtest-repo",
+    "cmd": "clone"
+  }
+]
diff --git a/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.json b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.json
new file mode 100644
index 0000000..bee4090
--- /dev/null
+++ b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.json
@@ -0,0 +1,5 @@
+[
+  {
+    "url": "http://localhost:8081/a/projects/loadtest-repo"
+  }
+]
diff --git a/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.json b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.json
new file mode 100644
index 0000000..85afaad
--- /dev/null
+++ b/src/test/resources/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.json
@@ -0,0 +1,5 @@
+[
+  {
+    "url": "http://localhost/a/projects/loadtest-repo/delete-project~delete"
+  }
+]
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
new file mode 100644
index 0000000..20ce2f5
--- /dev/null
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CloneUsingHAGerrit2.scala
@@ -0,0 +1,47 @@
+// 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 io.gatling.core.feeder.FileBasedFeederBuilder
+import io.gatling.core.structure.ScenarioBuilder
+
+import scala.concurrent.duration._
+
+class CloneUsingHAGerrit2 extends GitSimulation {
+  private val data: FileBasedFeederBuilder[Any]#F = jsonFile(added).queue
+
+  private val test: ScenarioBuilder = scenario(name)
+    .feed(data)
+    .exec(gitRequest)
+
+  private val createProject = new CreateProjectUsingHAGerrit1
+  private val deleteProject = new DeleteProjectUsingHAGerrit
+
+  setUp(
+    createProject.test.inject(
+      atOnceUsers(1)
+    ),
+    test.inject(
+      nothingFor(1 second),
+      atOnceUsers(1)
+    ),
+    deleteProject.test.inject(
+      nothingFor(3 second),
+      atOnceUsers(1)
+    ),
+  ).protocols(gitProtocol, httpProtocol)
+}
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
new file mode 100644
index 0000000..eeaaf82
--- /dev/null
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/CreateProjectUsingHAGerrit1.scala
@@ -0,0 +1,33 @@
+// 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.GerritSimulation
+import io.gatling.core.Predef._
+import io.gatling.core.feeder.FileBasedFeederBuilder
+import io.gatling.core.structure.ScenarioBuilder
+
+class CreateProjectUsingHAGerrit1 extends GerritSimulation {
+  private val data: FileBasedFeederBuilder[Any]#F = jsonFile(added).queue
+
+  val test: ScenarioBuilder = scenario(name)
+    .feed(data)
+    .exec(httpRequest)
+
+  setUp(
+    test.inject(
+      atOnceUsers(1)
+    )).protocols(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
new file mode 100644
index 0000000..0e4038f
--- /dev/null
+++ b/src/test/scala/com/ericsson/gerrit/plugins/highavailability/scenarios/DeleteProjectUsingHAGerrit.scala
@@ -0,0 +1,33 @@
+// 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.GerritSimulation
+import io.gatling.core.Predef._
+import io.gatling.core.feeder.FileBasedFeederBuilder
+import io.gatling.core.structure.ScenarioBuilder
+
+class DeleteProjectUsingHAGerrit extends GerritSimulation {
+  private val data: FileBasedFeederBuilder[Any]#F = jsonFile(added).queue
+
+  val test: ScenarioBuilder = scenario(name)
+    .feed(data)
+    .exec(httpRequest)
+
+  setUp(
+    test.inject(
+      atOnceUsers(1)
+    )).protocols(httpProtocol)
+}