Ver Fonte

Upgrade Finagle and Finch benchmarks (#2564)

Vladimir Kostyukov há 8 anos atrás
pai
commit
fa732fb6f3

+ 1 - 1
frameworks/Scala/finagle/build.sbt

@@ -7,6 +7,6 @@ version := "1.0.3"
 com.github.retronym.SbtOneJar.oneJarSettings
 
 libraryDependencies ++= Seq(
-  "com.twitter" %% "finagle-http" % "6.41.0",
+  "com.twitter" %% "finagle-http" % "6.42.0",
   "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.5.3"
 )

+ 2 - 3
frameworks/Scala/finch/build.sbt

@@ -7,7 +7,6 @@ scalaVersion := "2.11.8"
 com.github.retronym.SbtOneJar.oneJarSettings
 
 libraryDependencies ++= Seq(
-  "com.github.finagle" %% "finch-core" % "0.12.0",
-  "com.github.finagle" %% "finch-circe" % "0.12.0",
-  "io.circe" %% "circe-generic" % "0.7.0"
+  "com.github.finagle" %% "finch-core" % "0.13.0",
+  "com.github.finagle" %% "finch-circe" % "0.13.0"
 )

+ 7 - 12
frameworks/Scala/finch/src/main/scala/Main.scala

@@ -1,5 +1,4 @@
 import com.twitter.io.Buf
-import com.twitter.finagle.http.Response
 import com.twitter.finagle.Http
 import com.twitter.finagle.stats.NullStatsReceiver
 import com.twitter.finagle.tracing.NullTracer
@@ -16,19 +15,15 @@ object Main extends App {
   val json: Endpoint[Json] = get("json") {
     Ok(Json.obj("message" -> Json.fromString("Hello, World!")))
       .withHeader("Server" -> "Finch")
-      .withHeader("Date" -> currentTime())
   }
 
-  // Downgrade a text/plain endpoint to `Endpoint[Response]` as per
-  // https://github.com/finagle/finch/blob/master/docs/cookbook.md#serving-multiple-content-types
-  val plaintext: Endpoint[Response] = get("plaintext") {
-    val rep = Response()
-    rep.content = helloWorld
-    rep.contentType = "text/plain"
-    rep.headerMap.set("Server", "Finch")
-    rep.headerMap.set("Date", currentTime())
-
-    rep
+  // We need to downgrade to Buf and override Content-Type header manually
+  // to serve non-JSON payload out of the JSON service. This workaround
+  // shouldn't be needed in Finch 1.0.
+  val plaintext: Endpoint[Buf] = get("plaintext") {
+    Ok(helloWorld)
+      .withHeader("Server" -> "Finch")
+      .withHeader("Content-Type" -> "text/plain")
   }
 
   Await.ready(Http.server

+ 0 - 18
frameworks/Scala/finch/src/main/scala/currentTime.scala

@@ -1,18 +0,0 @@
-import java.time.format.DateTimeFormatter
-import java.time.{Instant, ZoneOffset}
-
-object currentTime {
-  private[this] val formatter: DateTimeFormatter = 
-    DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneOffset.UTC)
-
-  @volatile private[this] var last: (Long, String) = (0, "")
-
-  def apply(): String = {
-    val time = System.currentTimeMillis()
-    if (time - last._1 > 1000) {
-      last = time -> formatter.format(Instant.ofEpochMilli(time))
-    }
-
-    last._2
-  }
-}