From d54dfb17efc6bfff352dca7aec092643b5916bc2 Mon Sep 17 00:00:00 2001 From: Marco Miller Date: Mon, 4 May 2020 13:30:33 -0400 Subject: [PATCH] e2e-tests: Add FlushProjectsCache related scenarios Add a FlushProjectsCache scenario to this core framework. Make it reuse the added GetProjectsCacheEntries and CheckProjectsCacheFlushEntries scenarios, which can also be run independently as usual. Make all these added scenarios extend the introduced CacheFlushSimulation core class, for consistency and further reusability purposes. In order for CheckProjectsCacheFlushEntries to run independently, as opposed to otherwise being composed, introduce the PROJECTS_ENTRIES optional JAVA_OPTS property ([1]). Default that value to 1, based on the initial projects cache cardinality showed by locally testing this case. [1] https://gerrit-review.googlesource.com/Documentation/dev-e2e-tests.html#_environment_properties Change-Id: Ic5b6554332730763b538767d4946787d37baa9c1 --- .../CheckProjectsCacheFlushEntries.json | 6 ++ .../gerrit/scenarios/FlushProjectsCache.json | 5 ++ .../scenarios/GetProjectsCacheEntries.json | 5 ++ .../scenarios/CacheFlushSimulation.scala | 32 ++++++++++ .../CheckProjectsCacheFlushEntries.scala | 48 +++++++++++++++ .../gerrit/scenarios/FlushProjectsCache.scala | 60 +++++++++++++++++++ .../gerrit/scenarios/GerritSimulation.scala | 2 + .../scenarios/GetProjectsCacheEntries.scala | 45 ++++++++++++++ 8 files changed, 203 insertions(+) create mode 100644 e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/CheckProjectsCacheFlushEntries.json create mode 100644 e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/FlushProjectsCache.json create mode 100644 e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/GetProjectsCacheEntries.json create mode 100644 e2e-tests/src/test/scala/com/google/gerrit/scenarios/CacheFlushSimulation.scala create mode 100644 e2e-tests/src/test/scala/com/google/gerrit/scenarios/CheckProjectsCacheFlushEntries.scala create mode 100644 e2e-tests/src/test/scala/com/google/gerrit/scenarios/FlushProjectsCache.scala create mode 100644 e2e-tests/src/test/scala/com/google/gerrit/scenarios/GetProjectsCacheEntries.scala diff --git a/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/CheckProjectsCacheFlushEntries.json b/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/CheckProjectsCacheFlushEntries.json new file mode 100644 index 0000000000..6210deb684 --- /dev/null +++ b/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/CheckProjectsCacheFlushEntries.json @@ -0,0 +1,6 @@ +[ + { + "url": "http://HOSTNAME:HTTP_PORT/a/config/server/caches/projects", + "entries": "PROJECTS_ENTRIES" + } +] diff --git a/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/FlushProjectsCache.json b/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/FlushProjectsCache.json new file mode 100644 index 0000000000..9ff15a79b4 --- /dev/null +++ b/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/FlushProjectsCache.json @@ -0,0 +1,5 @@ +[ + { + "url": "http://HOSTNAME:HTTP_PORT/a/config/server/caches/projects/flush" + } +] diff --git a/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/GetProjectsCacheEntries.json b/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/GetProjectsCacheEntries.json new file mode 100644 index 0000000000..fcf4bc9ada --- /dev/null +++ b/e2e-tests/src/test/resources/data/com/google/gerrit/scenarios/GetProjectsCacheEntries.json @@ -0,0 +1,5 @@ +[ + { + "url": "http://HOSTNAME:HTTP_PORT/a/config/server/caches/projects" + } +] diff --git a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/CacheFlushSimulation.scala b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/CacheFlushSimulation.scala new file mode 100644 index 0000000000..98d0190a8a --- /dev/null +++ b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/CacheFlushSimulation.scala @@ -0,0 +1,32 @@ +// 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 + +class CacheFlushSimulation extends GerritSimulation { + protected val entriesKey = "entries" + protected val memKey = "mem" + protected var producer: Option[CacheFlushSimulation] = None + protected var consumer: Option[CacheFlushSimulation] = None + + private var cacheEntriesBeforeFlush: Int = 0 + + def entriesBeforeFlush(entries: Int): Unit = { + cacheEntriesBeforeFlush = entries + } + + def expectedEntriesAfterFlush(): Int = { + cacheEntriesBeforeFlush - 1 + } +} diff --git a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/CheckProjectsCacheFlushEntries.scala b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/CheckProjectsCacheFlushEntries.scala new file mode 100644 index 0000000000..040e5cfd1c --- /dev/null +++ b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/CheckProjectsCacheFlushEntries.scala @@ -0,0 +1,48 @@ +// 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.{atOnceUsers, _} +import io.gatling.core.feeder.FeederBuilder +import io.gatling.core.structure.ScenarioBuilder +import io.gatling.http.Predef._ + +class CheckProjectsCacheFlushEntries extends CacheFlushSimulation { + private val data: FeederBuilder = jsonFile(resource).convert(keys).queue + + def this(producer: CacheFlushSimulation) { + this() + this.producer = Some(producer) + } + + val test: ScenarioBuilder = scenario(unique) + .feed(data) + .exec(session => { + if (producer.nonEmpty) { + session.set(entriesKey, producer.get.expectedEntriesAfterFlush()) + } else { + session + } + }) + .exec(http(unique).get("${url}") + .check(regex("\"" + memKey + "\": (\\d+)") + .is(session => session(entriesKey).as[String]))) + + setUp( + test.inject( + atOnceUsers(1) + ), + ).protocols(httpProtocol) +} diff --git a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/FlushProjectsCache.scala b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/FlushProjectsCache.scala new file mode 100644 index 0000000000..94f4ae3e8e --- /dev/null +++ b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/FlushProjectsCache.scala @@ -0,0 +1,60 @@ +// 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 FlushProjectsCache extends CacheFlushSimulation { + private val data: FeederBuilder = jsonFile(resource).convert(keys).queue + private val default: String = name + + override def relativeRuntimeWeight = 2 + + private val flushCache: ScenarioBuilder = scenario(unique) + .feed(data) + .exec(httpRequest) + + private val createProject = new CreateProject(default) + private val getCacheEntriesAfterProject = new GetProjectsCacheEntries(this) + private val checkCacheEntriesAfterFlush = new CheckProjectsCacheFlushEntries(this) + private val deleteProject = new DeleteProject(default) + + setUp( + createProject.test.inject( + nothingFor(stepWaitTime(createProject) seconds), + atOnceUsers(1) + ), + getCacheEntriesAfterProject.test.inject( + nothingFor(stepWaitTime(getCacheEntriesAfterProject) seconds), + atOnceUsers(1) + ), + flushCache.inject( + nothingFor(stepWaitTime(this) seconds), + atOnceUsers(1) + ), + checkCacheEntriesAfterFlush.test.inject( + nothingFor(stepWaitTime(checkCacheEntriesAfterFlush) seconds), + atOnceUsers(1) + ), + deleteProject.test.inject( + nothingFor(stepWaitTime(deleteProject) seconds), + atOnceUsers(1) + ), + ).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 36df62797f..fb79f80a55 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 @@ -68,6 +68,8 @@ class GerritSimulation extends Simulation { case ("project", project) => val precedes = replaceKeyWith("_project", name, project.toString) replaceProperty("project", precedes) + case ("entries", entries) => + replaceProperty("projects_entries", "1", entries.toString) } private def replaceProperty(term: String, in: String): String = { diff --git a/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GetProjectsCacheEntries.scala b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GetProjectsCacheEntries.scala new file mode 100644 index 0000000000..27e3f190bc --- /dev/null +++ b/e2e-tests/src/test/scala/com/google/gerrit/scenarios/GetProjectsCacheEntries.scala @@ -0,0 +1,45 @@ +// 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 io.gatling.http.Predef.{http, _} + +class GetProjectsCacheEntries extends CacheFlushSimulation { + private val data: FeederBuilder = jsonFile(resource).convert(keys).queue + + def this(consumer: CacheFlushSimulation) { + this() + this.consumer = Some(consumer) + } + + val test: ScenarioBuilder = scenario(unique) + .feed(data) + .exec(http(unique).get("${url}") + .check(regex("\"" + memKey + "\": (\\d+)").saveAs(entriesKey))) + .exec(session => { + if (consumer.nonEmpty) { + consumer.get.entriesBeforeFlush(session(entriesKey).as[Int]) + } + session + }) + + setUp( + test.inject( + atOnceUsers(1) + )).protocols(httpProtocol) +}