Browse Source

adds plaintext and update tests to zend

Keith Newman 9 years ago
parent
commit
313c296238

+ 2 - 0
frameworks/PHP/zend/benchmark_config.json

@@ -3,8 +3,10 @@
   "tests": [{
     "default": {
       "setup_file": "setup",
+      "plaintext_url": "/plaintext",
       "json_url": "/json",
       "db_url": "/db",
+      "update_url": "/update?queries=",
       "query_url": "/db-multi?queries=",
       "port": 8080,
       "approach": "Realistic",

+ 44 - 1
frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/DbController.php → frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/BenchController.php

@@ -5,6 +5,7 @@ namespace FrameworkBenchmarks\Controller;
 use Zend\Mvc\Controller\AbstractActionController;
 use Zend\Stdlib\ArrayUtils;
 use Zend\View\Model\JsonModel;
+use Zend\Http\Headers;
 use Zend\Db\TableGateway\TableGateway;
 
 /**
@@ -13,7 +14,7 @@ use Zend\Db\TableGateway\TableGateway;
  * @author Marco Pivetta <[email protected]>
  * @link   http://www.techempower.com/benchmarks
  */
-class DbController extends AbstractActionController
+class BenchController extends AbstractActionController
 {
     /**
      * @var \Zend\Db\TableGateway\TableGateway
@@ -28,6 +29,16 @@ class DbController extends AbstractActionController
         $this->tableGateway = $tableGateway;
     }
 
+    public function indexAction()
+    {
+      return array('message' => 'test123');
+    }
+
+    public function jsonAction()
+    {
+        return new JsonModel(array('message' => 'Hello, World!'));
+    }
+
     /**
      * @return \Zend\View\Model\JsonModel
      */
@@ -63,4 +74,36 @@ class DbController extends AbstractActionController
 
         return new JsonModel($worlds);
     }
+
+    public function updateAction()
+    {
+      $request = $this->getRequest();
+      $queries = (int) $request->getQuery('queries', 1);
+      $queries = max(1, $queries);
+      $queries = min(500, $queries);
+
+      $worlds  = array();
+
+      for ($i = 0; $i < $queries; $i += 1) {
+          $id = mt_rand(1, 10000);
+          foreach ($this->tableGateway->select(array('id' => $id)) as $found) {
+              $random_number = mt_rand(1, 10000);
+              $found->randomNumber = $random_number;
+              $this->tableGateway->update(array('randomNumber' => $random_number), array('id' => $id));
+              $worlds[] = $found;
+          }
+      }
+
+      return new JsonModel($worlds);
+    }
+
+    public function plaintextAction()
+    {
+      $response = $this->getResponse();
+      $response->getHeaders()->addHeaders(array('COntent-Type' => 'text/plain'));
+      $response->setContent('Hello, World!');
+      return $response;
+      // echo "Hello, World!";
+      // return;
+    }
 }

+ 0 - 23
frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Controller/JsonController.php

@@ -1,23 +0,0 @@
-<?php
-
-namespace FrameworkBenchmarks\Controller;
-
-use Zend\Mvc\Controller\AbstractActionController;
-use Zend\View\Model\JsonModel;
-
-/**
- * Controller that produces the `hello world` json for the benchmarks of FrameworkBenchmarks
- *
- * @author Marco Pivetta <[email protected]>
- * @link   http://www.techempower.com/benchmarks
- */
-class JsonController extends AbstractActionController
-{
-    /**
-     * @return \Zend\View\Model\JsonModel
-     */
-    public function indexAction()
-    {
-        return new JsonModel(array('message' => 'Hello, World!'));
-    }
-}

+ 26 - 9
frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/Module.php

@@ -18,13 +18,23 @@ class Module
         return array(
             'router' => array(
                 'routes' => array(
+                    'plaintext' => array(
+                      'type' => 'Zend\Mvc\Router\Http\Literal',
+                      'options' => array(
+                          'route' => '/plaintext',
+                          'defaults' => array(
+                              'controller' => 'FrameworkBenchmarks\Controller\BenchController',
+                              'action' => 'plaintext',
+                          ),
+                      ),
+                    ),
                     'json' => array(
                         'type' => 'Zend\Mvc\Router\Http\Literal',
                         'options' => array(
                             'route' => '/json',
                             'defaults' => array(
-                                'controller' => 'FrameworkBenchmarks\Controller\JsonController',
-                                'action' => 'index',
+                                'controller' => 'FrameworkBenchmarks\Controller\BenchController',
+                                'action' => 'json',
                             ),
                         ),
                     ),
@@ -33,7 +43,7 @@ class Module
                         'options' => array(
                             'route' => '/db',
                             'defaults' => array(
-                                'controller' => 'FrameworkBenchmarks\Controller\DbController',
+                                'controller' => 'FrameworkBenchmarks\Controller\BenchController',
                                 'action' => 'db',
                             ),
                         ),
@@ -43,11 +53,21 @@ class Module
                         'options' => array(
                             'route' => '/db-multi',
                             'defaults' => array(
-                                'controller' => 'FrameworkBenchmarks\Controller\DbController',
+                                'controller' => 'FrameworkBenchmarks\Controller\BenchController',
                                 'action' => 'db-multi',
                             ),
                         ),
                     ),
+                    'update' => array(
+                        'type' => 'Zend\Mvc\Router\Http\Literal',
+                        'options' => array(
+                            'route' => '/update',
+                            'defaults' => array(
+                                'controller' => 'FrameworkBenchmarks\Controller\BenchController',
+                                'action' => 'update',
+                            ),
+                        ),
+                    ),
                 ),
             ),
             'db' => array(
@@ -55,12 +75,9 @@ class Module
                 'dsn'    => 'mysql:dbname=hello_world;host=localhost',
             ),
             'controllers' => array(
-                'invokables' => array(
-                    'FrameworkBenchmarks\Controller\JsonController' => 'FrameworkBenchmarks\Controller\JsonController',
-                ),
                 'factories' => array(
-                    'FrameworkBenchmarks\Controller\DbController'
-                        => 'FrameworkBenchmarks\ServiceFactory\DbControllerServiceFactory'
+                    'FrameworkBenchmarks\Controller\BenchController'
+                        => 'FrameworkBenchmarks\ServiceFactory\BenchControllerServiceFactory'
                 ),
             ),
             'service_manager' => array(

+ 3 - 3
frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/ServiceFactory/DbControllerServiceFactory.php → frameworks/PHP/zend/module/FrameworkBenchmarks/src/FrameworkBenchmarks/ServiceFactory/BenchControllerServiceFactory.php

@@ -9,7 +9,7 @@
 
 namespace FrameworkBenchmarks\ServiceFactory;
 
-use FrameworkBenchmarks\Controller\DbController;
+use FrameworkBenchmarks\Controller\BenchController;
 use FrameworkBenchmarks\Entity\World;
 use Zend\Db\ResultSet\ResultSet;
 use Zend\Db\TableGateway\TableGateway;
@@ -22,7 +22,7 @@ use Zend\ServiceManager\ServiceLocatorInterface;
  * @author Marco Pivetta <[email protected]>
  * @link   http://www.techempower.com/benchmarks
  */
-class DbControllerServiceFactory implements FactoryInterface
+class BenchControllerServiceFactory implements FactoryInterface
 {
     /**
      * {@inheritDoc}
@@ -38,6 +38,6 @@ class DbControllerServiceFactory implements FactoryInterface
 
         $resultSetPrototype->setArrayObjectPrototype(new World());
 
-        return new DbController(new TableGateway('World', $dbAdapter, null, $resultSetPrototype));
+        return new BenchController(new TableGateway('World', $dbAdapter, null, $resultSetPrototype));
     }
 }