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) +}