Browse Source

Update SNUnit benchmark and dependencies (#7897)

* Update SNUnit benchmark and dependencies

* Fix notFound method

* Update NGINX Unit to 1.29.1

* Remove broken tag
Lorenzo Gabriele 2 years ago
parent
commit
d63cdddcd3

+ 1 - 2
frameworks/Scala/snunit/benchmark_config.json

@@ -19,8 +19,7 @@
         "database_os": "Linux",
         "display_name": "SNUnit",
         "notes": "",
-        "versus": "",
-        "tags": ["broken"]
+        "versus": ""
       }
     }
   ]

+ 6 - 4
frameworks/Scala/snunit/build.sbt

@@ -1,12 +1,14 @@
 import scala.scalanative.build._
 
-scalaVersion := "2.13.8"
+scalaVersion := "2.13.10"
+
+val snunitVersion = "0.3.0"
+val jsoniterScalaVersion = "2.20.6"
 
-val snunitVersion = "0.2.4"
 libraryDependencies ++= Seq(
   "com.github.lolgab" %%% "snunit" % snunitVersion,
-  "com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-core" % "2.19.1",
-  "com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-macros" % "2.19.1" % "compile-internal"
+  "com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-core" % jsoniterScalaVersion,
+  "com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-macros" % jsoniterScalaVersion % "compile-internal"
 )
 
 nativeConfig ~= {

+ 1 - 1
frameworks/Scala/snunit/snunit.dockerfile

@@ -15,7 +15,7 @@ COPY . .
 
 RUN sbt nativeLink
 
-FROM nginx/unit:1.29.0-minimal
+FROM nginx/unit:1.29.1-minimal
 
 COPY /config.sh /docker-entrypoint.d/
 COPY --from=builder /workdir/target/scala-2.13/workdir-out /app/example

+ 27 - 21
frameworks/Scala/snunit/src/main/scala/Main.scala

@@ -9,29 +9,35 @@ object Message {
 }
 
 object Main {
+  val applicationJson = Seq("Content-Type" -> "application/json")
+  val textPlain = Seq("Content-Type" -> "text/plain")
+
+  @inline
+  private def notFound(req: Request) = req.send(
+    statusCode = StatusCode.NotFound,
+    content = "Not found",
+    headers = textPlain
+  )
+
   def main(args: Array[String]): Unit = {
-    val server = SyncServerBuilder
+    SyncServerBuilder
       .build(req =>
-        if (req.method == Method.GET && req.path == "/plaintext")
-          req.send(
-            statusCode = StatusCode.OK,
-            content = "Hello, World!",
-            headers = Seq("Content-Type" -> "text/plain")
-          )
-        else if (req.method == Method.GET && req.path == "/json")
-          req.send(
-            statusCode = StatusCode.OK,
-            content = writeToArray(Message("Hello, World!")),
-            headers = Seq("Content-Type" -> "application/json")
-          )
-        else
-          req.send(
-            statusCode = StatusCode.NotFound,
-            content = "Not found",
-            headers = Seq("Content-Type" -> "text/plain")
-          )
+        if (req.method == Method.GET) {
+          if(req.target == "/plaintext")
+            req.send(
+              statusCode = StatusCode.OK,
+              content = "Hello, World!",
+              headers = textPlain
+            )
+          else if(req.target == "/json")
+            req.send(
+              statusCode = StatusCode.OK,
+              content = writeToArray(Message("Hello, World!")),
+              headers = applicationJson
+            )
+          else notFound(req)
+        } else notFound(req)
       )
-
-    server.listen()
+      .listen()
   }
 }