From 576ba0d9569da01912e1f98dde4ba7ebf183fccd Mon Sep 17 00:00:00 2001 From: dan mcweeney Date: Mon, 21 Oct 2019 11:48:31 -0400 Subject: [PATCH] Update gatling to support JDK11 --- tests/performance/gatling_tests/build.gradle | 9 ++++++++- .../BlockingInvokeOneActionSimulation.scala | 13 +++++------- .../ColdBlockingInvokeSimulation.scala | 7 +++---- .../apache/openwhisk/LatencySimulation.scala | 20 +++++++++---------- .../whisk/OpenWhiskProtocolBuilder.scala | 4 ++-- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/tests/performance/gatling_tests/build.gradle b/tests/performance/gatling_tests/build.gradle index 3bf4c9bd8e8..b7d43af5c81 100644 --- a/tests/performance/gatling_tests/build.gradle +++ b/tests/performance/gatling_tests/build.gradle @@ -16,7 +16,7 @@ */ plugins { - id "com.github.lkishalmi.gatling" version "0.7.2" + id "com.github.lkishalmi.gatling" version "3.2.9" } apply plugin: 'eclipse' @@ -26,6 +26,13 @@ repositories { mavenCentral() } +sourceSets { + gatling { + scala.srcDirs = ["src/gatling/scala/"] + resources.srcDirs = ["src/gatling/resoruces/"] + } +} + dependencies { gatling "io.spray:spray-json_2.12:1.3.4" gatling "commons-io:commons-io:2.6" diff --git a/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/BlockingInvokeOneActionSimulation.scala b/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/BlockingInvokeOneActionSimulation.scala index 4fb25406db2..c9588eb9c1e 100644 --- a/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/BlockingInvokeOneActionSimulation.scala +++ b/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/BlockingInvokeOneActionSimulation.scala @@ -23,8 +23,7 @@ import org.apache.openwhisk.extension.whisk.OpenWhiskProtocolBuilder import org.apache.openwhisk.extension.whisk.Predef._ import io.gatling.core.Predef._ import io.gatling.core.structure.ScenarioBuilder -import io.gatling.core.util.Resource -import org.apache.commons.io.FileUtils +import io.gatling.core.util.ClasspathPackagedResource import scala.concurrent.duration._ @@ -56,12 +55,10 @@ class BlockingInvokeOneActionSimulation extends Simulation { // Define scenario val test: ScenarioBuilder = scenario(s"Invoke one ${if (async) "async" else "sync"} action blocking") .doIf(_.userId == 1) { - exec( - openWhisk("Create action") - .authenticate(uuid, key) - .action(actionName) - .create(FileUtils - .readFileToString(Resource.body(actionfile).get.file, StandardCharsets.UTF_8))) + exec(openWhisk("Create action") + .authenticate(uuid, key) + .action(actionName) + .create(ClasspathPackagedResource(actionfile, getClass.getResource(actionfile)).string(StandardCharsets.UTF_8))) } .rendezVous(connections) .during(5.seconds) { diff --git a/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/ColdBlockingInvokeSimulation.scala b/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/ColdBlockingInvokeSimulation.scala index 81acdb067b1..44cbf526d42 100644 --- a/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/ColdBlockingInvokeSimulation.scala +++ b/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/ColdBlockingInvokeSimulation.scala @@ -24,8 +24,7 @@ import org.apache.openwhisk.extension.whisk.Predef._ import io.gatling.core.Predef._ import io.gatling.core.session.Expression import io.gatling.core.structure.ScenarioBuilder -import io.gatling.core.util.Resource -import org.apache.commons.io.FileUtils +import io.gatling.core.util.ClasspathPackagedResource import scala.concurrent.duration._ @@ -84,8 +83,8 @@ class ColdBlockingInvokeSimulation extends Simulation { } private def actionCode = { - val code = FileUtils - .readFileToString(Resource.body("nodeJSAction.js").get.file, StandardCharsets.UTF_8) + val code = ClasspathPackagedResource("nodeJSAction.js", getClass.getResource("nodeJSAction.js")) + .string(StandardCharsets.UTF_8) //Pad the code with empty space to increase the stored code size if (codeSize > 0) code + " " * codeSize else code } diff --git a/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/LatencySimulation.scala b/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/LatencySimulation.scala index 34eeee23fc7..6080558c202 100644 --- a/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/LatencySimulation.scala +++ b/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/LatencySimulation.scala @@ -23,8 +23,7 @@ import java.util.Base64 import org.apache.openwhisk.extension.whisk.Predef._ import io.gatling.core.Predef._ import io.gatling.core.session.Expression -import io.gatling.core.util.Resource -import org.apache.commons.io.FileUtils +import io.gatling.core.util.ClasspathPackagedResource import scala.concurrent.duration._ @@ -65,14 +64,15 @@ class LatencySimulation extends Simulation { * `main` is only needed for java. This is the name of the class where the main method is located. */ val actions: Seq[(String, String, String, String)] = Map( - "nodejs:default" -> (FileUtils - .readFileToString(Resource.body("nodeJSAction.js").get.file, StandardCharsets.UTF_8), "latencyTest_node", ""), - "python:default" -> (FileUtils - .readFileToString(Resource.body("pythonAction.py").get.file, StandardCharsets.UTF_8), "latencyTest_python", ""), - "swift:default" -> (FileUtils - .readFileToString(Resource.body("swiftAction.swift").get.file, StandardCharsets.UTF_8), "latencyTest_swift", ""), - "java:default" -> (Base64.getEncoder.encodeToString( - FileUtils.readFileToByteArray(Resource.body("javaAction.jar").get.file)), "latencyTest_java", "JavaAction")) + "nodejs:default" -> (ClasspathPackagedResource("nodeJSAction.js", getClass.getResource("nodeJSAction.js")).string( + StandardCharsets.UTF_8), "latencyTest_node", ""), + "python:default" -> (ClasspathPackagedResource("pythonAction.py", getClass.getResource("pythonAction.py")).string( + StandardCharsets.UTF_8), "latencyTest_python", ""), + "swift:default" -> (ClasspathPackagedResource("swiftAction.swift", getClass.getResource("swiftAction.swift")) + .string(StandardCharsets.UTF_8), "latencyTest_swift", ""), + "java:default" -> (Base64.getEncoder.encodeToString(ClasspathPackagedResource( + "javaAction.jar", + getClass.getResource("javaAction.jar")).bytes), "latencyTest_java", "JavaAction")) .filterNot(e => excludedKinds.contains(e._1)) .map { case (kind, (code, name, main)) => diff --git a/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/extension/whisk/OpenWhiskProtocolBuilder.scala b/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/extension/whisk/OpenWhiskProtocolBuilder.scala index a3564e98b76..8a0ac133127 100644 --- a/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/extension/whisk/OpenWhiskProtocolBuilder.scala +++ b/tests/performance/gatling_tests/src/gatling/scala/org/apache/openwhisk/extension/whisk/OpenWhiskProtocolBuilder.scala @@ -20,9 +20,9 @@ package org.apache.openwhisk.extension.whisk import java.net.URL import com.softwaremill.quicklens._ -import io.gatling.core.Predef._ import io.gatling.core.config.GatlingConfiguration import io.gatling.http.Predef._ +import io.gatling.core.Predef._ import io.gatling.http.protocol.HttpProtocol import scala.language.implicitConversions @@ -72,7 +72,7 @@ case class OpenWhiskProtocolBuilder(private val protocol: OpenWhiskProtocol) { /** build the http protocol with the parameters provided by the openwhisk-protocol. */ def build(implicit configuration: GatlingConfiguration) = { http - .baseURL(s"${protocol.protocol}://${protocol.apiHost}:${protocol.port}") + .baseUrl(s"${protocol.protocol}://${protocol.apiHost}:${protocol.port}") .contentTypeHeader("application/json") .userAgentHeader("gatlingLoadTest") .warmUp("http://google.com")