Browse Source

Added fortunes test to PLAIN

weltermann17 12 years ago
parent
commit
3b8483847b

+ 1 - 0
plain/benchmark_config

@@ -8,6 +8,7 @@
             "db_url": "/db",
             "query_url": "/db?queries=",
             "update_url": "/update?queries=",
+            "fortune_url": "/fortunes",
             "port": 9080,
             "sort": 143
             }

+ 1 - 0
plain/src/main/resources/application.conf

@@ -25,6 +25,7 @@ benchmark-dispatcher.routes = [
 	{ uri = json, resource-class-name = com.ibm.techempower.Json }
 	{ uri = db, resource-class-name = com.ibm.techempower.Db }
 	{ uri = update, resource-class-name = com.ibm.techempower.Update }
+	{ uri = fortunes, resource-class-name = com.ibm.techempower.Fortunes }
 ]
 
 benchmark-mysql {

+ 41 - 0
plain/src/main/scala/com/ibm/techempower/Fortunes.scala

@@ -0,0 +1,41 @@
+package com.ibm.techempower
+
+import scala.collection.mutable.ListBuffer
+import scala.language.implicitConversions
+import scala.xml._
+
+import com.ibm.plain.rest.Resource
+import com.ibm.plain.jdbc.withConnection
+import com.ibm.plain.jdbc.ConnectionHelper._
+
+final class Fortunes
+
+    extends Resource {
+
+  Get {
+    val list = new ListBuffer[(Int, String)]
+    withConnection(datasource) { implicit c => for (row <- sql <<! asRow) { list += row } }
+    list += ((0, "Additional fortune added at request time."))
+    html(rows(list.sortBy(_._2))).toString
+  }
+
+  @inline private[this] final def asRow = (r: RichResultSet) => (r.nextInt.get, r.nextString.get)
+
+  @inline private[this] final def rows(list: ListBuffer[(Int, String)]) = list.map { e => row(e._1, e._2) }
+
+  @inline private[this] final def row(id: Int, message: String) = <tr><td>{ id }</td><td>{ message }</td></tr>
+
+  @inline private[this] final def html(rows: ListBuffer[Elem]) =
+    <html>
+      <head><title>Fortunes</title></head>
+      <body>  <table>
+                <tr><th>id</th><th>message</th></tr>
+                { rows }
+              </table> </body>
+    </html>
+
+  private[this] final val sql = "select id, message from Fortune"
+
+  private[this] final val datasource = "MysqlBenchmark"
+
+}