Browse Source

Update ktor to 1.4.0 (#5946)

* Update ktor to 1.4.0

* Update contact information
Leonid Stashevsky 5 years ago
parent
commit
4a00589bd8

+ 2 - 0
frameworks/Kotlin/ktor/ktor/README.md

@@ -37,6 +37,8 @@ Please note that the server holds tty so you may need nohup. See `setup.sh` for
 
 # Contact
 
+[Leonid Stashevsky](https://github.com/e5l)
+
 [Sergey Mashkov](https://github.com/cy6erGn0m)
 
 [Ilya Ryzhenkov](https://github.com/orangy) 

+ 7 - 8
frameworks/Kotlin/ktor/ktor/pom.xml

@@ -12,10 +12,9 @@
     <name>org.jetbrains.ktor tech-empower-framework-benchmark</name>
 
     <properties>
-        <kotlin.version>1.3.0</kotlin.version>
-        <ktor.version>1.0.0-beta-4</ktor.version>
-        <serialization.runtime>0.9.0</serialization.runtime>
-
+        <kotlin.version>1.4.0</kotlin.version>
+        <ktor.version>1.4.0</ktor.version>
+        <serialization.runtime>1.0.0-RC</serialization.runtime>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <hikaricp.version>3.2.0</hikaricp.version>
         <logback.version>1.2.3</logback.version>
@@ -36,10 +35,10 @@
         </dependency>
         <dependency>
             <groupId>org.jetbrains.kotlinx</groupId>
-            <artifactId>kotlinx-serialization-runtime</artifactId>
+            <artifactId>kotlinx-serialization-core</artifactId>
             <version>${serialization.runtime}</version>
         </dependency>
-        
+
         <dependency>
             <groupId>io.ktor</groupId>
             <artifactId>ktor-server-netty</artifactId>
@@ -77,7 +76,7 @@
             <artifactId>mysql-connector-java</artifactId>
             <version>${mysql.version}</version>
         </dependency>
-        
+
         <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-classic</artifactId>
@@ -124,7 +123,7 @@
                 <dependencies>
                     <dependency>
                         <groupId>org.jetbrains.kotlin</groupId>
-                        <artifactId>kotlinx-maven-serialization-plugin</artifactId>
+                        <artifactId>kotlin-maven-serialization</artifactId>
                         <version>${kotlin.version}</version>
                     </dependency>
                 </dependencies>

+ 23 - 17
frameworks/Kotlin/ktor/ktor/src/main/kotlin/org/jetbrains/ktor/benchmarks/Hello.kt

@@ -12,6 +12,7 @@ import kotlinx.coroutines.*
 import kotlinx.coroutines.scheduling.*
 import kotlinx.html.*
 import kotlinx.serialization.*
+import kotlinx.serialization.builtins.*
 import kotlinx.serialization.json.*
 import java.util.*
 import java.util.concurrent.*
@@ -25,10 +26,10 @@ data class World(val id: Int, var randomNumber: Int)
 @Serializable
 data class Fortune(val id: Int, var message: String)
 
-@UseExperimental(ImplicitReflectionSerializer::class, InternalCoroutinesApi::class)
+@OptIn(InternalCoroutinesApi::class)
 fun Application.main() {
     val worldSerializer = World.serializer()
-    val worldListSerializer = World.serializer().list
+    val worldListSerializer = ListSerializer(World.serializer())
 
     val dbRows = 10000
     val poolSize = 48
@@ -45,7 +46,7 @@ fun Application.main() {
         }
 
         get("/json") {
-            call.respondText(JSON.stringify(Message()), ContentType.Application.Json, HttpStatusCode.OK)
+            call.respondText(Json.encodeToString(Message()), ContentType.Application.Json, HttpStatusCode.OK)
         }
 
         get("/db") {
@@ -68,10 +69,12 @@ fun Application.main() {
                 }
             }
 
-            call.respondText(when (queries) {
-                null -> JSON.stringify(worldSerializer, result.single())
-                else -> JSON.stringify(worldListSerializer, result)
-            }, ContentType.Application.Json, HttpStatusCode.OK)
+            call.respondText(
+                when (queries) {
+                    null -> Json.encodeToString(worldSerializer, result.single())
+                    else -> Json.encodeToString(worldListSerializer, result)
+                }, ContentType.Application.Json, HttpStatusCode.OK
+            )
         }
 
         get("/fortunes") {
@@ -131,22 +134,25 @@ fun Application.main() {
 
                     result.forEach { it.randomNumber = random.nextInt(dbRows) + 1 }
 
-                    connection.prepareStatement("UPDATE World SET randomNumber = ? WHERE id = ?").use { updateStatement ->
-                        for ((id, randomNumber) in result) {
-                            updateStatement.setInt(1, randomNumber)
-                            updateStatement.setInt(2, id)
+                    connection.prepareStatement("UPDATE World SET randomNumber = ? WHERE id = ?")
+                        .use { updateStatement ->
+                            for ((id, randomNumber) in result) {
+                                updateStatement.setInt(1, randomNumber)
+                                updateStatement.setInt(2, id)
 
-                            updateStatement.executeUpdate()
+                                updateStatement.executeUpdate()
+                            }
                         }
-                    }
 
                 }
             }
 
-            call.respondText(when (queries) {
-                null -> JSON.stringify(worldSerializer, result.single())
-                else -> JSON.stringify(worldListSerializer, result)
-            }, ContentType.Application.Json, HttpStatusCode.OK)
+            call.respondText(
+                when (queries) {
+                    null -> Json.encodeToString(worldSerializer, result.single())
+                    else -> Json.encodeToString(worldListSerializer, result)
+                }, ContentType.Application.Json, HttpStatusCode.OK
+            )
         }
     }
 }