Merge branch 'stable-3.1'

* stable-3.1:
  e2e-tests: Introduce a CloneUsingMultiGerrit1 scenario

Change-Id: I3548a473fc22de99dde850b33b77540f573c90d9
diff --git a/dockerised_local_env/.gitignore b/dockerised_local_env/.gitignore
index 36a108e..bc7d3f3 100644
--- a/dockerised_local_env/.gitignore
+++ b/dockerised_local_env/.gitignore
@@ -24,5 +24,7 @@
 /gerrit-2/ssh/known_hosts
 /gerrit-2/tmp/
 
+/gerrit-common/shared-dir/
+
 /syslog-sidecar/logs/
 /syslog-sidecar/socket/
diff --git a/dockerised_local_env/Makefile b/dockerised_local_env/Makefile
index f02695b..d48a672 100644
--- a/dockerised_local_env/Makefile
+++ b/dockerised_local_env/Makefile
@@ -20,6 +20,7 @@
 
 download: gerrit plugin_websession_flatfile \
 	plugin_healthcheck \
+	plugin_delete_project \
 	plugin_multi_site
 
 
@@ -42,6 +43,10 @@
 	$(WGET) $(CI_URL)/plugin-healthcheck-bazel-stable-2.16/lastSuccessfulBuild/artifact/bazel-bin/plugins/healthcheck/healthcheck.jar -P $(GERRIT_1_PLUGINS_DIRECTORY)
 	cp $(GERRIT_1_PLUGINS_DIRECTORY)/healthcheck.jar $(GERRIT_2_PLUGINS_DIRECTORY)/healthcheck.jar
 
+plugin_delete_project: prepare
+	$(WGET) $(CI_URL)/plugin-delete-project-bazel-stable-2.16/lastSuccessfulBuild/artifact/bazel-bin/plugins/delete-project/delete-project.jar -P $(GERRIT_1_PLUGINS_DIRECTORY)
+	cp $(GERRIT_1_PLUGINS_DIRECTORY)/delete-project.jar $(GERRIT_2_PLUGINS_DIRECTORY)/delete-project.jar
+
 build:
 	docker build -t $(MYDIR) ./gerrit-1
 	docker build -t $(MYDIR) ./gerrit-2
diff --git a/dockerised_local_env/README.md b/dockerised_local_env/README.md
index 8c2bf41..92be0cd 100644
--- a/dockerised_local_env/README.md
+++ b/dockerised_local_env/README.md
@@ -39,3 +39,26 @@
 ```bash
 make restart_gerrit_1 # (or make restart_gerrit_2)
 ```
+
+## 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:
+
+```bash
+sbt "gatling:testOnly com.googlesource.gerrit.plugins.multisite.scenarios.CloneUsingMultiGerrit1"
+```
+
+This is a scenario that can serve as an example for how to start testing a
+multi-site Gerrit system, here such as this dockerized one. That scenario tries
+to clone a project created on this dockerized multi Gerrit, from gerrit-1 (port
+8081). The scenario therefore expects Gerrit multi-site to have properly
+synchronized the new project from the up node gerrit-2 to gerrit-1. That
+project gets deleted after by the (so aggregate) scenario.
+
+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.
diff --git a/src/test/README.md b/src/test/README.md
new file mode 100644
index 0000000..0fe89c6
--- /dev/null
+++ b/src/test/README.md
@@ -0,0 +1,8 @@
+# About this directory structure
+
+Refer to ../../dockerised_local_env/README.md for more about these directory structures:
+
+```bash
+  ./resources/com
+  ./scala
+```
diff --git a/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/CloneUsingMultiGerrit1.json b/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/CloneUsingMultiGerrit1.json
new file mode 100644
index 0000000..37891ad
--- /dev/null
+++ b/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/CloneUsingMultiGerrit1.json
@@ -0,0 +1,6 @@
+[
+  {
+    "url": "http://localhost:8081/loadtest-repo",
+    "cmd": "clone"
+  }
+]
diff --git a/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerrit.json b/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerrit.json
new file mode 100644
index 0000000..2e54de5
--- /dev/null
+++ b/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerrit.json
@@ -0,0 +1,5 @@
+[
+  {
+    "url": "http://localhost:8080/a/projects/loadtest-repo"
+  }
+]
diff --git a/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteProjectUsingMultiGerrit.json b/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteProjectUsingMultiGerrit.json
new file mode 100644
index 0000000..9312fb4
--- /dev/null
+++ b/src/test/resources/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteProjectUsingMultiGerrit.json
@@ -0,0 +1,5 @@
+[
+  {
+    "url": "http://localhost:8080/a/projects/loadtest-repo/delete-project~delete"
+  }
+]
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
new file mode 100644
index 0000000..5a26360
--- /dev/null
+++ b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CloneUsingMultiGerrit1.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.googlesource.gerrit.plugins.multisite.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 CloneUsingMultiGerrit1 extends GitSimulation {
+  private val data: FileBasedFeederBuilder[Any]#F = jsonFile(resource).queue
+
+  private val test: ScenarioBuilder = scenario(name)
+    .feed(data)
+    .exec(gitRequest)
+
+  private val createProject = new CreateProjectUsingMultiGerrit
+  private val deleteProject = new DeleteProjectUsingMultiGerrit
+
+  setUp(
+    createProject.test.inject(
+      atOnceUsers(1)
+    ),
+    test.inject(
+      nothingFor(21 second),
+      atOnceUsers(1)
+    ),
+    deleteProject.test.inject(
+      nothingFor(23 second),
+      atOnceUsers(1)
+    ),
+  ).protocols(gitProtocol, httpProtocol)
+}
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
new file mode 100644
index 0000000..8f46a2a
--- /dev/null
+++ b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/CreateProjectUsingMultiGerrit.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.googlesource.gerrit.plugins.multisite.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 CreateProjectUsingMultiGerrit extends GerritSimulation {
+  private val data: FileBasedFeederBuilder[Any]#F = jsonFile(resource).queue
+
+  val test: ScenarioBuilder = scenario(name)
+    .feed(data)
+    .exec(httpRequest)
+
+  setUp(
+    test.inject(
+      atOnceUsers(1)
+    )).protocols(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
new file mode 100644
index 0000000..628edfc
--- /dev/null
+++ b/src/test/scala/com/googlesource/gerrit/plugins/multisite/scenarios/DeleteProjectUsingMultiGerrit.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.googlesource.gerrit.plugins.multisite.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 DeleteProjectUsingMultiGerrit extends GerritSimulation {
+  private val data: FileBasedFeederBuilder[Any]#F = jsonFile(resource).queue
+
+  val test: ScenarioBuilder = scenario(name)
+    .feed(data)
+    .exec(httpRequest)
+
+  setUp(
+    test.inject(
+      atOnceUsers(1)
+    )).protocols(httpProtocol)
+}