Browse Source

[Kotlin/Hexagon] Upgrade version and add support files (#5693)

* Update Hexagon benchmark

* Update Hexagon benchmark

* Remove features not used in tests

* Remove MySql storage

* Enable Resin test

* Upgrade Hexagon to v0.11

* Disable Resin

* Fix dependencies

* Improve template rendering

* Test in travis

* Fix build script

* Restore Travis script

* Restore Travis script

* MySQL store support and MongoDB fix

* Fix MySQL test

* Fix MySQL test

* Fix MySQL test

* Travis testing

* Fix MySQL test

* Restore Travis

* Take MySQL URL from other test

* Add PostgreSQL support

* Update version and tests

* Update version and tests

* Only test Hexagon in fork

* Fix config

* Fix config

* Update version and tests

* Remove Resin tests

* Restore Travis

* Restore Travis

* Upgrade framework version

* Reduce local tests temporarily

* Disable Resin tests

* Fix Gradle Wrapper issues

* Restore Resin tests

* Add Bintray repository

* Disable Resin backend

* Restore master's

* Upgrade framework version

* Test only Hexagon changes (temporary)

* Test Hexagon in Travis CI

* Add Undertow support

* Test only Undertow

* Restore Travis jobs

* Enable all Hexagon's variants

* Optimize benchmark

* Fix documentation

* Fix documentation

* Add Gradle Wrapper

* Move code to conform with Kotlin's coding standards

* Trace more information (only in tests)

* Add mini performance tests (to be sure everything would be fine in TFB)

* Support different template engines

* Add configuration properties

* Drop Undertow engine

* Update versions and dependencies

* Update documentation

* Ignore Gradle directories

* Update configuration

* Update benchmark

* Improve benchmark

* Improve benchmark dockerfiles

* Next Hexagon release

* Delete Gatlin simulation

* Fix url for testing

* Remove Gatling test

* Update Hexagon benchmark

* Improve data update test

* Merge Hexagon config

* Remove batch for updates benchmark

* Fix compilation problem

* Update Kotlin version

* Update dependencies and tools

* Move source files to their package directories

* Update Gradle version

* Update

* Update Hexagon version

* Update Hexagon version

* Update Hexagon version

* Disable logging

* Update versions

* Update versions

* Update Hexagon version

* Fix dockerfiles

* Fix link

* Add infrastructure to verify the benchmark before committing

These will be used only in this benchmark's development. The Dockerfiles to
generate the images won't run the tests or start testing infrastructure.

* Assure the benchmark behaves properly under light load

The tests will run only at development.

* Upgrade Hexagon and dependencies versions

* Delete unneeded settings

* Upgrade images versions

* Add missing Gradle Wrapper scripts

* Improve documentation

* Fix build problem (CURL not included in `slim` image)

* Fix pipeline

* Fix pipeline

* Add Docker images to Docker Compose to test containers

* Apply PR suggestions

Co-authored-by: Juanjo Aguililla <[email protected]>
Co-authored-by: jaguililla <[email protected]>
Juanjo Aguililla 5 years ago
parent
commit
f3a61d2c05

+ 0 - 5
frameworks/Kotlin/hexagon/.gitignore

@@ -1,5 +0,0 @@
-
-gradle/
-gradlew*
-
-src/test/scala/

+ 3 - 0
frameworks/Kotlin/hexagon/README.md

@@ -6,6 +6,9 @@ of web development platforms. The test utilizes Hexagon routes, serialization an
 
 ## Tests
 
+You can run tests against any running server passing the `verify.endpoint` project property. I.e.:
+`./gradlew verify -Pverify.endpoint=http://host:1234`
+
 * [Hexagon Web](src/main/kotlin/com/hexagonkt/Benchmark.kt)
 * [Hexagon Storage](src/main/kotlin/com/hexagonkt/BenchmarkStorage.kt)
 

+ 4 - 7
frameworks/Kotlin/hexagon/build.gradle

@@ -1,19 +1,16 @@
 
 plugins {
-    id "org.jetbrains.kotlin.jvm" version "1.3.61"
+    id "org.jetbrains.kotlin.jvm" version "1.3.72"
 }
 
 apply(from: "$gradleScripts/kotlin.gradle")
-apply(from: "$gradleScripts/service.gradle")
-apply(from: "$gradleScripts/testng.gradle")
+apply(from: "$gradleScripts/application.gradle")
+apply(from: "$gradleScripts/junit.gradle")
 
 apply(plugin: "war")
 
 defaultTasks("installDist")
 
-mainClassName = "com.hexagonkt.BenchmarkKt"
-applicationDefaultJvmArgs = [ "-XX:+UseNUMA", "-XX:+UseParallelGC" ]
-
 war {
     archiveFileName = "ROOT.war"
 }
@@ -31,5 +28,5 @@ dependencies {
     // providedCompile excludes the dependency only in the WAR, not in the distribution
     providedCompile("org.eclipse.jetty:jetty-webapp:$jettyVersion") { exclude module: "slf4j-api" }
 
-    testImplementation("com.hexagonkt:port_http_client:$hexagonVersion")
+    testImplementation("com.hexagonkt:http_client_ahc:$hexagonVersion")
 }

+ 6 - 7
frameworks/Kotlin/hexagon/gradle.properties

@@ -1,11 +1,10 @@
 description=Hexagon web framework's benchmark
-gradleScripts=https\://raw.githubusercontent.com/hexagonkt/hexagon/1.1.3/gradle
-hexagonVersion=1.1.3
-hikariVersion=3.4.1
-jettyVersion=9.4.24.v20191120
-kotlinCoroutinesVersion=1.3.3
-kotlinVersion=1.3.61
+gradleScripts=https\://raw.githubusercontent.com/hexagonkt/hexagon/1.2.16/gradle
+hexagonVersion=1.2.16
+hikariVersion=3.4.3
+jettyVersion=9.4.28.v20200408
 logbackVersion=1.2.3
+mainClassName=com.hexagonkt.BenchmarkKt
 name=hexagon
-postgresqlVersion=42.2.8
+postgresqlVersion=42.2.12
 testngVersion=6.14.3

BIN
frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.jar


+ 5 - 0
frameworks/Kotlin/hexagon/gradle/wrapper/gradle-wrapper.properties

@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists

+ 183 - 0
frameworks/Kotlin/hexagon/gradlew

@@ -0,0 +1,183 @@
+#!/usr/bin/env sh
+
+#
+# Copyright 2015 the original author or authors.
+#
+# 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
+#
+#      https://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.
+#
+
+##############################################################################
+##
+##  Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`"/$link"
+    fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+    echo "$*"
+}
+
+die () {
+    echo
+    echo "$*"
+    echo
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+  CYGWIN* )
+    cygwin=true
+    ;;
+  Darwin* )
+    darwin=true
+    ;;
+  MINGW* )
+    msys=true
+    ;;
+  NONSTOP* )
+    nonstop=true
+    ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+        # IBM's JDK on AIX uses strange locations for the executables
+        JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+        JAVACMD="$JAVA_HOME/bin/java"
+    fi
+    if [ ! -x "$JAVACMD" ] ; then
+        die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+    fi
+else
+    JAVACMD="java"
+    which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+    MAX_FD_LIMIT=`ulimit -H -n`
+    if [ $? -eq 0 ] ; then
+        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+            MAX_FD="$MAX_FD_LIMIT"
+        fi
+        ulimit -n $MAX_FD
+        if [ $? -ne 0 ] ; then
+            warn "Could not set maximum file descriptor limit: $MAX_FD"
+        fi
+    else
+        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+    fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
+    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+    JAVACMD=`cygpath --unix "$JAVACMD"`
+
+    # We build the pattern for arguments to be converted via cygpath
+    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+    SEP=""
+    for dir in $ROOTDIRSRAW ; do
+        ROOTDIRS="$ROOTDIRS$SEP$dir"
+        SEP="|"
+    done
+    OURCYGPATTERN="(^($ROOTDIRS))"
+    # Add a user-defined pattern to the cygpath arguments
+    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+    fi
+    # Now convert the arguments - kludge to limit ourselves to /bin/sh
+    i=0
+    for arg in "$@" ; do
+        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
+
+        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
+            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+        else
+            eval `echo args$i`="\"$arg\""
+        fi
+        i=`expr $i + 1`
+    done
+    case $i in
+        0) set -- ;;
+        1) set -- "$args0" ;;
+        2) set -- "$args0" "$args1" ;;
+        3) set -- "$args0" "$args1" "$args2" ;;
+        4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+        5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+        6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+        7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+        8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+        9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+    esac
+fi
+
+# Escape application args
+save () {
+    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+    echo " "
+}
+APP_ARGS=`save "$@"`
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+exec "$JAVACMD" "$@"

+ 103 - 0
frameworks/Kotlin/hexagon/gradlew.bat

@@ -0,0 +1,103 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem      https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem  Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega

+ 2 - 3
frameworks/Kotlin/hexagon/hexagon-jetty-postgresql.dockerfile

@@ -1,8 +1,7 @@
-
 #
 # BUILD
 #
-FROM gradle:5.5.1-jdk11 AS gradle_build
+FROM gradle:6.4-jdk11 AS gradle_build
 USER root
 WORKDIR /hexagon
 
@@ -14,7 +13,7 @@ RUN gradle --quiet --exclude-task test
 #
 # RUNTIME
 #
-FROM openjdk:11.0.3-jre-stretch
+FROM openjdk:11.0.7-jre-buster
 ENV DBSTORE postgresql
 ENV POSTGRESQL_DB_HOST tfb-database
 ENV WEBENGINE jetty

+ 3 - 4
frameworks/Kotlin/hexagon/hexagon-resin-mongodb.dockerfile

@@ -1,8 +1,7 @@
-
 #
 # BUILD
 #
-FROM gradle:5.5.1-jdk11 AS gradle_build
+FROM gradle:6.4-jdk11 AS gradle_build
 USER root
 WORKDIR /hexagon
 
@@ -14,10 +13,10 @@ RUN gradle --quiet --exclude-task test
 #
 # RUNTIME
 #
-FROM openjdk:11.0.3-jre-stretch
+FROM openjdk:11.0.7-jre-buster
 ENV DBSTORE mongodb
 ENV MONGODB_DB_HOST tfb-database
-ENV RESIN http://caucho.com/download/resin-4.0.61.tar.gz
+ENV RESIN http://caucho.com/download/resin-4.0.64.tar.gz
 
 WORKDIR /resin
 RUN curl -sL $RESIN | tar xz --strip-components=1

+ 3 - 4
frameworks/Kotlin/hexagon/hexagon-resin-postgresql.dockerfile

@@ -1,8 +1,7 @@
-
 #
 # BUILD
 #
-FROM gradle:5.5.1-jdk11 AS gradle_build
+FROM gradle:6.4-jdk11 AS gradle_build
 USER root
 WORKDIR /hexagon
 
@@ -14,10 +13,10 @@ RUN gradle --quiet --exclude-task test
 #
 # RUNTIME
 #
-FROM openjdk:11.0.3-jre-stretch
+FROM openjdk:11.0.7-jre-buster
 ENV DBSTORE postgresql
 ENV POSTGRESQL_DB_HOST tfb-database
-ENV RESIN http://caucho.com/download/resin-4.0.61.tar.gz
+ENV RESIN http://caucho.com/download/resin-4.0.64.tar.gz
 
 WORKDIR /resin
 RUN curl -sL $RESIN | tar xz --strip-components=1

+ 2 - 3
frameworks/Kotlin/hexagon/hexagon.dockerfile

@@ -1,8 +1,7 @@
-
 #
 # BUILD
 #
-FROM gradle:5.5.1-jdk11 AS gradle_build
+FROM gradle:6.4-jdk11 AS gradle_build
 USER root
 WORKDIR /hexagon
 
@@ -14,7 +13,7 @@ RUN gradle --quiet --exclude-task test
 #
 # RUNTIME
 #
-FROM openjdk:11.0.3-jre-stretch
+FROM openjdk:11.0.7-jre-buster
 ENV DBSTORE mongodb
 ENV MONGODB_DB_HOST tfb-database
 ENV WEBENGINE jetty

+ 10 - 9
frameworks/Kotlin/hexagon/src/main/kotlin/com/hexagonkt/Benchmark.kt

@@ -42,8 +42,8 @@ private val defaultLocale = Locale.getDefault()
 private val router: Router by lazy {
     Router {
         before {
-            response.setHeader("Server", "Servlet/3.1")
-            response.setHeader("Transfer-Encoding", "chunked")
+            response.headers["Server"] = "Servlet/3.1"
+            response.headers["Transfer-Encoding"] = "chunked"
         }
 
         get("/plaintext") { ok(TEXT_MESSAGE, "text/plain") }
@@ -74,14 +74,15 @@ internal fun createEngine(): ServerPort = when (systemSetting("WEBENGINE", "jett
 private fun returnWorlds(worldsList: List<World>): List<Map<Any?, Any?>> =
     worldsList.map { it.convertToMap() - "_id" }
 
-private fun Call.getWorldsCount() = parameters[QUERIES_PARAM]?.firstOrNull()?.toIntOrNull().let {
-    when {
-        it == null -> 1
-        it < 1 -> 1
-        it > 500 -> 500
-        else -> it
+private fun Call.getWorldsCount(): Int =
+    queryParametersValues[QUERIES_PARAM]?.firstOrNull()?.toIntOrNull().let {
+        when {
+            it == null -> 1
+            it < 1 -> 1
+            it > 500 -> 500
+            else -> it
+        }
     }
-}
 
 // HANDLERS
 private fun Call.listFortunes(

+ 3 - 1
frameworks/Kotlin/hexagon/src/main/kotlin/com/hexagonkt/BenchmarkStorage.kt

@@ -53,7 +53,9 @@ internal class BenchmarkMongoDbStore(engine: String) : BenchmarkStore {
             worldCopy
         }
 
-    override fun close() { /* Not needed */ }
+    override fun close() {
+        /* Not needed */
+    }
 }
 
 internal class BenchmarkSqlStore(engine: String) : BenchmarkStore {

+ 0 - 11
frameworks/Kotlin/hexagon/src/main/resources/logback.xml

@@ -10,19 +10,8 @@
     </encoder>
   </appender>
 
-  <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-      <FileNamePattern>log/%d{yyyy-MM-dd}.log</FileNamePattern>
-      <MaxHistory>5</MaxHistory>
-    </rollingPolicy>
-    <encoder>
-      <Pattern>%d{HH:mm:ss.SSS} %-5p [%-15.15thread] %-30logger{30} %X{jvmId} | %m%n</Pattern>
-    </encoder>
-  </appender>
-
   <root level="off">
     <appender-ref ref="console" />
-    <appender-ref ref="file" />
   </root>
 
   <logger name="com.hexagonkt.server.Server" level="info" />

+ 87 - 69
frameworks/Kotlin/hexagon/src/test/kotlin/com/hexagonkt/BenchmarkTest.kt

@@ -3,50 +3,86 @@ package com.hexagonkt
 import com.hexagonkt.serialization.parse
 import com.hexagonkt.http.client.Client
 import com.hexagonkt.serialization.Json
-import com.hexagonkt.serialization.parseObjects
 import com.hexagonkt.http.Method.GET
+import com.hexagonkt.http.client.Response
+import com.hexagonkt.http.client.ahc.AhcAdapter
 import com.hexagonkt.http.server.jetty.JettyServletAdapter
-import org.asynchttpclient.Response
-import org.testng.annotations.AfterClass
-import org.testng.annotations.BeforeClass
-import org.testng.annotations.Test
+import com.hexagonkt.serialization.parseObjects
+import io.kotest.assertions.throwables.shouldThrow
+import io.kotest.core.spec.style.StringSpec
 import java.lang.IllegalStateException
 import java.lang.System.setProperty
 
-@Test class BenchmarkJettyMongoDbTest : BenchmarkTestBase("jetty", "mongodb")
+class BenchmarkJettyMongoDbTest : BenchmarkTestBase("jetty", "mongodb")
 
-@Test class BenchmarkJettyPostgreSqlTest : BenchmarkTestBase("jetty", "postgresql")
+class BenchmarkJettyPostgreSqlTest : BenchmarkTestBase("jetty", "postgresql")
 
-@Test abstract class BenchmarkTestBase(
+abstract class BenchmarkTestBase(
     private val webEngine: String,
     private val databaseEngine: String,
     private val templateEngine: String = "pebble"
-) {
-    private val client by lazy { Client("http://localhost:${benchmarkServer.runtimePort}") }
+): StringSpec({
+
+    val endpoint = System.getProperty("verify.endpoint")
+    val users = (System.getProperty("users") ?: "8").toInt()
+    val count = (System.getProperty("count") ?: "2").toInt() * users
+
+    lateinit var client: Client
+
+    fun checkResponse(res: Response, contentType: String) {
+        assert(res.headers["Date"] != null)
+        assert(res.headers["Server"] != null)
+        assert(res.headers["Transfer-Encoding"] != null)
+        assert(res.headers["Content-Type"]?.first() == contentType)
+    }
+
+    fun checkDbRequest(path: String, itemsCount: Int) {
+        val response = client.get(path)
+        val content = response.body
+
+        checkResponse(response, Json.contentType)
+
+        val resultsList = content?.parse(List::class) ?: error("")
+        assert(itemsCount == resultsList.size)
+
+        (1..itemsCount).forEach {
+            val r = resultsList[it - 1] as Map<*, *>
+            assert(r.containsKey(World::id.name) && r.containsKey(World::randomNumber.name))
+            assert(!r.containsKey(World::_id.name))
+            assert((r[World::id.name] as Int) in 1..10000)
+        }
+    }
 
-    @BeforeClass fun startUp() {
+    beforeSpec {
         setProperty("WEBENGINE", webEngine)
-        main()
+        client = if (endpoint == null) {
+            main()
+            Client(AhcAdapter(), "http://localhost:${benchmarkServer.runtimePort}")
+        }
+        else {
+            Client(AhcAdapter(), endpoint)
+        }
     }
 
-    @AfterClass fun shutDown() {
+    afterSpec {
         benchmarkStores[databaseEngine]?.close()
         benchmarkServer.stop()
     }
 
-    @Test fun `Empty server code creates a Jetty Servlet Adapter`() {
+    "Empty server code creates a Jetty Servlet Adapter" {
         System.clearProperty("WEBENGINE")
         createEngine()
         assert(engine is JettyServletAdapter)
     }
 
-    @Test(expectedExceptions = [ IllegalStateException::class ])
-    fun `Invalid server code throws an exception`() {
-        setProperty("WEBENGINE", "invalid")
-        createEngine()
+    "Invalid server code throws an exception" {
+        shouldThrow<IllegalStateException> {
+            setProperty("WEBENGINE", "invalid")
+            createEngine()
+        }
     }
 
-    @Test fun web() {
+    "Web" {
         val web = Web()
 
         val webRoutes = web.serverRouter.requestHandlers
@@ -64,25 +100,25 @@ import java.lang.System.setProperty
         assert(webRoutes.containsAll(benchmarkRoutes))
     }
 
-    @Test fun json() {
+    "JSON".config(invocations = count, threads = users) {
         val response = client.get("/json")
-        val content = response.responseBody
+        val content = response.body
 
         checkResponse(response, Json.contentType)
-        assert("Hello, World!" == content.parse<Message>().message)
+        assert("Hello, World!" == content?.parse<Message>()?.message)
     }
 
-    @Test fun plaintext() {
+    "Plaintext".config(invocations = count, threads = users) {
         val response = client.get("/plaintext")
-        val content = response.responseBody
+        val content = response.body
 
         checkResponse(response, "text/plain")
         assert("Hello, World!" == content)
     }
 
-    @Test fun fortunes() {
+    "Fortunes".config(invocations = count, threads = users) {
         val response = client.get("/$databaseEngine/$templateEngine/fortunes")
-        val content = response.responseBody
+        val content = response.body ?: error("body is required")
 
         checkResponse(response, "text/html;charset=utf-8")
         assert(content.contains("<td>&lt;script&gt;alert(&quot;This should not be"))
@@ -90,9 +126,9 @@ import java.lang.System.setProperty
         assert(content.contains("<td>フレームワークのベンチマーク</td>"))
     }
 
-    @Test fun `no query parameter`() {
+    "No query parameter".config(invocations = count, threads = users) {
         val response = client.get("/$databaseEngine/db")
-        val body = response.responseBody
+        val body = response.body ?: error("body is required")
 
         checkResponse(response, Json.contentType)
         val bodyMap = body.parse(Map::class)
@@ -100,9 +136,9 @@ import java.lang.System.setProperty
         assert(bodyMap.containsKey(World::randomNumber.name))
     }
 
-    @Test fun `no updates parameter`() {
+    "No updates parameter".config(invocations = count, threads = users) {
         val response = client.get("/$databaseEngine/update")
-        val body = response.responseBody
+        val body = response.body ?: error("body is required")
 
         checkResponse(response, Json.contentType)
         val bodyMap = body.parseObjects(Map::class).first()
@@ -110,45 +146,27 @@ import java.lang.System.setProperty
         assert(bodyMap.containsKey(World::randomNumber.name))
     }
 
-    @Test fun `empty query parameter`() = checkDbRequest("/$databaseEngine/query?queries", 1)
-    @Test fun `text query parameter`() = checkDbRequest("/$databaseEngine/query?queries=text", 1)
-    @Test fun `zero queries`() = checkDbRequest("/$databaseEngine/query?queries=0", 1)
-    @Test fun `one thousand queries`() = checkDbRequest("/$databaseEngine/query?queries=1000", 500)
-    @Test fun `one query`() = checkDbRequest("/$databaseEngine/query?queries=1", 1)
-    @Test fun `ten queries`() = checkDbRequest("/$databaseEngine/query?queries=10", 10)
-    @Test fun `one hundred queries`() = checkDbRequest("/$databaseEngine/query?queries=100", 100)
-    @Test fun `five hundred queries`() = checkDbRequest("/$databaseEngine/query?queries=500", 500)
-
-    @Test fun `empty updates parameter`() = checkDbRequest("/$databaseEngine/update?queries", 1)
-    @Test fun `text updates parameter`() = checkDbRequest("/$databaseEngine/update?queries=text", 1)
-    @Test fun `zero updates`() = checkDbRequest("/$databaseEngine/update?queries=0", 1)
-    @Test fun `one thousand updates`() = checkDbRequest("/$databaseEngine/update?queries=1000", 500)
-    @Test fun `one update`() = checkDbRequest("/$databaseEngine/update?queries=1", 1)
-    @Test fun `ten updates`() = checkDbRequest("/$databaseEngine/update?queries=10", 10)
-    @Test fun `one hundred updates`() = checkDbRequest("/$databaseEngine/update?queries=100", 100)
-    @Test fun `five hundred updates`() = checkDbRequest("/$databaseEngine/update?queries=500", 500)
-
-    private fun checkDbRequest(path: String, itemsCount: Int) {
-        val response = client.get(path)
-        val content = response.responseBody
-
-        checkResponse(response, Json.contentType)
-
-        val resultsList = content.parse(List::class)
-        assert(itemsCount == resultsList.size)
-
-        (1..itemsCount).forEach {
-            val r = resultsList[it - 1] as Map<*, *>
-            assert(r.containsKey(World::id.name) && r.containsKey(World::randomNumber.name))
-            assert(!r.containsKey(World::_id.name))
-            assert((r[World::id.name] as Int) in 1..10000)
+    fun testDb(test: String, path: String, itemsCount: Int) {
+        test.config(invocations = count, threads = users) {
+            checkDbRequest("/$databaseEngine/$path", itemsCount)
         }
     }
 
-    private fun checkResponse(res: Response, contentType: String) {
-        assert(res.headers ["Date"] != null)
-        assert(res.headers ["Server"] != null)
-        assert(res.headers ["Transfer-Encoding"] != null)
-        assert(res.headers ["Content-Type"] == contentType)
-    }
-}
+    testDb("Empty query parameter", "query?queries", 1)
+    testDb("Text query parameter", "query?queries=text", 1)
+    testDb("Zero queries", "query?queries=0", 1)
+    testDb("One thousand queries", "query?queries=1000", 500)
+    testDb("One query", "query?queries=1", 1)
+    testDb("Ten queries", "query?queries=10", 10)
+    testDb("One hundred queries", "query?queries=100", 100)
+    testDb("Five hundred queries", "query?queries=500", 500)
+
+    testDb("Empty updates parameter", "update?queries", 1)
+    testDb("Text updates parameter", "update?queries=text", 1)
+    testDb("Zero updates", "update?queries=0", 1)
+    testDb("One thousand updates", "update?queries=1000", 500)
+    testDb("One update", "update?queries=1", 1)
+    testDb("Ten updates", "update?queries=10", 10)
+    testDb("One hundred updates", "update?queries=100", 100)
+    testDb("Five hundred updates", "update?queries=500", 500)
+})