Browse Source

Update Pellet to 0.0.16 (#8817)

carrot 1 year ago
parent
commit
bb28a9f2b0

+ 2 - 2
frameworks/Kotlin/pellet/pellet.dockerfile

@@ -1,10 +1,10 @@
-FROM gradle:jdk18 as gradle
+FROM gradle:jdk21 as gradle
 WORKDIR /sample
 COPY sample/build.gradle.kts build.gradle.kts
 COPY sample/src src
 RUN gradle clean shadowJar --no-daemon
 
-FROM openjdk:18-jdk-buster
+FROM openjdk:21-jdk-buster
 WORKDIR /sample
 COPY --from=gradle /sample/build/libs/sample-1.0.0-all.jar app.jar
 

+ 9 - 13
frameworks/Kotlin/pellet/sample/build.gradle.kts

@@ -1,8 +1,8 @@
 plugins {
     application
     id("com.github.johnrengelman.shadow") version "7.1.0"
-    kotlin("jvm") version "1.7.10"
-    kotlin("plugin.serialization") version "1.7.10"
+    kotlin("jvm") version "1.9.23"
+    kotlin("plugin.serialization") version "1.9.23"
     id("nu.studer.rocker") version "3.0.4"
 }
 
@@ -25,31 +25,27 @@ rocker {
 }
 
 dependencies {
-    implementation(platform("dev.pellet:pellet-bom:0.0.15"))
+    implementation(platform("dev.pellet:pellet-bom:0.0.16"))
     implementation("dev.pellet:pellet-server")
     implementation("dev.pellet:pellet-logging")
     implementation("org.slf4j:slf4j-api:1.7.36")
-    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0-RC")
+    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
     implementation(platform(kotlin("bom")))
     implementation(kotlin("stdlib-jdk8"))
-    implementation(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4"))
-    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
-    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8")
-    implementation("io.vertx:vertx-pg-client:4.3.2")
+    implementation("io.vertx:vertx-pg-client:4.5.5")
+    implementation("io.vertx:vertx-lang-kotlin:4.5.5")
     implementation("com.ongres.scram:client:2.1")
-    implementation("io.vertx:vertx-lang-kotlin:4.3.2")
-    implementation("io.vertx:vertx-lang-kotlin-coroutines:4.3.2")
 }
 
 java {
     toolchain {
-        sourceCompatibility = JavaVersion.VERSION_18
-        targetCompatibility = JavaVersion.VERSION_18
+        sourceCompatibility = JavaVersion.VERSION_21
+        targetCompatibility = JavaVersion.VERSION_21
     }
 }
 
 tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
-    kotlinOptions.jvmTarget = "18"
+    kotlinOptions.jvmTarget = "21"
 }
 
 application {

+ 8 - 9
frameworks/Kotlin/pellet/sample/src/main/kotlin/benchmark/Benchmark.kt

@@ -10,7 +10,6 @@ import dev.pellet.server.PelletConnector
 import dev.pellet.server.codec.mime.MediaType
 import dev.pellet.server.responder.http.PelletHTTPRouteContext
 import dev.pellet.server.routing.http.HTTPRouteResponse
-import kotlinx.coroutines.runBlocking
 import kotlinx.serialization.json.Json
 import java.time.Instant
 import java.time.ZoneId
@@ -25,7 +24,7 @@ val jsonEncoder = Json {
     prettyPrint = false
 }
 
-fun main() = runBlocking {
+fun main() {
     val sharedRouter = httpRouter {
         get("/plaintext", ::handlePlain)
         get("/json", ::handleJson)
@@ -44,14 +43,14 @@ fun main() = runBlocking {
             router = sharedRouter
         }
     }
-    pellet.start().join()
+    pellet.start()
 }
 
 val dateFormatter = DateTimeFormatter
     .ofPattern("EEE, dd MMM yyyy HH:mm:ss z", Locale.ENGLISH)
     .withZone(ZoneId.of("GMT"))
 
-private suspend fun handlePlain(
+private fun handlePlain(
     context: PelletHTTPRouteContext
 ): HTTPRouteResponse {
     return HTTPRouteResponse.Builder()
@@ -67,7 +66,7 @@ data class ResponseBody(
     val message: String
 )
 
-private suspend fun handleJson(
+private fun handleJson(
     context: PelletHTTPRouteContext
 ): HTTPRouteResponse {
     val responseBody = ResponseBody(message = "Hello, World!")
@@ -81,7 +80,7 @@ private suspend fun handleJson(
 
 private val repository = TFBRepository()
 
-private suspend fun handleDb(
+private fun handleDb(
     context: PelletHTTPRouteContext
 ): HTTPRouteResponse {
     val result = repository.fetchWorld()
@@ -93,7 +92,7 @@ private suspend fun handleDb(
         .build()
 }
 
-private suspend fun handleQuery(
+private fun handleQuery(
     context: PelletHTTPRouteContext
 ): HTTPRouteResponse {
     val rawQueries = context.firstQueryParameter("queries").getOrNull()
@@ -110,7 +109,7 @@ private suspend fun handleQuery(
         .build()
 }
 
-private suspend fun handleUpdates(
+private fun handleUpdates(
     context: PelletHTTPRouteContext
 ): HTTPRouteResponse {
     val rawQueries = context.firstQueryParameter("queries").getOrNull()
@@ -133,7 +132,7 @@ private suspend fun handleUpdates(
         .build()
 }
 
-private suspend fun handleFortunes(
+private fun handleFortunes(
     context: PelletHTTPRouteContext
 ): HTTPRouteResponse {
     val newFortune = Fortune(0, "Additional fortune added at request time.")

+ 1 - 1
frameworks/Kotlin/pellet/sample/src/main/kotlin/benchmark/data/FortuneDAO.kt

@@ -2,5 +2,5 @@ package benchmark.data
 
 interface FortuneDAO {
 
-    suspend fun fetchFortunes(): List<Fortune>
+    fun fetchFortunes(): List<Fortune>
 }

+ 17 - 9
frameworks/Kotlin/pellet/sample/src/main/kotlin/benchmark/data/TFBRepository.kt

@@ -1,8 +1,7 @@
 package benchmark.data
 
-import io.vertx.kotlin.coroutines.await
+import io.vertx.pgclient.PgBuilder
 import io.vertx.pgclient.PgConnectOptions
-import io.vertx.pgclient.PgPool
 import io.vertx.sqlclient.PoolOptions
 import io.vertx.sqlclient.Tuple
 import java.util.concurrent.ThreadLocalRandom
@@ -20,14 +19,19 @@ class TFBRepository: WorldDAO, FortuneDAO {
         }
 
     private val poolOptions = PoolOptions()
-    private val client = PgPool.client(connectOptions, poolOptions)
+    private val client = PgBuilder.client()
+        .with(poolOptions)
+        .connectingTo(connectOptions)
+        .build()
 
-    override suspend fun fetchWorld(): WorldDTO {
+    override fun fetchWorld(): WorldDTO {
         val worldId = ThreadLocalRandom.current().nextInt(1, 10001)
         val result = client
             .preparedQuery("select id, randomNumber from world where id = $1")
             .execute(Tuple.of(worldId))
-            .await()
+            .toCompletionStage()
+            .toCompletableFuture()
+            .get()
         val row = result.first()
         return WorldDTO(
             row.getInteger(0),
@@ -35,20 +39,24 @@ class TFBRepository: WorldDAO, FortuneDAO {
         )
     }
 
-    override suspend fun updateWorlds(worlds: List<WorldDTO>) {
+    override fun updateWorlds(worlds: List<WorldDTO>) {
         val batch = worlds.map {
             Tuple.of(it.id, it.randomNumber)
         }
         client
             .preparedQuery("update world set randomNumber = $1 where id = $2")
             .executeBatch(batch)
-            .await()
+            .toCompletionStage()
+            .toCompletableFuture()
+            .get()
     }
 
-    override suspend fun fetchFortunes(): List<Fortune> {
+    override fun fetchFortunes(): List<Fortune> {
         val results = client.preparedQuery("select id, message from fortune")
             .execute()
-            .await()
+            .toCompletionStage()
+            .toCompletableFuture()
+            .get()
         return results.map {
             Fortune(
                 it.getInteger(0),

+ 2 - 2
frameworks/Kotlin/pellet/sample/src/main/kotlin/benchmark/data/WorldDAO.kt

@@ -2,6 +2,6 @@ package benchmark.data
 
 interface WorldDAO {
 
-    suspend fun fetchWorld(): WorldDTO
-    suspend fun updateWorlds(worlds: List<WorldDTO>)
+    fun fetchWorld(): WorldDTO
+    fun updateWorlds(worlds: List<WorldDTO>)
 }