Browse Source

Merge pull request #174 from Skamander/play-scala-fortune

play-scala fortune testcase + readme fixes...
Patrick Falls 12 years ago
parent
commit
2153870512

+ 2 - 2
php-fuel/README.md

@@ -5,13 +5,13 @@ This is the FuelPHP portion of a [benchmarking test suite](../) comparing a vari
 ### JSON Encoding Test
 Uses the PHP standard [JSON encoder](http://www.php.net/manual/en/function.json-encode.php).
 
-* [JSON test controller](fuel/app/classes/controllers/bench.php)
+* [JSON test controller](fuel/app/classes/controller/bench.php)
 
 
 ### Data-Store/Database Mapping Test
 Uses the Fuel ORM
 
-* [DB test controller](fuel/app/classes/controllers/bench.php)
+* [DB test controller](fuel/app/classes/controller/bench.php)
 
 
 ## Infrastructure Software Versions

+ 2 - 2
php-kohana/README.md

@@ -5,13 +5,13 @@ This is the Kohana PHP portion of a [benchmarking test suite](../) comparing a v
 ### JSON Encoding Test
 Uses the PHP standard [JSON encoder](http://www.php.net/manual/en/function.json-encode.php).
 
-* [JSON test controller](application/classes/controllers/Bench.php)
+* [JSON test controller](application/classes/Controller/Bench.php)
 
 
 ### Data-Store/Database Mapping Test
 Uses the db abstraction class from Kohana
 
-* [DB test controller](application/classes/controllers/Bench.php)
+* [DB test controller](application/classes/Controller/Bench.php)
 
 
 ## Infrastructure Software Versions

+ 2 - 2
php-micromvc/README.md

@@ -5,13 +5,13 @@ This is the Micromvc portion of a [benchmarking test suite](../) comparing a var
 ### JSON Encoding Test
 Uses the PHP standard [JSON encoder](http://www.php.net/manual/en/function.json-encode.php).
 
-* [JSON test controller](index.php)
+* [JSON test controller](Class/Controller/Benchmark/Json.php)
 
 
 ### Data-Store/Database Mapping Test
 Uses the built-in ORM of micromvc
 
-* [DB test controller](index.php)
+* [DB test controller](Class/Controller/Benchmark/Db.php)
 
 
 ## Infrastructure Software Versions

+ 1 - 1
php-silex/README.md

@@ -1,4 +1,4 @@
-# Cake PHP Benchmarking Test
+# Silex Benchmarking Test
 
 This is the Silex PHP portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
 

+ 3 - 3
php-symfony2/README.md

@@ -1,4 +1,4 @@
-# Cake PHP Benchmarking Test
+# Symfony 2 Benchmarking Test
 
 This is the Symfony 2 PHP portion of a [benchmarking test suite](../) comparing a variety of web development platforms.
 
@@ -11,8 +11,8 @@ Uses the PHP standard [JSON encoder](http://www.php.net/manual/en/function.json-
 ### Data-Store/Database Mapping Test
 Uses the Symfony 2/Doctrine 2 Entity functionality.
 
-* [DB test controller](src/Skamander/BenchmarkBundle/BenchController.php)
-* [DB test model](src/Skamander/BenchmarkBundle/World.php)
+* [DB test controller](src/Skamander/BenchmarkBundle/Controller/BenchController.php)
+* [DB test model](src/Skamander/BenchmarkBundle/Entity/World.php)
 
 
 ## Infrastructure Software Versions

+ 3 - 3
php-symfony2/web/app.php

@@ -8,10 +8,10 @@ $loader = require_once __DIR__.'/../app/bootstrap.php.cache';
 // Use APC for autoloading to improve performance.
 // Change 'sf2' to a unique prefix in order to prevent cache key conflicts
 // with other applications also using APC.
-/*
-$loader = new ApcClassLoader('sf2', $loader);
+
+$loader = new ApcClassLoader('symfony2Benchmark', $loader);
 $loader->register(true);
-*/
+
 
 require_once __DIR__.'/../app/AppKernel.php';
 //require_once __DIR__.'/../app/AppCache.php';

+ 11 - 1
play-scala/app/controllers/Application.scala

@@ -5,7 +5,7 @@ import play.api.mvc._
 import play.api.libs.json.Json
 import java.util.concurrent._
 import scala.concurrent._
-import models._
+import models.{World, Fortune}
 import utils._
 import scala.concurrent.Future
 
@@ -58,4 +58,14 @@ object Application extends Controller {
     }
   }
 
+  def fortunes() = PredicatedAction(isDbAvailable, ServiceUnavailable) {
+    Action {
+      Async {
+        Future(Fortune.getAll())(dbEc).map { fs =>
+          val fortunes =  fs :+ Fortune(anorm.NotAssigned, "Additional fortune added at request time.")
+          Ok(views.html.fortune(fortunes))
+        }
+      }
+    }
+  }
 }

+ 24 - 0
play-scala/app/models/Fortune.scala

@@ -0,0 +1,24 @@
+package models
+
+import play.api.db._
+import play.api.Play.current
+import anorm._
+import anorm.SqlParser._
+
+case class Fortune(id: Pk[Long], message: String)
+
+object Fortune {
+
+  val simpleRowParser = {
+    get[Pk[Long]]("fortune.id") ~
+    get[String]("fortune.message") map {
+      case id~message => Fortune(id, message)
+    }
+  }
+
+  def getAll(): List[Fortune] = {
+    DB.withConnection { implicit connection =>
+      SQL("SELECT * FROM Fortune").as(Fortune.simpleRowParser *)
+    }
+  }
+}

+ 1 - 1
play-scala/app/models/World.scala

@@ -37,7 +37,7 @@ object World {
    */
     def findById(id: Long): World = {
         DB.withConnection { implicit connection =>
-            SQL("SELECT * FROM world WHERE id = {id}").on(
+            SQL("SELECT * FROM World WHERE id = {id}").on(
                 "id" -> id
             ).as(World.simpleRowParser.single)
         }

+ 18 - 0
play-scala/app/views/fortune.scala.html

@@ -0,0 +1,18 @@
+@(fortunes: List[Fortune])
+
+@main("Testcase 4 :: Fortune :: FrameworkBenchmark") {
+    <table>
+        <tr>
+            <th>id</th>
+            <th>message</th>
+        </tr>
+
+        @fortunes.sortBy(_.message).map { case Fortune(id, message) =>
+            <tr>
+                <td>@id</td>
+                <td>@message</td>
+            </tr>
+        }
+
+    </table>
+}

+ 13 - 0
play-scala/app/views/main.scala.html

@@ -0,0 +1,13 @@
+@(title: String)(content: Html)
+
+<!DOCTYPE html>
+
+<html>
+<head>
+    <title>@title</title>
+    <meta charset=utf-8>
+</head>
+<body>
+    @content
+</body>
+</html>

+ 1 - 0
play-scala/benchmark_config

@@ -6,6 +6,7 @@
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/db?queries=",
+      "fortune_url": "/fortunes",
       "port": 9000,
       "sort": 32
     }

+ 1 - 0
play-scala/conf/routes

@@ -5,6 +5,7 @@
 # Home page
 GET     /json                           controllers.Application.json
 GET     /db                             controllers.Application.db(queries: Int ?= 1)
+GET     /fortunes                       controllers.Application.fortunes
 
 # Map static resources from the /public folder to the /assets URL path
 GET     /assets/*file                   controllers.Assets.at(path="/public", file)