Explorar o código

Add a simple blaze sample (#2517)

* Add a simple blaze sample

Modeled after the finagle sample

* Remove '; charset=utf-8' from 'content-type' header
Bryce Anderson %!s(int64=8) %!d(string=hai) anos
pai
achega
530c4bbc36

+ 1 - 0
.travis.yml

@@ -177,6 +177,7 @@ env:
     - "TESTDIR=Rust/hyper"
     - "TESTDIR=Rust/tokio-minihttp"
     - "TESTDIR=Scala/akka-http"
+    - "TESTDIR=Scala/blaze"
     - "TESTDIR=Scala/colossus"
     - "TESTDIR=Scala/finagle"
     - "TESTDIR=Scala/finatra"

+ 3 - 0
frameworks/Scala/blaze/.gitignore

@@ -0,0 +1,3 @@
+target
+projet/target
+.cache

+ 21 - 0
frameworks/Scala/blaze/README.md

@@ -0,0 +1,21 @@
+#blaze Benchmarking Test
+
+## Infrastructure Software Versions
+The tests were run with:
+
+* [Java Oracle 1.8.0_101](http://www.oracle.com/technetwork/java/javase)
+* [blaze 0.13.0](https://github.com/http4s/blaze/)
+
+## Test URLs
+### JSON Encoding Test
+
+http://localhost:8080/json
+
+### Plaintext Test
+
+http://localhost:8080/plaintext
+
+## How to run
+sbt 'oneJar'
+
+java -jar target/scala-2.11/blaze_2.11-1.0-SNAPSHOT-one-jar.jar

+ 23 - 0
frameworks/Scala/blaze/benchmark_config.json

@@ -0,0 +1,23 @@
+{
+  "framework": "blaze",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "None",
+      "framework": "blaze",
+      "language": "Scala",
+      "orm": "Raw",
+      "platform": "blaze",
+      "webserver": "None",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "blaze",
+      "notes": ""
+    }
+  }]
+}

+ 17 - 0
frameworks/Scala/blaze/build.sbt

@@ -0,0 +1,17 @@
+name := "blaze"
+
+version := "1.0-SNAPSHOT"
+
+scalaVersion := "2.11.8"
+
+com.github.retronym.SbtOneJar.oneJarSettings
+
+val blazeVersion = "0.13.0"
+
+libraryDependencies ++= Seq(
+	"org.http4s" %% "blaze-http" % blazeVersion,
+	"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.8.4"
+)
+
+mainClass in oneJar := Some("blaze.techempower.benchmark.Main")
+

+ 2 - 0
frameworks/Scala/blaze/project/plugins.sbt

@@ -0,0 +1,2 @@
+addSbtPlugin("org.scala-sbt.plugins" % "sbt-onejar" % "0.8")
+

+ 7 - 0
frameworks/Scala/blaze/setup.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+fw_depends java sbt
+
+sbt 'oneJar' -batch
+
+java -jar target/scala-2.11/blaze*one-jar.jar &

+ 1 - 0
frameworks/Scala/blaze/source_code

@@ -0,0 +1 @@
+./http4s/src/main/scala/WebServer.scala

+ 14 - 0
frameworks/Scala/blaze/src/main/resources/logback.xml

@@ -0,0 +1,14 @@
+<configuration>
+
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <!-- encoders are assigned the type
+         ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+    <encoder>
+      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+    </encoder>
+  </appender>
+
+  <root level="error">
+    <appender-ref ref="STDOUT" />
+  </root>
+</configuration>

+ 50 - 0
frameworks/Scala/blaze/src/main/scala/Main.scala

@@ -0,0 +1,50 @@
+package blaze.techempower.benchmark
+
+import java.net.InetSocketAddress
+import java.nio.charset.StandardCharsets.UTF_8
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.module.scala.DefaultScalaModule
+
+import org.http4s.blaze.channel.SocketConnection
+import org.http4s.blaze.http._
+
+import scala.concurrent.Future
+
+object Main {
+
+  private val mapper: ObjectMapper = new ObjectMapper().registerModule(DefaultScalaModule)
+
+  private val plaintextResult = Future.successful {
+    val hs = Seq("server" -> "blaze", "content-type" -> "text/plain")
+    RouteAction.Ok("Hello, World!".getBytes(UTF_8), hs)
+  }
+
+  private def notFound(path: String) = Future.successful {
+    RouteAction.String(s"Not found: $path", 404, "Not Found", Nil)
+  }
+
+  // HTTP service definition
+  private def service(request: HttpRequest): Future[RouteAction] = request.uri match {
+    case "/plaintext" => plaintextResult
+
+    case "/json" => Future.successful {
+      val msg = mapper.writeValueAsBytes(Map("message" -> "Hello, World!"))
+      RouteAction.Ok(msg, Seq("server" -> "blaze", "content-type" -> "application/json"))
+    }
+
+    case other => notFound(other)
+  }
+
+  def main(args: Array[String]): Unit = {
+    val srvc = { _: SocketConnection => service(_:HttpRequest) }
+    val server = Http1Server(srvc, new InetSocketAddress(8080), HttpServerStageConfig())
+      .getOrElse(sys.error("Failed to bind socket"))
+
+    try server.channel.join()
+    finally {
+      server.group.closeGroup()
+    }
+  }
+}
+