e2e-tests: Add JAVA_OPTS support to the framework
Unhardcode hostname and port values to start with, which typically vary across test execution environments or deployments. This allows for less json scenario data file duplication and proliferation. Base this JAVA_OPTS solution on [1] below. If no JAVA_OPTS property|ies gets defined in the scenario execution shell environment, use the well-known default value(s) coded in. Document how to use JAVA_OPTS. Adapt the showcase core CloneUsingBothProtocols and aggregated project scenarios accordingly. Make them reuse core's amended GerritSimulation. [1] https://gatling.io/docs/current/cookbook/passing_parameters Change-Id: I45cf4b7ccf5cc51c8bd31fedbac99ae4bed053bb
This commit is contained in:
@@ -21,7 +21,7 @@ import io.gatling.core.structure.ScenarioBuilder
|
||||
import scala.concurrent.duration._
|
||||
|
||||
class CloneUsingBothProtocols extends GitSimulation {
|
||||
private val data: FileBasedFeederBuilder[Any]#F = jsonFile(resource).queue
|
||||
private val data: FileBasedFeederBuilder[Any]#F#F = jsonFile(resource).convert(url).queue
|
||||
|
||||
private val test: ScenarioBuilder = scenario(name)
|
||||
.feed(data)
|
||||
|
@@ -19,7 +19,7 @@ import io.gatling.core.feeder.FileBasedFeederBuilder
|
||||
import io.gatling.core.structure.ScenarioBuilder
|
||||
|
||||
class CreateProject extends GerritSimulation {
|
||||
private val data: FileBasedFeederBuilder[Any]#F = jsonFile(resource).queue
|
||||
private val data: FileBasedFeederBuilder[Any]#F#F = jsonFile(resource).convert(url).queue
|
||||
|
||||
val test: ScenarioBuilder = scenario(name)
|
||||
.feed(data)
|
||||
|
@@ -19,7 +19,7 @@ import io.gatling.core.feeder.FileBasedFeederBuilder
|
||||
import io.gatling.core.structure.ScenarioBuilder
|
||||
|
||||
class DeleteProject extends GerritSimulation {
|
||||
private val data: FileBasedFeederBuilder[Any]#F = jsonFile(resource).queue
|
||||
private val data: FileBasedFeederBuilder[Any]#F#F = jsonFile(resource).convert(url).queue
|
||||
|
||||
val test: ScenarioBuilder = scenario(name)
|
||||
.feed(data)
|
||||
|
@@ -23,7 +23,8 @@ import io.gatling.http.request.builder.HttpRequestBuilder
|
||||
class GerritSimulation extends Simulation {
|
||||
implicit val conf: GatlingGitConfiguration = GatlingGitConfiguration()
|
||||
|
||||
private val path: String = this.getClass.getPackage.getName.replaceAllLiterally(".", "/")
|
||||
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"
|
||||
|
||||
@@ -31,4 +32,27 @@ class GerritSimulation extends Simulation {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user