Ver Fonte

fix hapi tests (#2489)

Nate há 8 anos atrás
pai
commit
4a2453837f

+ 3 - 3
frameworks/JavaScript/hapi/benchmark_config.json

@@ -2,7 +2,7 @@
   "framework": "hapi",
   "tests": [{
     "default": {
-      "setup_file": "setup-mongodb",
+      "setup_file": "setup",
       "json_url": "/json",
       "plaintext_url": "/plaintext",
       "db_url": "/mongoose/db",
@@ -26,7 +26,7 @@
       "versus": "nodejs"
     },
     "mysql": {
-      "setup_file": "setup-mysql",
+      "setup_file": "setup",
       "db_url": "/sequelize/db",
       "query_url": "/sequelize/queries?queries=",
       "fortune_url": "/sequelize/fortunes",
@@ -48,7 +48,7 @@
       "versus": "nodejs"
     },
     "postgres": {
-      "setup_file": "setup-postgresql",
+      "setup_file": "setup",
       "db_url": "/sequelize-pg/db",
       "query_url": "/sequelize-pg/queries?queries=",
       "fortune_url": "/sequelize-pg/fortunes",

+ 0 - 8
frameworks/JavaScript/hapi/create-server.js

@@ -22,19 +22,16 @@ var Promise = require('bluebird');
 var MongooseHandler;
 var SequelizeHandler;
 var SequelizePgHandler;
-// var RedisHandler;
 
 // Slight start-up improvement loading handlers in parallel
 Promise.join(
   require('./handlers/mongoose'),
   require('./handlers/sequelize'),
   require('./handlers/sequelize-postgres'),
-  // require('./handlers/redis'),
   function (mongo, mysql, pg) {
     MongooseHandler = mongo;
     SequelizeHandler = mysql;
     SequelizePgHandler = pg;
-    // RedisHandler = redis;
   })
   .catch(function (err) {
     console.log('There was a problem setting up the handlers');
@@ -60,11 +57,6 @@ Route('/sequelize-pg/queries', SequelizePgHandler.MultipleQueries);
 Route('/sequelize-pg/fortunes', SequelizePgHandler.Fortunes);
 Route('/sequelize-pg/updates', SequelizePgHandler.Updates);
 
-// Route('/hiredis/db', RedisHandler.SingleQuery);
-// Route('/hiredis/queries', RedisHandler.MultipleQueries);
-// Route('/hiredis/fortunes', RedisHandler.Fortunes);
-// Route('/hiredis/updates', RedisHandler.Updates);
-
 
 function JsonSerialization(req, reply) {
   reply({ message: 'Hello, World!' })

+ 0 - 133
frameworks/JavaScript/hapi/handlers/redis.js

@@ -1,133 +0,0 @@
-// Connects to Redis using the node_redis and hiredis drivers
-// Handles related routes
-
-// "If hiredis [pure C library] is installed, node_redis will use it by default.
-// Otherwise, a pure JavaScript parser will be used."
-// >> hiredis is installed for these tests
-
-var h = require('../helper');
-var Promise = require('bluebird');
-// Can treat redis library as one that supports Promises
-// these methods will then have "-Async" appended to them.
-var redis = Promise.promisifyAll(require('redis'));
-var client = redis.createClient(6379, '127.0.0.1', {});
-
-client.on('error', function (err) {
-  console.log('Redis Error: ' + err);
-  // Do nothing further if Redis errors/is unavailable
-});
-
-function redisWorldId(id) {
-  return 'world:' + id;
-}
-
-function randomWorldPromise() {
-  var id = h.randomTfbNumber();
-  var redisId = redisWorldId(id);
-
-  var promise = client.getAsync(redisId)
-    .then(function (worldValue) {
-      return {
-        id: id,
-        randomNumber: worldValue
-      }
-    })
-    .catch(function (err) {
-      process.exit(1);
-    });
-  return promise;
-}
-
-function redisSetWorld(world) {
-  var redisId = redisWorldId(world.id);
-  var promise = client
-    .setAsync(redisId, world.randomNumber)
-    .then(function (result) {
-      return world;
-    })
-    .catch(function (err) {
-      process.exit(1);
-    });
-  return promise;
-}
-
-function redisGetAllFortunes() {
-  var promise = client
-    .lrangeAsync('fortunes', 0, -1)
-    .then(function (fortuneMessages) {
-      var fortunes = fortuneMessages.map(function (e, i) {
-        return { id: i + 1, message: e }
-      });
-      return fortunes;
-    })
-    .catch(function (err) {
-      if (err) { return process.exit(1); }
-    });
-  return promise;
-}
-
-
-module.exports = {
-  
-  SingleQuery: function(req, reply) {
-    randomWorldPromise()
-      .then(function (world) {
-        reply(world)
-          .header('Server', 'hapi');
-      })
-      .catch(function (err) {
-        if (err) { return process.exit(1); }
-      })
-  },
-
-  MultipleQueries: function(req, reply) {
-    var queries = h.getQueries(req);
-    var worldPromises = h.fillArray(randomWorldPromise(), queries);
-
-    Promise
-      .all(worldPromises)
-      .then(function (worlds) {
-         reply(worlds)
-          .header('Server', 'hapi');
-      });
-  },
-
-  Fortunes: function(req, reply) {
-    redisGetAllFortunes()
-      .then(function (fortunes) {
-        fortunes.push(h.ADDITIONAL_FORTUNE);
-        fortunes.sort(function (a, b) {
-          return a.message.localeCompare(b.message);
-        });
-
-        reply.view('fortunes', {
-          fortunes: fortunes
-        })
-          .header('Content-Type', 'text/html')
-          .header('Server', 'hapi');
-      })
-      .catch(function (err) {
-        process.exit(1);
-      })
-  },
-
-  Updates: function(req, reply) {
-    var queries = h.getQueries(req)
-    var worldPromises = h.fillArray(randomWorldPromise(), queries);
-
-    Promise
-      .all(worldPromises)
-      .map(function (world) {
-        world.randomNumber = h.randomTfbNumber();
-        return redisSetWorld(world);
-      })
-      .then(function (updated) {
-        reply(updated)
-          .header('Server', 'hapi');
-      })
-      .catch(function (err) {
-        process.exit(1);
-      });
-  }
-
-};

+ 0 - 5
frameworks/JavaScript/hapi/setup-mongodb.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-
-fw_depends mongodb
-
-source ./setup.sh

+ 0 - 5
frameworks/JavaScript/hapi/setup-mysql.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-
-fw_depends mysql
-
-source ./setup.sh

+ 0 - 5
frameworks/JavaScript/hapi/setup-postgresql.sh

@@ -1,5 +0,0 @@
-#!/bin/bash
-
-fw_depends postgresql
-
-source ./setup.sh

+ 1 - 2
frameworks/JavaScript/hapi/setup.sh

@@ -1,11 +1,10 @@
 #!/bin/bash
 
-fw_depends nodejs
+fw_depends mongodb postgresql mysql nodejs
 
 sed -i 's|127.0.0.1|'"${DBHOST}"'|g' handlers/mongoose.js
 sed -i 's|127.0.0.1|'"${DBHOST}"'|g' handlers/sequelize-postgres.js
 sed -i 's|127.0.0.1|'"${DBHOST}"'|g' handlers/sequelize.js
-sed -i 's|127.0.0.1|'"${DBHOST}"'|g' handlers/redis.js
 
 npm install
 node app &