Permalink
Please sign in to comment.
Browse files
Fix http4k setup files, and add undertow server backend, database and…
… fortunes tests (#2822) * adding undertow implementation * fixes to setup scripts * fixes to setup scripts * fixes to setup scripts * fixes to setup scripts * fixes to setup scripts * fixes to setup scripts * upgrade version of http4k * adding fortunes and worlds tests * some fixes for database driver * fix number of records returned * set content type on view * set content type on json * fix max and min * adding new fortune to list and sorting result
- Loading branch information...
Showing
with
291 additions
and 48 deletions.
- +1 −1 frameworks/Kotlin/http4k/Dockerfile
- +5 −0 frameworks/Kotlin/http4k/README.md
- +40 −7 frameworks/Kotlin/http4k/benchmark_config.json
- +10 −4 frameworks/Kotlin/http4k/build.gradle
- +2 −3 frameworks/Kotlin/http4k/setup_jetty.sh
- +2 −3 frameworks/Kotlin/http4k/setup_netty.sh
- +7 −0 frameworks/Kotlin/http4k/setup_undertow.sh
- +9 −4 frameworks/Kotlin/http4k/source_code
- +50 −0 frameworks/Kotlin/http4k/src/main/kotlin/Database.kt
- +31 −0 frameworks/Kotlin/http4k/src/main/kotlin/FortunesRoute.kt
- +8 −26 frameworks/Kotlin/http4k/src/main/kotlin/Http4kBenchmarkServer.kt
- +5 −0 frameworks/Kotlin/http4k/src/main/kotlin/Http4kUndertowServer.kt
- +15 −0 frameworks/Kotlin/http4k/src/main/kotlin/JsonRoute.kt
- +18 −0 frameworks/Kotlin/http4k/src/main/kotlin/PlainTextRoute.kt
- +87 −0 frameworks/Kotlin/http4k/src/main/kotlin/WorldRoutes.kt
- +1 −0 frameworks/Kotlin/http4k/src/main/resources/FortunesList.hbs
| @@ -1,3 +1,3 @@ | ||
| FROM mysql | ||
| FROM postgres | ||
| ADD create.sql /docker-entrypoint-initdb.d/ |
| @@ -1,8 +1,7 @@ | ||
| #!/bin/bash | ||
| fw_depends mysql java | ||
| fw_depends postgresql java | ||
| gradle wrapper | ||
| ./gradlew clean build jetty | ||
| gradle clean build jetty | ||
| java -server -XX:+UseNUMA -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+AlwaysPreTouch -jar build/libs/http4k-standalone.jar & |
| @@ -1,8 +1,7 @@ | ||
| #!/bin/bash | ||
| fw_depends mysql java | ||
| fw_depends postgresql java | ||
| gradle wrapper | ||
| ./gradlew clean build netty | ||
| gradle clean build netty | ||
| java -server -XX:+UseNUMA -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+AlwaysPreTouch -jar build/libs/http4k-standalone.jar & |
| @@ -0,0 +1,7 @@ | ||
| #!/bin/bash | ||
| fw_depends postgresql java | ||
| ./gradlew clean build undertow | ||
| java -server -XX:+UseNUMA -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+AlwaysPreTouch -jar build/libs/http4k-standalone.jar & |
| @@ -1,4 +1,9 @@ | ||
| http4k/src/main/scala/ | ||
| http4k/src/main/scala/Http4kBenchmarkServer.kt | ||
| http4k/src/main/scala/Http4kJettyServer.kt | ||
| http4k/src/main/scala/Http4kNettyServer.kt | ||
| http4k/src/main/kotlin/Database.kt | ||
| http4k/src/main/kotlin/FortunesRoute.kt | ||
| http4k/src/main/kotlin/JsonRoute.kt | ||
| http4k/src/main/kotlin/PlainTextRoute.kt | ||
| http4k/src/main/kotlin/WorldRoutes.kt | ||
| http4k/src/main/kotlin/Http4kBenchmarkServer.kt | ||
| http4k/src/main/kotlin/Http4kJettyServer.kt | ||
| http4k/src/main/kotlin/Http4kNettyServer.kt | ||
| http4k/src/main/kotlin/Http4kUndertowServer.kt |
| @@ -0,0 +1,50 @@ | ||
| import com.zaxxer.hikari.HikariConfig | ||
| import com.zaxxer.hikari.HikariDataSource | ||
| import java.sql.Connection | ||
| import java.sql.ResultSet | ||
| class Database(private val dataSource: javax.sql.DataSource) { | ||
| companion object { | ||
| operator fun invoke(host: String): Database { | ||
| val postgresqlUrl = "jdbc:postgresql://$host/hello_world?" + | ||
| "jdbcCompliantTruncation=false&" + | ||
| "elideSetAutoCommits=true&" + | ||
| "useLocalSessionState=true&" + | ||
| "cachePrepStmts=true&" + | ||
| "cacheCallableStmts=true&" + | ||
| "alwaysSendSetIsolation=false&" + | ||
| "prepStmtCacheSize=4096&" + | ||
| "cacheServerConfiguration=true&" + | ||
| "prepStmtCacheSqlLimit=2048&" + | ||
| "traceProtocol=false&" + | ||
| "useUnbufferedInput=false&" + | ||
| "useReadAheadInput=false&" + | ||
| "maintainTimeStats=false&" + | ||
| "useServerPrepStmts=true&" + | ||
| "cacheRSMetadata=true" | ||
| val config = HikariConfig() | ||
| config.jdbcUrl = postgresqlUrl | ||
| config.maximumPoolSize = 256 | ||
| config.username = "benchmarkdbuser" | ||
| config.password = "benchmarkdbpass" | ||
| return Database(HikariDataSource(config)) | ||
| } | ||
| } | ||
| fun <T> withConnection(fn: (Connection) -> T): T = | ||
| try { | ||
| fn(dataSource.connection) | ||
| } finally { | ||
| dataSource.connection.close() | ||
| } | ||
| } | ||
| fun <T> ResultSet.toList(fn: (ResultSet) -> T): List<T> { | ||
| val t = mutableListOf<T>() | ||
| while (this.next()) { | ||
| t.add(fn(this)) | ||
| } | ||
| return t | ||
| } |
| @@ -0,0 +1,31 @@ | ||
| import org.http4k.core.Body | ||
| import org.http4k.core.ContentType.Companion.TEXT_HTML | ||
| import org.http4k.core.Method.GET | ||
| import org.http4k.core.Response | ||
| import org.http4k.core.Status.Companion.OK | ||
| import org.http4k.core.with | ||
| import org.http4k.routing.Route | ||
| import org.http4k.routing.by | ||
| import org.http4k.template.HandlebarsTemplates | ||
| import org.http4k.template.ViewModel | ||
| import org.http4k.template.view | ||
| data class Fortune(val id: Int, val message: String) | ||
| data class FortunesList(val items: List<Fortune>) : ViewModel | ||
| object FortunesRoute { | ||
| private val viewBody = Body.view(HandlebarsTemplates().CachingClasspath(), TEXT_HTML) | ||
| operator fun invoke(database: Database): Route = GET to "fortunes" by { | ||
| val items = database.withConnection { | ||
| it.prepareStatement("select * from fortune").executeQuery().toList { | ||
| Fortune(it.getInt(1), it.getString(2)) | ||
| } | ||
| } | ||
| .plus(Fortune(0, "Additional fortune added at request time.")) | ||
| .sortedBy { it.message } | ||
| Response(OK).with(viewBody of FortunesList(items)) | ||
| } | ||
| } |
| @@ -0,0 +1,5 @@ | ||
| import org.http4k.server.Undertow | ||
| fun main(args: Array<String>) { | ||
| Http4kBenchmarkServer.start(Undertow(9000)) | ||
| } |
| @@ -0,0 +1,15 @@ | ||
| import org.http4k.core.Body | ||
| import org.http4k.core.Method.GET | ||
| import org.http4k.core.Response | ||
| import org.http4k.core.Status.Companion.OK | ||
| import org.http4k.core.with | ||
| import org.http4k.format.Jackson.json | ||
| import org.http4k.format.Jackson.obj | ||
| import org.http4k.format.Jackson.string | ||
| import org.http4k.routing.by | ||
| object JsonRoute { | ||
| private val jsonBody = Body.json().toLens() | ||
| operator fun invoke() = GET to "/json" by { Response(OK).with(jsonBody of obj("message" to string("Hello, World!"))) } | ||
| } |
| @@ -0,0 +1,18 @@ | ||
| import org.http4k.asByteBuffer | ||
| import org.http4k.core.Body | ||
| import org.http4k.core.ContentType.Companion.TEXT_PLAIN | ||
| import org.http4k.core.Method.GET | ||
| import org.http4k.core.Response | ||
| import org.http4k.core.Status.Companion.OK | ||
| import org.http4k.core.with | ||
| import org.http4k.lens.binary | ||
| import org.http4k.routing.by | ||
| object PlainTextRoute { | ||
| private val preAllocatedHelloWorldText = "Hello, World!".asByteBuffer() | ||
| private val plainTextBody = Body.binary(TEXT_PLAIN).toLens() | ||
| operator fun invoke() = GET to "/plaintext" by { Response(OK).with(plainTextBody of preAllocatedHelloWorldText) } | ||
| } |
Oops, something went wrong.
0 comments on commit
169900b