blob: a159977edfa7e4c8314fdd25bf6bd52637b016be [file] [log] [blame]
// 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 com.github.barbasa.gatling.git.GatlingGitConfiguration
import io.gatling.core.Predef._
import io.gatling.http.Predef.http
import io.gatling.http.protocol.HttpProtocolBuilder
import io.gatling.http.request.builder.HttpRequestBuilder
class GerritSimulation extends Simulation {
implicit val conf: GatlingGitConfiguration = GatlingGitConfiguration()
private val pack: String = this.getClass.getPackage.getName
private val path: String = pack.replaceAllLiterally(".", "/")
protected val name: String = this.getClass.getSimpleName
protected val resource: String = s"data/$path/$name.json"
protected val httpRequest: HttpRequestBuilder = http(name).post("${url}")
protected val httpProtocol: HttpProtocolBuilder = http.basicAuth(
conf.httpConfiguration.userName,
conf.httpConfiguration.password)
protected val url: PartialFunction[(String, Any), Any] = {
case ("url", url) =>
var in = replaceProperty("hostname", "localhost", url.toString)
in = replaceProperty("http_port", 8080, in)
replaceProperty("ssh_port", 29418, in)
}
private def replaceProperty(term: String, default: Any, in: String): String = {
val key: String = term.toUpperCase
val property = pack + "." + term
var value = default
default match {
case _: String =>
val propertyValue = Option(System.getProperty(property))
if (propertyValue.nonEmpty) {
value = propertyValue.get
}
case _: Integer =>
value = Integer.getInteger(property, default.asInstanceOf[Integer])
}
in.replaceAllLiterally(key, value.toString)
}
}